forked from LupusNobilis/java-org.hwo
org.hwo.io angepasst
parent
74d50cd9f3
commit
fd9d976d84
|
@ -9,7 +9,7 @@ import java.util.ArrayList;
|
|||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.hwo.fifo.FiFo;
|
||||
import org.hwo.nativeloader.NativeLoader;
|
||||
import org.hwo.platform.natives.NativeLoader;
|
||||
|
||||
|
||||
/* NATIVE RETURN VALUES:
|
||||
|
|
|
@ -13,8 +13,8 @@ import org.hwo.StringHelper;
|
|||
import org.hwo.io.NativeSerialPort;
|
||||
import org.hwo.io.SerialPortExeption;
|
||||
import org.hwo.io.SerialPortWINDOWS;
|
||||
import org.hwo.nativeloader.NativeLoader;
|
||||
import org.hwo.os.OsDetect;
|
||||
import org.hwo.platform.Platform;
|
||||
import org.hwo.platform.natives.NativeLoader;
|
||||
|
||||
public class NewSerialPort {
|
||||
|
||||
|
@ -45,10 +45,14 @@ public class NewSerialPort {
|
|||
private NewSerialPortInputStream inputStream;
|
||||
private NewSerialPortOutputStream outputStream;
|
||||
|
||||
private List<NewSerialPortListener> serialPortListeners;
|
||||
|
||||
public NewSerialPort(String portName) {
|
||||
|
||||
this.nsp = nsp_alloc();
|
||||
|
||||
serialPortListeners = new LinkedList<NewSerialPortListener>();
|
||||
|
||||
setPortName(portName);
|
||||
|
||||
setBaudRate(9600);
|
||||
|
@ -71,6 +75,19 @@ public class NewSerialPort {
|
|||
super.finalize();
|
||||
}
|
||||
|
||||
public void addNewSerialPortListener(NewSerialPortListener listener){
|
||||
serialPortListeners.add(listener);
|
||||
}
|
||||
public void removeNewSerialPortListener(NewSerialPortListener listener){
|
||||
serialPortListeners.remove(listener);
|
||||
}
|
||||
|
||||
private void fireConnectionStateChanged(){
|
||||
for (NewSerialPortListener l: serialPortListeners)
|
||||
l.connectionStateChanged(this, isOpen());
|
||||
}
|
||||
|
||||
|
||||
public NewSerialPortInputStream getInputStream() {
|
||||
return inputStream;
|
||||
}
|
||||
|
@ -153,11 +170,14 @@ public class NewSerialPort {
|
|||
|
||||
System.err.println(String.format("nsp_open(): %d",r));
|
||||
|
||||
fireConnectionStateChanged();
|
||||
|
||||
return wasOpened;
|
||||
}
|
||||
public void close(){
|
||||
nsp_close(nsp);
|
||||
wasOpened = false;
|
||||
fireConnectionStateChanged();
|
||||
}
|
||||
|
||||
public boolean isOpen(){
|
||||
|
@ -215,21 +235,21 @@ public class NewSerialPort {
|
|||
|
||||
|
||||
|
||||
private static native long nsp_alloc();
|
||||
private static native int nsp_free(long msp);
|
||||
private static native synchronized long nsp_alloc();
|
||||
private static native synchronized int nsp_free(long msp);
|
||||
|
||||
private static native int nsp_set_portname(long nsp,String portName);
|
||||
private static native int nsp_setup_baudrate(long nsp,int baudRate);
|
||||
private static native int nsp_setup_bits(long nsp,int dataBits,int stopBits);
|
||||
private static native int nsp_setup_parity(long nsp,int parity);
|
||||
private static native int nsp_setup_handshake(long nsp,int handshake);
|
||||
private static native int nsp_setup_timeout(long nsp,int timeout);
|
||||
private static native synchronized int nsp_set_portname(long nsp,String portName);
|
||||
private static native synchronized int nsp_setup_baudrate(long nsp,int baudRate);
|
||||
private static native synchronized int nsp_setup_bits(long nsp,int dataBits,int stopBits);
|
||||
private static native synchronized int nsp_setup_parity(long nsp,int parity);
|
||||
private static native synchronized int nsp_setup_handshake(long nsp,int handshake);
|
||||
private static native synchronized int nsp_setup_timeout(long nsp,int timeout);
|
||||
|
||||
private static native int nsp_open(long nsp);
|
||||
private static native int nsp_close(long nsp);
|
||||
private static native synchronized int nsp_open(long nsp);
|
||||
private static native synchronized int nsp_close(long nsp);
|
||||
|
||||
private static native int nsp_read(long nsp);
|
||||
private static native int nsp_write(long nsp,int ch);
|
||||
private static native synchronized int nsp_read(long nsp);
|
||||
private static native synchronized int nsp_write(long nsp,int ch);
|
||||
|
||||
static {
|
||||
NativeLoader.loadLibrary("nsp");
|
||||
|
@ -272,7 +292,7 @@ public class NewSerialPort {
|
|||
}
|
||||
|
||||
static public String[] getPortNames(){
|
||||
switch (OsDetect.getOperatingSystem()){
|
||||
switch (Platform.getOperatingSystem()){
|
||||
case LINUX:
|
||||
return getPortNamesLIN();
|
||||
case WINDOWS:
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package org.hwo.io.NewSerialPort;
|
||||
|
||||
public interface NewSerialPortListener {
|
||||
|
||||
void connectionStateChanged(NewSerialPort port,boolean connected);
|
||||
|
||||
}
|
|
@ -2,13 +2,13 @@ package org.hwo.io;
|
|||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import org.hwo.os.OsDetect;
|
||||
import org.hwo.platform.Platform;
|
||||
|
||||
public abstract class SerialPort {
|
||||
|
||||
static public String[] getPortNames()
|
||||
{
|
||||
switch (OsDetect.getOperatingSystem())
|
||||
switch (Platform.getOperatingSystem())
|
||||
{
|
||||
case OSX:
|
||||
return SerialPortOSX.getPortNames();
|
||||
|
@ -23,7 +23,7 @@ public abstract class SerialPort {
|
|||
|
||||
static public SerialPort newInstance()
|
||||
{
|
||||
switch (OsDetect.getOperatingSystem())
|
||||
switch (Platform.getOperatingSystem())
|
||||
{
|
||||
case OSX:
|
||||
return new SerialPortOSX();
|
||||
|
|
Loading…
Reference in New Issue