use of gnu.io.CommPort in project openhab1-addons by openhab.
the class SerialPortConnector method connectPort.
@Override
protected void connectPort() throws Exception {
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(device);
CommPort commPort = portIdentifier.open(this.getClass().getName(), 2000);
serialPort = (SerialPort) commPort;
setSerialPortParameters(baudrate);
in = serialPort.getInputStream();
out = new DataOutputStream(serialPort.getOutputStream());
}
use of gnu.io.CommPort in project openhab1-addons by openhab.
the class OpenEnergyMonitorSerialConnector method connect.
@Override
public void connect() throws OpenEnergyMonitorException {
try {
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
CommPort commPort = portIdentifier.open(this.getClass().getName(), 2000);
serialPort = (SerialPort) commPort;
serialPort.setSerialPortParams(BAUDRATE, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
in = serialPort.getInputStream();
logger.debug("Open Energy Monitor Serial Port message listener started");
} catch (Exception e) {
throw new OpenEnergyMonitorException(e);
}
}
use of gnu.io.CommPort in project openhab1-addons by openhab.
the class ZWaveController method connect.
// Controller methods
/**
* Connects to the comm port and starts send and receive threads.
*
* @param serialPortName the port name to open
* @throws SerialInterfaceException when a connection error occurs.
*/
public void connect(final String serialPortName) throws SerialInterfaceException {
logger.info("Connecting to serial port {}", serialPortName);
try {
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(serialPortName);
CommPort commPort = portIdentifier.open("org.openhab.binding.zwave", 2000);
this.serialPort = (SerialPort) commPort;
this.serialPort.setSerialPortParams(115200, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
this.serialPort.enableReceiveThreshold(1);
this.serialPort.enableReceiveTimeout(ZWAVE_RECEIVE_TIMEOUT);
this.receiveThread = new ZWaveReceiveThread();
this.receiveThread.start();
this.sendThread = new ZWaveSendThread();
this.sendThread.start();
this.inputThread = new ZWaveInputThread();
this.inputThread.start();
// RXTX serial port library causes high CPU load
// Start event listener, which will just sleep and slow down event loop
serialPort.addEventListener(this.receiveThread);
serialPort.notifyOnDataAvailable(true);
logger.info("Serial port is initialized");
} catch (NoSuchPortException e) {
logger.error("Serial Error: Port {} does not exist", serialPortName);
throw new SerialInterfaceException(String.format("Port %s does not exist", serialPortName), e);
} catch (PortInUseException e) {
logger.error("Serial Error: Port {} in use.", serialPortName);
throw new SerialInterfaceException(String.format("Port %s in use.", serialPortName), e);
} catch (UnsupportedCommOperationException e) {
logger.error("Serial Error: Unsupported comm operation on Port {}.", serialPortName);
throw new SerialInterfaceException(String.format("Unsupported comm operation on Port %s.", serialPortName), e);
} catch (TooManyListenersException e) {
logger.error("Serial Error: Too many listeners on Port {}.", serialPortName);
e.printStackTrace();
}
}
use of gnu.io.CommPort in project openhab1-addons by openhab.
the class PrimareSerialConnector method connectSerial.
private void connectSerial() throws Exception {
logger.debug("Initializing serial port {}", serialPortName);
try {
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(serialPortName);
CommPort commPort = portIdentifier.open(this.getClass().getName(), 2000);
serialPort = (SerialPort) commPort;
try {
serialPort.setSerialPortParams(4800, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
serialPort.enableReceiveThreshold(1);
serialPort.disableReceiveTimeout();
} catch (UnsupportedCommOperationException unimportant) {
// We might have a perfectly usable PTY even if above operations are unsupported
}
;
inStream = new DataInputStream(serialPort.getInputStream());
outStream = serialPort.getOutputStream();
outStream.flush();
if (inStream.markSupported()) {
inStream.reset();
}
logger.debug("Starting DataListener for {}", PrimareSerialConnector.this.toString());
dataListener = new DataListener();
dataListener.start();
logger.debug("Starting DataListener for {}", PrimareSerialConnector.this.toString());
sendInitMessages();
} catch (NoSuchPortException e) {
logger.error("No such port: {}", serialPortName);
Enumeration portList = CommPortIdentifier.getPortIdentifiers();
if (portList.hasMoreElements()) {
StringBuilder sb = new StringBuilder();
while (portList.hasMoreElements()) {
CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement();
sb.append(String.format("%s ", portId.getName()));
}
logger.error("The following communications ports are available: {}", sb.toString().trim());
} else {
logger.error("There are no communications ports available");
}
logger.error("You may consider OpenHAB startup parameter [ -Dgnu.io.rxtx.SerialPorts={} ]", serialPortName);
throw e;
}
}
use of gnu.io.CommPort in project openhab1-addons by openhab.
the class RFXComSerialConnector method connect.
@Override
public void connect(String device) throws NoSuchPortException, PortInUseException, UnsupportedCommOperationException, IOException {
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(device);
CommPort commPort = portIdentifier.open(this.getClass().getName(), 2000);
serialPort = (SerialPort) commPort;
serialPort.setSerialPortParams(38400, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
serialPort.enableReceiveThreshold(1);
serialPort.disableReceiveTimeout();
in = serialPort.getInputStream();
out = serialPort.getOutputStream();
out.flush();
if (in.markSupported()) {
in.reset();
}
readerThread = new SerialReader(in);
readerThread.start();
}
Aggregations