Subversion Repositories Programming Utils

Compare Revisions

Ignore whitespace Rev 95 → Rev 96

/trunk/JavaSerial/.classpath
1,6 → 1,20
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
/trunk/JavaSerial/NativeCode/com_rm5248_serial_SerialInputStream.h
7,8 → 7,8
#ifdef __cplusplus
extern "C" {
#endif
#undef com_rm5248_serial_SerialInputStream_SKIP_BUFFER_SIZE
#define com_rm5248_serial_SerialInputStream_SKIP_BUFFER_SIZE 2048L
#undef com_rm5248_serial_SerialInputStream_MAX_SKIP_BUFFER_SIZE
#define com_rm5248_serial_SerialInputStream_MAX_SKIP_BUFFER_SIZE 2048L
/*
* Class: com_rm5248_serial_SerialInputStream
* Method: readByte
/trunk/JavaSerial/NativeCode/SerialPortImpl.c
62,6 → 62,7
#include "com_rm5248_serial_SerialPort.h"
#include "com_rm5248_serial_SerialInputStream.h"
#include "com_rm5248_serial_SerialOutputStream.h"
#include "com_rm5248_serial_SimpleSerialInputStream.h"
 
//
// Struct Definitions
1441,9 → 1442,55
return ret_val;
}
 
/*
* Class: com_rm5248_serial_SimpleSerialInputStream
* Method: readByte
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_com_rm5248_serial_SimpleSerialInputStream_readByte
(JNIEnv * env, jobject obj){
struct port_descriptor* desc;
jint ret_val;
int stat;
 
desc = get_port_descriptor( env, obj );
if( desc == NULL ){
return 0;
}
ret_val = 0;
 
#ifdef _WIN32
if( !ReadFile( desc->port, &ret_val, 1, 0, 0) ){
throw_io_exception( env, GetLastError() );
return -1;
}
#else
pthread_mutex_lock( &(desc->in_use) );
stat = read( desc->port, &ret_val, 1 );
if( stat < 0 ){
throw_io_exception( env, errno );
pthread_mutex_unlock( &(desc->in_use) );
return -1;
}
pthread_mutex_unlock( &(desc->in_use) );
#endif
return ret_val;
}
 
/*
* Class: com_rm5248_serial_SimpleSerialInputStream
* Method: getAvailable
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_com_rm5248_serial_SimpleSerialInputStream_getAvailable
(JNIEnv * env, jobject obj){
//use our already-existing method to get the available bytes, it already works
return Java_com_rm5248_serial_SerialInputStream_getAvailable( env, obj );
}
 
 
/*
* Class: com_rm5248_serial_SerialOutputStream
* Method: writeByte
* Signature: (I)V
1565,7 → 1612,7
*/
JNIEXPORT jint JNICALL Java_com_rm5248_serial_SerialPort_getMinorNativeVersion
(JNIEnv * env, jclass cls){
return 4;
return 5;
}
 
/*
/trunk/JavaSerial/NativeCode/com_rm5248_serial_SimpleSerialInputStream.h
0,0 → 1,31
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_rm5248_serial_SimpleSerialInputStream */
 
#ifndef _Included_com_rm5248_serial_SimpleSerialInputStream
#define _Included_com_rm5248_serial_SimpleSerialInputStream
#ifdef __cplusplus
extern "C" {
#endif
#undef com_rm5248_serial_SimpleSerialInputStream_MAX_SKIP_BUFFER_SIZE
#define com_rm5248_serial_SimpleSerialInputStream_MAX_SKIP_BUFFER_SIZE 2048L
/*
* Class: com_rm5248_serial_SimpleSerialInputStream
* Method: readByte
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_com_rm5248_serial_SimpleSerialInputStream_readByte
(JNIEnv *, jobject);
 
/*
* Class: com_rm5248_serial_SimpleSerialInputStream
* Method: getAvailable
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_com_rm5248_serial_SimpleSerialInputStream_getAvailable
(JNIEnv *, jobject);
 
#ifdef __cplusplus
}
#endif
#endif
/trunk/JavaSerial/NativeCode/Makefile
56,7 → 56,7
.PRECIOUS: $(SOURCEFILES)
OBJFILES = SerialPortImpl.o
 
JNI_INCLUDE_DIR = /usr/lib/jvm/java-7-sun/include
JNI_INCLUDE_DIR = /usr/lib/jvm/java-7-openjdk-amd64/include
JNI_INCLUDE_DIR_WIN=C:\Program Files (x86)\Java\jdk1.6.0_18\include
 
#
78,7 → 78,8
 
SerialPortImpl.o: SerialPortImpl.c com_rm5248_serial_SerialPort.h \
com_rm5248_serial_SerialInputStream.h \
com_rm5248_serial_SerialOutputStream.h
com_rm5248_serial_SerialOutputStream.h \
com_rm5248_serial_SimpleSerialInputStream.h
 
#
# Installation Targets
/trunk/JavaSerial/LICENSE
1,7 → 1,7
Copyright (c) 2013 rm5248
Copyright (c) 2013-2015 rm5248
 
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
/trunk/JavaSerial/.project
10,8 → 10,14
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
/trunk/JavaSerial/src/com/rm5248/serial/SerialPort.java
1,21 → 1,100
package com.rm5248.serial;
 
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
 
/**
* A SerialPort represents a serial port on the system.
*
* All SerialPorts must implement this class.
* All SerialPorts must extend this class. It is unable to be instantiated, except
* by subclasses.
*
* See the documentation for the subclasses on how to create
* a specific instance of a SerialPort.
* a specific instance of a SerialPort. The two main subclasses are IOSerialPort and
* NIOSerialPort.
*
* @author rm5248
*
*/
public interface SerialPort {
public class SerialPort {
//The first time this class is referenced, we need to load the library.
static{
loadNativeLibrary();
}
/**
* Load the native library.
*
* There are two important system properties that can be set here:
*
* com.rm5248.javaserial.lib.path - give the directory name that the JNI code is located in
* com.rm5248.javaserial.lib.name - explicitly give the name of the library(the default is 'javaserial')
*
* This is based largely off of SQLite-JDBC( https://github.com/xerial/sqlite-jdbc )
*/
private static void loadNativeLibrary() {
String nativeLibraryPath = System.getProperty( "com.rm5248.javaserial.lib.path" );
String nativeLibraryName = System.getProperty( "com.rm5248.javaserial.lib.name" );
if( nativeLibraryName == null ){
nativeLibraryName = System.mapLibraryName( "javaserial" );
if( nativeLibraryName.endsWith( "dylib" ) ){
//mac uses jnilib instead of dylib for some reason
nativeLibraryName.replace( "dylib", "jnilib" );
}
}
if( nativeLibraryPath != null ){
File libToLoad = new File(nativeLibraryPath, nativeLibraryName);
System.load( libToLoad.getAbsolutePath() );
return;
}
//if we get here, that means that we must extract the JNI from the jar
try {
File extractedLib;
Path tempFolder;
String osName;
String arch;
InputStream library;
osName = System.getProperty( "os.name" );
if( osName.contains( "Windows" ) ){
osName = "Windows";
}else if( osName.contains( "Mac" ) || osName.contains( "Darwin" ) ){
osName = "Mac";
}else if( osName.contains( "Linux" ) ){
osName = "Linux";
}else{
osName = osName.replaceAll( "\\W", "" );
}
arch = System.getProperty( "os.arch" );
arch.replaceAll( "\\W", "" );
//create the temp folder to extract the library to
tempFolder = Files.createTempDirectory( "jserial" );
tempFolder.toFile().deleteOnExit();
extractedLib = new File( tempFolder.toFile(), nativeLibraryName );
//now let's extract the proper library
library = SerialPort.class.getResourceAsStream( "NativeCode/" +
osName + "/" + arch + "/" + nativeLibraryName );
Files.copy( library, extractedLib.toPath() );
System.load( extractedLib.getAbsolutePath() );
} catch (IOException e) {
throw new UnsatisfiedLinkError( "Unable to create temp directory or extract: " + e.getMessage() );
}
}
/**
* Represents the BaudRate that the SerialPort uses.
*/
public enum BaudRate{
79,59 → 158,348
HARDWARE,
SOFTWARE
}
/* The handle to our internal data structure which keeps track of the port settings.
* We need a special structure, as on windows we have a HANDLE type, which is void*,
* yet on Linux we have a file descriptor, which is an int.
* This is not just a pointer to memory, because if we're running on a 64-bit
* system, then we might have problems putting it in 32-bits. Better safe than sorry.
*/
protected int handle;
/* Make sure we don't close ourselves twice */
protected boolean closed;
/* The name of the port that's currently open */
private String portName;
/* Cache of the last gotten serial line state */
protected volatile SerialLineState state;
/**
* Open the specified port, defining all options
*
* @param portName The name of the port to open
* @param rate The Buad Rate to open this port at
* @param data The number of data bits
* @param stop The number of stop bits
* @param parity The parity of the line
* @param flow The flow control of the line
* @throws NoSuchPortException If this port does not exist
* @throws NotASerialPortException If the specified port is not a serial port
*/
protected SerialPort( String portName, BaudRate rate, DataBits data, StopBits stop, Parity parity, FlowControl flow )
throws NoSuchPortException, NotASerialPortException {
int myRate = 0;
int myData = 0;
int myStop = 0;
int myParity = 0;
int myFlow = 0;
SerialLineState s;
int state;
//Check for null values in our arguments
if( portName == null ){
throw new IllegalArgumentException( "portName must not be null" );
}
if( rate == null ){
throw new IllegalArgumentException( "rate must not be null" );
}
if( data == null ){
throw new IllegalArgumentException( "data must not be null" );
}
if( stop == null ){
throw new IllegalArgumentException( "stop must not be null" );
}
if( parity == null ){
throw new IllegalArgumentException( "parity must not be null" );
}
if( flow == null ){
throw new IllegalArgumentException( "flow must not be null" );
}
 
//Okay, looks like we're good!
this.portName = portName;
closed = false;
 
switch( rate ){
case B0 : myRate = 0; break;
case B50 : myRate = 50; break;
case B75 : myRate = 75; break;
case B110 : myRate = 110; break;
case B134 : myRate = 134; break;
case B150 : myRate = 150; break;
case B200 : myRate = 200; break;
case B300 : myRate = 300; break;
case B600 : myRate = 600; break;
case B1200 : myRate = 1200; break;
case B1800 : myRate = 1800; break;
case B2400 : myRate = 2400; break;
case B4800 : myRate = 4800; break;
case B9600 : myRate = 9600; break;
case B38400 : myRate = 38400; break;
case B115200: myRate = 115200; break;
}
 
switch( data ){
case DATABITS_5: myData = 5; break;
case DATABITS_6: myData = 6; break;
case DATABITS_7: myData = 7; break;
case DATABITS_8: myData = 8; break;
}
 
switch( stop ){
case STOPBITS_1: myStop = 1; break;
case STOPBITS_2: myStop = 2; break;
}
 
switch( parity ){
case NONE: myParity = 0; break;
case ODD: myParity = 1; break;
case EVEN: myParity = 2; break;
}
 
switch( flow ){
case NONE: myFlow = 0; break;
case HARDWARE: myFlow = 1; break;
case SOFTWARE: myFlow = 2; break;
}
 
handle = openPort(portName, myRate, myData, myStop, myParity, myFlow);
 
s = new SerialLineState();
state = getSerialLineStateInternalNonblocking();
if( ( state & 0x01 ) > 0 ){
s.carrierDetect = true;
}
if( ( state & (0x01 << 1 ) ) > 0 ){
s.clearToSend = true;
}
if( ( state & (0x01 << 2 ) ) > 0 ){
s.dataSetReady = true;
}
if( ( state & (0x01 << 3 ) ) > 0 ){
s.dataTerminalReady = true;
}
if( ( state & (0x01 << 4 ) ) > 0 ){
s.requestToSend = true;
}
if( ( state & (0x01 << 5 ) ) > 0 ){
s.ringIndicator = true;
}
 
this.state = s;
}
/**
* Open up a serial port, but allow the user to keep the current settings of the serial port.
*
* @param portName The port to open
* @param keepSettings If true, will simply open the serial port without setting anything. If false, this method
* acts the same as {@link #SerialPort(String) SerialPort( String portName ) }
* @throws NoSuchPortException If the port does not exist
* @throws NotASerialPortException If the port is not in fact a serial port
*/
protected SerialPort( String portName, boolean keepSettings ) throws NoSuchPortException, NotASerialPortException{
if( portName == null ){
throw new IllegalArgumentException( "portName must not be null" );
}
if( keepSettings ){
this.handle = openPort( portName );
this.portName = portName;
this.closed = false;
}else{
this.handle = openPort( portName, 9600, 8, 1, 0, 0 );
}
}
 
/**
* Set the Baud Rate for this port.
*
* @param rate
*/
public abstract void setBaudRate(BaudRate rate);
public void setBaudRate( BaudRate rate ){
int myRate = 0;
 
/**
* Close the serial port, and all input streams
*/
public abstract void close();
if( closed ){
throw new IllegalStateException( "Cannot set the BaudRate once the port has been closed." );
}
if( rate == null ){
throw new IllegalArgumentException( "rate must not be null" );
}
 
/**
* See if the port has been closed already.
* @return
*/
public abstract boolean isClosed();
switch( rate ){
case B0 : myRate = 0; break;
case B50 : myRate = 50; break;
case B75 : myRate = 75; break;
case B110 : myRate = 110; break;
case B134 : myRate = 134; break;
case B150 : myRate = 150; break;
case B200 : myRate = 200; break;
case B300 : myRate = 300; break;
case B600 : myRate = 600; break;
case B1200 : myRate = 1200; break;
case B1800 : myRate = 1800; break;
case B2400 : myRate = 2400; break;
case B4800 : myRate = 4800; break;
case B9600 : myRate = 9600; break;
case B38400 : myRate = 38400; break;
case B115200: myRate = 115200; break;
}
 
setBaudRate( myRate );
}
public boolean isClosed(){
return closed;
}
 
public void finalize(){
close();
}
public void close(){
if( closed ) return;
closed = true;
doClose();
}
 
/**
* Set the stop bits of the serial port, after the port has been opened.
*
* @param stop
*/
public abstract void setStopBits(StopBits stop);
public void setStopBits( StopBits stop ){
int myStop = 0;
 
if( closed ){
throw new IllegalStateException( "Cannot set the StopBits once the port has been closed." );
}
if( stop == null ){
throw new IllegalArgumentException( "stop must not be null" );
}
 
switch( stop ){
case STOPBITS_1: myStop = 1; break;
case STOPBITS_2: myStop = 2; break;
}
 
setStopBits( myStop );
}
 
/**
* Set the data bits size, after the port has been opened.
*
* @param data
*/
public abstract void setDataSize(DataBits data);
public void setDataSize( DataBits data ){
int myData = 0;
 
if( closed ){
throw new IllegalStateException( "Cannot set the DataBits once the port has been closed." );
}
if( data == null ){
throw new IllegalArgumentException( "data must not be null" );
}
 
switch( data ){
case DATABITS_5: myData = 5; break;
case DATABITS_6: myData = 6; break;
case DATABITS_7: myData = 7; break;
case DATABITS_8: myData = 8; break;
}
 
setCharSize( myData );
}
 
/**
* Set the parity of the serial port, after the port has been opened.
*
* @param parity
*/
public abstract void setParity(Parity parity);
public void setParity( Parity parity ){
int myParity = 0;
 
if( closed ){
throw new IllegalStateException( "Cannot set the parity once the port has been closed." );
}
 
if( parity == null ){
throw new IllegalArgumentException( "parity must not be null" );
}
switch( parity ){
case NONE: myParity = 0; break;
case ODD: myParity = 1; break;
case EVEN: myParity = 2; break;
}
 
setParity( myParity );
}
 
/**
* Get the serial line state for the specified serial port.
*
* @return
*/
public abstract SerialLineState getSerialLineState() throws IOException;
public SerialLineState getSerialLineState() throws IOException{
if( closed ){
throw new IllegalStateException( "Cannot get the serial line state once the port has been closed." );
}
 
int gotState = getSerialLineStateInternalNonblocking();
 
SerialLineState s = new SerialLineState();
// do some sort of bitwise operations here....
if( ( gotState & 0x01 ) > 0 ){
s.carrierDetect = true;
}
if( ( gotState & (0x01 << 1 ) ) > 0 ){
s.clearToSend = true;
}
if( ( gotState & (0x01 << 2 ) ) > 0 ){
s.dataSetReady = true;
}
if( ( gotState & (0x01 << 3 ) ) > 0 ){
s.dataTerminalReady = true;
}
if( ( gotState & (0x01 << 4 ) ) > 0 ){
s.requestToSend = true;
}
if( ( gotState & (0x01 << 5 ) ) > 0 ){
s.ringIndicator = true;
}
 
return s;
}
 
/**
* Set the serial line state to the parameters given.
*
* @param state
*/
public abstract void setSerialLineState(SerialLineState state);
public void setSerialLineState( SerialLineState state ){
if( closed ){
throw new IllegalStateException( "Cannot set the serial line state once the port has been closed." );
}
setSerialLineStateInternal( state );
//Now, because Windows is weird, we need to post a serial changed event here.
//however, since we can only set DTR and RTS, only post an event if those are
//the things that changed
// if( this.state.dataTerminalReady != state.dataTerminalReady ||
// this.state.requestToSend != state.requestToSend ){
// this.postSerialChangedEvent( state );
// }
}
 
/**
* Get the baud rate of the serial port.
138,42 → 506,155
*
* @return
*/
public abstract IOSerialPort.BaudRate getBaudRate();
public BaudRate getBaudRate(){
int baudRate;
BaudRate toReturn;
if( closed ){
throw new IllegalStateException( "Cannot get the baud rate once the port has been closed." );
}
baudRate = getBaudRateInternal();
toReturn = BaudRate.B0;
 
switch( baudRate ){
case 0 : toReturn = BaudRate.B0 ; break;
case 50 : toReturn = BaudRate.B50 ; break;
case 75 : toReturn = BaudRate.B75 ; break;
case 110 : toReturn = BaudRate.B110 ; break;
case 134 : toReturn = BaudRate.B134 ; break;
case 150 : toReturn = BaudRate.B150 ; break;
case 200 : toReturn = BaudRate.B200 ; break;
case 300 : toReturn = BaudRate.B300 ; break;
case 600 : toReturn = BaudRate.B600 ; break;
case 1200 : toReturn = BaudRate.B1200 ; break;
case 1800 : toReturn = BaudRate.B1800 ; break;
case 2400 : toReturn = BaudRate.B2400 ; break;
case 4800 : toReturn = BaudRate.B4800 ; break;
case 9600 : toReturn = BaudRate.B9600 ; break;
case 38400 : toReturn = BaudRate.B38400 ; break;
case 115200: toReturn = BaudRate.B115200; break;
}
 
return toReturn;
}
 
/**
* Get the number of data bits.
*
* @return
*/
public abstract IOSerialPort.DataBits getDataBits();
public DataBits getDataBits(){
int dataBits;
DataBits bits;
if( closed ){
throw new IllegalStateException( "Cannot get the data bits once the port has been closed." );
}
dataBits = getCharSizeInternal();
bits = DataBits.DATABITS_8;
 
switch( dataBits ){
case 8: bits = DataBits.DATABITS_8; break;
case 7: bits = DataBits.DATABITS_7; break;
case 6: bits = DataBits.DATABITS_6; break;
case 5: bits = DataBits.DATABITS_5; break;
}
 
return bits;
}
 
/**
* Get the number of stop bits.
*
* @return
*/
public abstract IOSerialPort.StopBits getStopBits();
public StopBits getStopBits(){
int stopBits;
StopBits bits;
if( closed ){
throw new IllegalStateException( "Cannot get stop bits once the port has been closed." );
}
stopBits = getStopBitsInternal();
bits = StopBits.STOPBITS_1;
 
switch( stopBits ){
case 1: bits = StopBits.STOPBITS_1; break;
case 2: bits = StopBits.STOPBITS_2; break;
}
 
return bits;
}
 
/**
* Get the parity of the serial port.
*
* @return
*/
public abstract IOSerialPort.Parity getParity();
public Parity getParity(){
int parity;
Parity par;
if( closed ){
throw new IllegalStateException( "Cannot get the parity once the port has been closed." );
}
parity = getParityInternal();
par = Parity.NONE;
 
switch( parity ){
case 0: par = Parity.NONE; break;
case 1: par = Parity.ODD; break;
case 2: par = Parity.EVEN; break;
}
 
return par;
}
 
/**
* Get the flow control for the serial port.
*
* @return
*/
public abstract IOSerialPort.FlowControl getFlowControl();
public FlowControl getFlowControl(){
int flowControl;
FlowControl cont;
if( closed ){
throw new IllegalStateException( "Cannot get the flow once the port has been closed." );
}
flowControl = getFlowControlInternal();
cont = FlowControl.NONE;
 
switch( flowControl ){
case 0: cont = FlowControl.NONE; break;
case 1: cont = FlowControl.HARDWARE; break;
case 2: cont = FlowControl.SOFTWARE; break;
}
 
return cont;
}
 
/**
* Set the flow control for the serial port
*
* @param flow
*/
public abstract void setFlowControl(FlowControl flow);
public void setFlowControl( FlowControl flow ){
if( closed ){
throw new IllegalStateException( "Cannot set flow once the port has been closed." );
}
switch( flow ){
case HARDWARE: setFlowControl( 1 ); break;
case NONE: setFlowControl( 0 ); break;
case SOFTWARE: setFlowControl( 2 ); break;
}
}
 
/**
* Set the listener which will get events when there is activity on the serial port.
184,12 → 665,153
*
* @param listen The listener which gets events
*/
public abstract void setSerialChangeListener(SerialChangeListener listen);
public void setSerialChangeListener( SerialChangeListener listen ){
}
 
/**
* Get the name of the serial port that this object represents.
* @return
*/
public abstract String getPortName();
public String getPortName(){
return portName;
}
/**
* Open the specified port, return an internal handle to the data structure for this port.
*
* @param portName
* @return
*/
private native int openPort( String portName, int baudRate, int dataBits, int stopBits, int parity, int flowControl ) throws NoSuchPortException, NotASerialPortException;
 
/**
* Open the specified port, return an internal handle for the data of this port.
* This method DOES NOT set any of the serial port settings
*
* @param portName The port to open
* @return
*/
private native int openPort( String portName ) throws NoSuchPortException, NotASerialPortException;
 
/**
* Close this port, release all native resources
*/
private native void doClose();
 
/**
* Set the baud rate in the native code.
*
* @param baudRate
* @return
*/
private native boolean setBaudRate( int baudRate );
 
private native int getBaudRateInternal();
 
/**
* Set the number of stop bits, once the port has been opened.
*
* @param stopBits
* @return
*/
private native boolean setStopBits( int stopBits );
 
private native int getStopBitsInternal();
 
/**
* Set the character size, once the port has been opened.
* This should probably be called 'setDataBits'
*
* @param charSize
* @return
*/
private native boolean setCharSize( int charSize );
 
private native int getCharSizeInternal();
 
/** Set the parity once the port has been opened.
*
* @param parity 0 = None, 1 = Odd, 2 = Even
* @return
*/
private native boolean setParity( int parity );
 
private native int getParityInternal();
 
/** Set the flow control once the port has been opened.
*
*
* @param flowControl 0 = None, 1 = hardware, 2 = software
* @return
*/
private native boolean setFlowControl( int flowControl );
 
private native int getFlowControlInternal();
 
/** Get the serial line state, but don't block when getting it
*
* @return
*/
protected native int getSerialLineStateInternalNonblocking();
/**
* Set the state of the serial line.
* @return
*/
private native int setSerialLineStateInternal( SerialLineState s );
 
 
//
// Static Methods
//
/**
* Get the major version of this library. For example, if this is version
* 0.2, this returns 0
*/
public static int getMajorVersion(){
return 0;
}
/**
* Get the minor version of this library. For example, if this is version
* 0.2, this returns 2.
*/
public static int getMinorVersion(){
return 5;
}
/**
* Get the major version of the native code. This should match up with
* {@link #getMajorVersion() getMajorVersion()}, although this is not
* guaranteed. For example, if this is version 0.2, this returns 0
*/
public static native int getMajorNativeVersion();
/**
* Get the minor version of the native code. This should match up with
* {@link #getMinorVersion() getMinorVersion()}, although this is not
* guaranteed. For example, if this is version 0.2, this returns 2.
*/
public static native int getMinorNativeVersion();
/**
* <p>
* Get an array of all the serial ports on the system. For example, on
* Windows this will return {@code { "COM1", "COM3", .... } } depending on how
* many serial devices you have plugged in. On Linux, this returns
* {@code { "/dev/ttyS0", "/dev/ttyUSB0", "/dev/symlink", ... } }
* It will not resolve symlinks, such that if there is a symlink
* from {@code /dev/symlink } to {@code /dev/ttyUSB0 }, they will both show up.
* </p>
* <p>
* <b>NOTE:</b> this will only return ports that you have permissions to
* open.
* </p>
*
* @return
*/
public static native String[] getSerialPorts();
 
}
/trunk/JavaSerial/src/com/rm5248/serial/NIOSerialPort.java
10,8 → 10,15
* @author rm5248
*
*/
public class NIOSerialPort implements SerialPort {
public class NIOSerialPort extends SerialPort {
 
protected NIOSerialPort(String portName, BaudRate rate, DataBits data,
StopBits stop, Parity parity, FlowControl flow)
throws NoSuchPortException, NotASerialPortException {
super(portName, rate, data, stop, parity, flow);
// TODO Auto-generated constructor stub
}
 
@Override
public void setBaudRate(BaudRate rate) {
// TODO Auto-generated method stub
/trunk/JavaSerial/src/com/rm5248/serial/IOSerialPort.java
21,17 → 21,13
* @author rm5248
*
*/
public class IOSerialPort implements Closeable, SerialPort {
public class IOSerialPort extends SerialPort implements Closeable {
 
static{
System.loadLibrary( "javaserial" );
}
private class SerialStateListener implements Runnable{
 
private class SerialStateListener implements Runnable{
private volatile boolean stop;
private SerialChangeListener listen;
 
SerialStateListener( SerialChangeListener listen ){
stop = false;
this.listen = listen;
51,19 → 47,12
}
}
}
 
void doStop(){
stop = true;
}
}
 
/* The handle to our internal data structure which keeps track of the port settings.
* We need a special structure, as on windows we have a HANDLE type, which is void*,
* yet on Linux we have a file descriptor, which is an int.
* This is not just a pointer to memory, because if we're running on a 64-bit
* system, then we might have problems putting it in 32-bits. Better safe than sorry.
*/
private int handle;
/* The input stream that user code uses to read from the serial port. */
private InputStream inputStream;
/* The buffered serial input stream which filters out events for us. */
70,12 → 59,6
private BufferedSerialInputStream bis;
/* The output stream that user code uses to write to the serial port. */
private SerialOutputStream outputStream;
/* Make sure we don't close ourselves twice */
private boolean closed;
/* The name of the port that's currently open */
private String portName;
/* Cache of the last gotten serial line state */
private volatile SerialLineState state;
/* Runs in the background to check for serial port events */
private SerialStateListener serialListen;
/* Used for synchronizing serialListen */
112,54 → 95,45
* @throws NotASerialPortException If the port is not in fact a serial port
*/
public IOSerialPort( String portName, boolean keepSettings, boolean ignoreControlLines ) throws NoSuchPortException, NotASerialPortException{
if( portName == null ){
throw new IllegalArgumentException( "portName must not be null" );
super( portName, keepSettings );
 
this.ignoringControlLines = ignoreControlLines;
if( ignoreControlLines ){
SimpleSerialInputStream ssis = new SimpleSerialInputStream( handle );
inputStream = ssis;
}else{
SerialInputStream sis = new SerialInputStream( handle );
inputStream = sis;
bis = new BufferedSerialInputStream( sis, this );
}
if( keepSettings ){
this.handle = openPort( portName );
this.portName = portName;
this.ignoringControlLines = ignoreControlLines;
if( ignoreControlLines ){
SimpleSerialInputStream ssis = new SimpleSerialInputStream( handle );
inputStream = ssis;
}else{
SerialInputStream sis = new SerialInputStream( handle );
inputStream = sis;
bis = new BufferedSerialInputStream( sis, this );
}
outputStream = new SerialOutputStream( handle );
closed = false;
outputStream = new SerialOutputStream( handle );
 
SerialLineState s = new SerialLineState();
int state = getSerialLineStateInternalNonblocking();
// do some sort of bitwise operations here....
if( ( state & 0x01 ) > 0 ){
s.carrierDetect = true;
}
if( ( state & (0x01 << 1 ) ) > 0 ){
s.clearToSend = true;
}
if( ( state & (0x01 << 2 ) ) > 0 ){
s.dataSetReady = true;
}
if( ( state & (0x01 << 3 ) ) > 0 ){
s.dataTerminalReady = true;
}
if( ( state & (0x01 << 4 ) ) > 0 ){
s.requestToSend = true;
}
if( ( state & (0x01 << 5 ) ) > 0 ){
s.ringIndicator = true;
}
SerialLineState s = new SerialLineState();
int state = 0;//getSerialLineStateInternalNonblocking();
// do some sort of bitwise operations here....
if( ( state & 0x01 ) > 0 ){
s.carrierDetect = true;
}
if( ( state & (0x01 << 1 ) ) > 0 ){
s.clearToSend = true;
}
if( ( state & (0x01 << 2 ) ) > 0 ){
s.dataSetReady = true;
}
if( ( state & (0x01 << 3 ) ) > 0 ){
s.dataTerminalReady = true;
}
if( ( state & (0x01 << 4 ) ) > 0 ){
s.requestToSend = true;
}
if( ( state & (0x01 << 5 ) ) > 0 ){
s.ringIndicator = true;
}
 
this.state = s;
this.state = s;
 
if( !ignoreControlLines ){
serialListenSync = new Object();
}else{
this.handle = openPort( portName, 9600, 8, 1, 0, 0 );
}
if( !ignoreControlLines ){
new Thread( bis, "BufferedSerialReader-" + portName ).start();
}
}
231,89 → 205,11
* @throws NotASerialPortException If the specified port is not a serial port
*/
public IOSerialPort( String portName, BaudRate rate, DataBits data, StopBits stop, Parity parity, FlowControl flow ) throws NoSuchPortException, NotASerialPortException {
int myRate = 0;
int myData = 0;
int myStop = 0;
int myParity = 0;
int myFlow = 0;
super( portName, rate, data, stop, parity, flow );
SerialInputStream sis;
SerialLineState s;
int state;
SerialInputStream sis;
//Check for null values in our arguments
if( portName == null ){
throw new IllegalArgumentException( "portName must not be null" );
}
if( rate == null ){
throw new IllegalArgumentException( "rate must not be null" );
}
if( data == null ){
throw new IllegalArgumentException( "data must not be null" );
}
if( stop == null ){
throw new IllegalArgumentException( "stop must not be null" );
}
if( parity == null ){
throw new IllegalArgumentException( "parity must not be null" );
}
if( flow == null ){
throw new IllegalArgumentException( "flow must not be null" );
}
 
//Okay, looks like we're good!
this.portName = portName;
closed = false;
ignoringControlLines = false;
 
switch( rate ){
case B0 : myRate = 0; break;
case B50 : myRate = 50; break;
case B75 : myRate = 75; break;
case B110 : myRate = 110; break;
case B134 : myRate = 134; break;
case B150 : myRate = 150; break;
case B200 : myRate = 200; break;
case B300 : myRate = 300; break;
case B600 : myRate = 600; break;
case B1200 : myRate = 1200; break;
case B1800 : myRate = 1800; break;
case B2400 : myRate = 2400; break;
case B4800 : myRate = 4800; break;
case B9600 : myRate = 9600; break;
case B38400 : myRate = 38400; break;
case B115200: myRate = 115200; break;
}
 
switch( data ){
case DATABITS_5: myData = 5; break;
case DATABITS_6: myData = 6; break;
case DATABITS_7: myData = 7; break;
case DATABITS_8: myData = 8; break;
}
 
switch( stop ){
case STOPBITS_1: myStop = 1; break;
case STOPBITS_2: myStop = 2; break;
}
 
switch( parity ){
case NONE: myParity = 0; break;
case ODD: myParity = 1; break;
case EVEN: myParity = 2; break;
}
 
switch( flow ){
case NONE: myFlow = 0; break;
case HARDWARE: myFlow = 1; break;
case SOFTWARE: myFlow = 2; break;
}
 
handle = openPort(portName, myRate, myData, myStop, myParity, myFlow);
sis = new SerialInputStream( handle );
inputStream = sis;
bis = new BufferedSerialInputStream( sis, this );
345,48 → 241,11
new Thread( bis, "BufferedSerialReader" ).start();
}
 
/* (non-Javadoc)
* @see com.rm5248.serial.SerialPortI#setBaudRate(com.rm5248.serial.SerialPort.BaudRate)
*/
@Override
public void setBaudRate( BaudRate rate ){
int myRate = 0;
 
if( closed ){
throw new IllegalStateException( "Cannot set the BaudRate once the port has been closed." );
}
if( rate == null ){
throw new IllegalArgumentException( "rate must not be null" );
}
 
switch( rate ){
case B0 : myRate = 0; break;
case B50 : myRate = 50; break;
case B75 : myRate = 75; break;
case B110 : myRate = 110; break;
case B134 : myRate = 134; break;
case B150 : myRate = 150; break;
case B200 : myRate = 200; break;
case B300 : myRate = 300; break;
case B600 : myRate = 600; break;
case B1200 : myRate = 1200; break;
case B1800 : myRate = 1800; break;
case B2400 : myRate = 2400; break;
case B4800 : myRate = 4800; break;
case B9600 : myRate = 9600; break;
case B38400 : myRate = 38400; break;
case B115200: myRate = 115200; break;
}
 
setBaudRate( myRate );
}
 
/**
* Get the input stream used to talk to this device.
*/
public InputStream getInputStream(){
if( closed ){
if( isClosed() ){
throw new IllegalStateException( "Cannot get the input stream once the port has been closed." );
}
 
393,7 → 252,7
if( ignoringControlLines ){
return inputStream;
}
 
return bis;
}
 
401,7 → 260,7
* Get the OutputStream used to talk to this device.
*/
public OutputStream getOutputStream(){
if( closed ){
if( isClosed() ){
throw new IllegalStateException( "Cannot get the output stream once the port has been closed." );
}
 
413,9 → 272,8
*/
@Override
public void close(){
if( closed ) return;
closed = true;
doClose();
if( isClosed() ) return;
super.close();
if( serialListen != null ){
serialListen.doStop();
}
424,322 → 282,11
}
}
 
/* (non-Javadoc)
* @see com.rm5248.serial.SerialPortI#isClosed()
*/
@Override
public boolean isClosed(){
return closed;
public String toString(){
return "IOSerial Port " + getPortName() + ":" + getBaudRate();
}
 
public void finalize(){
close();
}
 
/* (non-Javadoc)
* @see com.rm5248.serial.SerialPortI#setStopBits(com.rm5248.serial.SerialPort.StopBits)
*/
@Override
public void setStopBits( StopBits stop ){
int myStop = 0;
 
if( closed ){
throw new IllegalStateException( "Cannot set the StopBits once the port has been closed." );
}
if( stop == null ){
throw new IllegalArgumentException( "stop must not be null" );
}
 
switch( stop ){
case STOPBITS_1: myStop = 1; break;
case STOPBITS_2: myStop = 2; break;
}
 
setStopBits( myStop );
}
 
/* (non-Javadoc)
* @see com.rm5248.serial.SerialPortI#setDataSize(com.rm5248.serial.SerialPort.DataBits)
*/
@Override
public void setDataSize( DataBits data ){
int myData = 0;
 
if( closed ){
throw new IllegalStateException( "Cannot set the DataBits once the port has been closed." );
}
if( data == null ){
throw new IllegalArgumentException( "data must not be null" );
}
 
switch( data ){
case DATABITS_5: myData = 5; break;
case DATABITS_6: myData = 6; break;
case DATABITS_7: myData = 7; break;
case DATABITS_8: myData = 8; break;
}
 
setCharSize( myData );
}
 
/* (non-Javadoc)
* @see com.rm5248.serial.SerialPortI#setParity(com.rm5248.serial.SerialPort.Parity)
*/
@Override
public void setParity( Parity parity ){
int myParity = 0;
 
if( closed ){
throw new IllegalStateException( "Cannot set the parity once the port has been closed." );
}
 
if( parity == null ){
throw new IllegalArgumentException( "parity must not be null" );
}
switch( parity ){
case NONE: myParity = 0; break;
case ODD: myParity = 1; break;
case EVEN: myParity = 2; break;
}
 
setParity( myParity );
}
 
/* (non-Javadoc)
* @see com.rm5248.serial.SerialPortI#getSerialLineState()
*/
@Override
public SerialLineState getSerialLineState() throws IOException{
if( closed ){
throw new IllegalStateException( "Cannot get the serial line state once the port has been closed." );
}
 
int gotState = getSerialLineStateInternalNonblocking();
 
SerialLineState s = new SerialLineState();
// do some sort of bitwise operations here....
if( ( gotState & 0x01 ) > 0 ){
s.carrierDetect = true;
}
if( ( gotState & (0x01 << 1 ) ) > 0 ){
s.clearToSend = true;
}
if( ( gotState & (0x01 << 2 ) ) > 0 ){
s.dataSetReady = true;
}
if( ( gotState & (0x01 << 3 ) ) > 0 ){
s.dataTerminalReady = true;
}
if( ( gotState & (0x01 << 4 ) ) > 0 ){
s.requestToSend = true;
}
if( ( gotState & (0x01 << 5 ) ) > 0 ){
s.ringIndicator = true;
}
 
return s;
}
 
/* (non-Javadoc)
* @see com.rm5248.serial.SerialPortI#setSerialLineState(com.rm5248.serial.SerialLineState)
*/
@Override
public void setSerialLineState( SerialLineState state ){
if( closed ){
throw new IllegalStateException( "Cannot set the serial line state once the port has been closed." );
}
setSerialLineStateInternal( state );
//Now, because Windows is weird, we need to post a serial changed event here.
//however, since we can only set DTR and RTS, only post an event if those are
//the things that changed
if( this.state.dataTerminalReady != state.dataTerminalReady ||
this.state.requestToSend != state.requestToSend ){
this.postSerialChangedEvent( state );
}
}
 
/* (non-Javadoc)
* @see com.rm5248.serial.SerialPortI#getBaudRate()
*/
@Override
public IOSerialPort.BaudRate getBaudRate(){
int baudRate;
BaudRate toReturn;
if( closed ){
throw new IllegalStateException( "Cannot get the baud rate once the port has been closed." );
}
baudRate = getBaudRateInternal();
toReturn = BaudRate.B0;
 
switch( baudRate ){
case 0 : toReturn = BaudRate.B0 ; break;
case 50 : toReturn = BaudRate.B50 ; break;
case 75 : toReturn = BaudRate.B75 ; break;
case 110 : toReturn = BaudRate.B110 ; break;
case 134 : toReturn = BaudRate.B134 ; break;
case 150 : toReturn = BaudRate.B150 ; break;
case 200 : toReturn = BaudRate.B200 ; break;
case 300 : toReturn = BaudRate.B300 ; break;
case 600 : toReturn = BaudRate.B600 ; break;
case 1200 : toReturn = BaudRate.B1200 ; break;
case 1800 : toReturn = BaudRate.B1800 ; break;
case 2400 : toReturn = BaudRate.B2400 ; break;
case 4800 : toReturn = BaudRate.B4800 ; break;
case 9600 : toReturn = BaudRate.B9600 ; break;
case 38400 : toReturn = BaudRate.B38400 ; break;
case 115200: toReturn = BaudRate.B115200; break;
}
 
return toReturn;
}
 
/* (non-Javadoc)
* @see com.rm5248.serial.SerialPortI#getDataBits()
*/
@Override
public IOSerialPort.DataBits getDataBits(){
int dataBits;
DataBits bits;
if( closed ){
throw new IllegalStateException( "Cannot get the data bits once the port has been closed." );
}
dataBits = getCharSizeInternal();
bits = DataBits.DATABITS_8;
 
switch( dataBits ){
case 8: bits = DataBits.DATABITS_8; break;
case 7: bits = DataBits.DATABITS_7; break;
case 6: bits = DataBits.DATABITS_6; break;
case 5: bits = DataBits.DATABITS_5; break;
}
 
return bits;
}
 
/* (non-Javadoc)
* @see com.rm5248.serial.SerialPortI#getStopBits()
*/
@Override
public IOSerialPort.StopBits getStopBits(){
int stopBits;
StopBits bits;
if( closed ){
throw new IllegalStateException( "Cannot get stop bits once the port has been closed." );
}
stopBits = getStopBitsInternal();
bits = StopBits.STOPBITS_1;
 
switch( stopBits ){
case 1: bits = StopBits.STOPBITS_1; break;
case 2: bits = StopBits.STOPBITS_2; break;
}
 
return bits;
}
 
/* (non-Javadoc)
* @see com.rm5248.serial.SerialPortI#getParity()
*/
@Override
public IOSerialPort.Parity getParity(){
int parity;
Parity par;
if( closed ){
throw new IllegalStateException( "Cannot get the parity once the port has been closed." );
}
parity = getParityInternal();
par = Parity.NONE;
 
switch( parity ){
case 0: par = Parity.NONE; break;
case 1: par = Parity.ODD; break;
case 2: par = Parity.EVEN; break;
}
 
return par;
}
 
/* (non-Javadoc)
* @see com.rm5248.serial.SerialPortI#getFlowControl()
*/
@Override
public IOSerialPort.FlowControl getFlowControl(){
int flowControl;
FlowControl cont;
if( closed ){
throw new IllegalStateException( "Cannot get the flow once the port has been closed." );
}
flowControl = getFlowControlInternal();
cont = FlowControl.NONE;
 
switch( flowControl ){
case 0: cont = FlowControl.NONE; break;
case 1: cont = FlowControl.HARDWARE; break;
case 2: cont = FlowControl.SOFTWARE; break;
}
 
return cont;
}
/* (non-Javadoc)
* @see com.rm5248.serial.SerialPortI#setFlowControl(com.rm5248.serial.SerialPort.FlowControl)
*/
@Override
public void setFlowControl( FlowControl flow ){
if( closed ){
throw new IllegalStateException( "Cannot set flow once the port has been closed." );
}
switch( flow ){
case HARDWARE: setFlowControl( 1 ); break;
case NONE: setFlowControl( 0 ); break;
case SOFTWARE: setFlowControl( 2 ); break;
}
}
 
/* (non-Javadoc)
* @see com.rm5248.serial.SerialPortI#setSerialChangeListener(com.rm5248.serial.SerialChangeListener)
*/
@Override
public void setSerialChangeListener( SerialChangeListener listen ){
if( serialListen != null ){
serialListen.doStop();
}
if( listen != null ){
serialListen = new SerialStateListener( listen );
new Thread( serialListen, "SerialListen" ).start();
}
 
}
 
public String toString(){
return "Serial Port " + portName + ":" + getBaudRate();
}
 
/* (non-Javadoc)
* @see com.rm5248.serial.SerialPortI#getPortName()
*/
@Override
public String getPortName(){
return portName;
}
/**
* This method is called when the state of the serial lines is changed.
*
748,7 → 295,7
void postSerialChangedEvent( SerialLineState newState ){
if( !state.equals( newState ) ){
state = newState;
 
synchronized( serialListenSync ){
serialListenSync.notify();
}
755,140 → 302,16
}
}
 
/**
* Open the specified port, return an internal handle to the data structure for this port.
*
* @param portName
* @return
*/
private native int openPort( String portName, int baudRate, int dataBits, int stopBits, int parity, int flowControl ) throws NoSuchPortException, NotASerialPortException;
@Override
public void setSerialChangeListener( SerialChangeListener listen ){
if( serialListen != null ){
serialListen.doStop();
}
 
/**
* Open the specified port, return an internal handle for the data of this port.
* This method DOES NOT set any of the serial port settings
*
* @param portName The port to open
* @return
*/
private native int openPort( String portName ) throws NoSuchPortException, NotASerialPortException;
if( listen != null ){
serialListen = new SerialStateListener( listen );
new Thread( serialListen, "SerialListen" ).start();
}
 
/**
* Close this port, release all native resources
*/
private native void doClose();
 
/**
* Set the baud rate in the native code.
*
* @param baudRate
* @return
*/
private native boolean setBaudRate( int baudRate );
 
private native int getBaudRateInternal();
 
/**
* Set the number of stop bits, once the port has been opened.
*
* @param stopBits
* @return
*/
private native boolean setStopBits( int stopBits );
 
private native int getStopBitsInternal();
 
/**
* Set the character size, once the port has been opened.
* This should probably be called 'setDataBits'
*
* @param charSize
* @return
*/
private native boolean setCharSize( int charSize );
 
private native int getCharSizeInternal();
 
/** Set the parity once the port has been opened.
*
* @param parity 0 = None, 1 = Odd, 2 = Even
* @return
*/
private native boolean setParity( int parity );
 
private native int getParityInternal();
 
/** Set the flow control once the port has been opened.
*
*
* @param flowControl 0 = None, 1 = hardware, 2 = software
* @return
*/
private native boolean setFlowControl( int flowControl );
 
private native int getFlowControlInternal();
 
/** Get the serial line state, but don't block when getting it
*
* @return
*/
private native int getSerialLineStateInternalNonblocking();
/**
* Set the state of the serial line.
* @return
*/
private native int setSerialLineStateInternal( SerialLineState s );
//
// Static Methods
//
/**
* Get the major version of this library. For example, if this is version
* 0.2, this returns 0
*/
public static int getMajorVersion(){
return 0;
}
/**
* Get the minor version of this library. For example, if this is version
* 0.2, this returns 2.
*/
public static int getMinorVersion(){
return 4;
}
/**
* Get the major version of the native code. This should match up with
* {@link #getMajorVersion() getMajorVersion()}, although this is not
* guaranteed. For example, if this is version 0.2, this returns 0
*/
public static native int getMajorNativeVersion();
/**
* Get the minor version of the native code. This should match up with
* {@link #getMinorVersion() getMinorVersion()}, although this is not
* guaranteed. For example, if this is version 0.2, this returns 2.
*/
public static native int getMinorNativeVersion();
/**
* <p>
* Get an array of all the serial ports on the system. For example, on
* Windows this will return {@code { "COM1", "COM3", .... } } depending on how
* many serial devices you have plugged in. On Linux, this returns
* {@code { "/dev/ttyS0", "/dev/ttyUSB0", "/dev/symlink", ... } }
* It will not resolve symlinks, such that if there is a symlink
* from {@code /dev/symlink } to {@code /dev/ttyUSB0 }, they will both show up.
* </p>
* <p>
* <b>NOTE:</b> this will only return ports that you have permissions to
* open.
* </p>
*
* @return
*/
public static native String[] getSerialPorts();
 
}
/trunk/JavaSerial/pom.xml
0,0 → 1,36
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.rm5248</groupId>
<artifactId>JavaSerial</artifactId>
<version>0.5-SNAPSHOT</version>
<description>A cross-platform way of accessing serial ports through Java. Supports Windows and Linux. Does not use the Java SerialAPI. Implementations have both traditional IO and NIO implementations.</description>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source/>
<target/>
</configuration>
</plugin>
</plugins>
</build>
<url>http://programming.rm5248.com/</url>
<name>Java Serial</name>
<licenses>
<license>
<name>Apache License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<scm>
<url>http://svn.rm5248.com/prog_utils/trunk/JavaSerial/</url>
<connection>svn</connection>
</scm>
<issueManagement>
<url>http://programming.rm5248.com/</url>
</issueManagement>
</project>