Skip to content

Commit

Permalink
Moved from nrjavaserial to jSerialComm
Browse files Browse the repository at this point in the history
  • Loading branch information
pfrommerd committed Nov 22, 2017
1 parent a874dab commit b0ac6b0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 43 deletions.
Binary file added lib/serial/jSerialComm-1.3.11.jar
Binary file not shown.
Binary file removed lib/serial/nrjavaserial.jar
Binary file not shown.
55 changes: 12 additions & 43 deletions src/us/pfrommer/insteon/msg/serial/SerialIOStream.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
package us.pfrommer.insteon.msg.serial;

import gnu.io.CommPort;
import gnu.io.CommPortIdentifier;
import gnu.io.NoSuchPortException;
import gnu.io.PortInUseException;
import gnu.io.SerialPort;
import gnu.io.UnsupportedCommOperationException;
import com.fazecast.jSerialComm.SerialPort;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -18,7 +13,6 @@ public class SerialIOStream implements IOStream {
private OutputStream m_out;

private SerialPort m_port = null;
private final String m_appName = "PLM";
private final int m_speed = 19200; // baud rate
private String m_devName = null;

Expand All @@ -34,49 +28,24 @@ public SerialIOStream(String devName) {
@Override
public void open() throws IOException {
try {
/* by default, RXTX searches only devices /dev/ttyS* and
* /dev/ttyUSB*, and will so not find symlinks. The
* setProperty() call below helps
*/
System.setProperty("gnu.io.rxtx.SerialPorts", m_devName);
CommPortIdentifier ci =
CommPortIdentifier.getPortIdentifier(m_devName);
CommPort cp = ci.open(m_appName, 1000);
if (cp instanceof SerialPort) {
m_port = (SerialPort)cp;
} else {
throw new IllegalStateException("unknown port type");
}
m_port.setSerialPortParams(m_speed, SerialPort.DATABITS_8,
SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
m_port.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
m_port.disableReceiveFraming();
m_port.disableReceiveThreshold();
//m_port.enableReceiveThreshold(1000);
//Do receive timeout so we can check if the reader has to stop
m_port.enableReceiveTimeout(1000);

m_in = m_port.getInputStream();
m_out = new NoFlushOutputStream(m_port.getOutputStream());
} catch (IOException e) {
throw e;
} catch (PortInUseException e) {
throw new IOException(e);
} catch (UnsupportedCommOperationException e) {
throw new IOException(e);
} catch (NoSuchPortException e) {
throw new IOException(e);
} catch (IllegalStateException e) {
throw new IOException(e);
}
m_port = SerialPort.getCommPort(m_devName);
m_port.setComPortParameters(m_speed, 8, SerialPort.ONE_STOP_BIT, SerialPort.NO_PARITY);
m_port.setComPortTimeouts(SerialPort.TIMEOUT_READ_SEMI_BLOCKING, 0, 0);
m_port.setFlowControl(SerialPort.FLOW_CONTROL_DISABLED);
m_port.openPort();
m_in = m_port.getInputStream();
m_out = m_port.getOutputStream();
} catch (Exception e) {
throw new IOException(e);
}
}

@Override
public void close() throws IOException {
if (m_in != null) m_in.close();
if (m_out != null) m_out.close();
if (m_port != null) {
m_port.close();
m_port.closePort();
}
m_port = null;
m_in = null;
Expand Down

0 comments on commit b0ac6b0

Please sign in to comment.