use of com.fazecast.jSerialComm.SerialPort in project solarthing by wildmountainfarms.
the class SerialIOConfig method createIOBundle.
@Override
public IOBundle createIOBundle() throws Exception {
SerialConfig serialConfig = this.serialConfig;
if (serialConfig == null) {
serialConfig = defaultSerialConfig;
if (serialConfig == null) {
throw new NullPointerException("serialConfig is null! This is likely because the injection didn't work properly.");
}
}
String port = this.port;
if (port == null) {
throw new NullPointerException("null is not a valid value for the port!");
}
SerialPort serialPort = JSerialIOBundle.createSerialPortFromName(port);
return new JSerialIOBundle(serialPort, serialConfig, new JSerialIOBundle.Config(200, 65536, 65536));
}
use of com.fazecast.jSerialComm.SerialPort in project openpos-framework by JumpMind.
the class JSerialCommDemo method main.
public static void main(String[] args) throws Exception {
for (String key : System.getProperties().stringPropertyNames()) {
System.out.println(key + " " + System.getProperty(key));
}
SerialPort port = SerialPort.getCommPort("COM3");
port.openPort();
InputStream in = port.getInputStream();
OutputStream out = port.getOutputStream();
out.write("Hello\n".getBytes());
port.closePort();
}
use of com.fazecast.jSerialComm.SerialPort in project openremote by openremote.
the class JSerialCommChannel method doConnect.
@Override
protected void doConnect(SocketAddress remoteAddress, SocketAddress localAddress) throws Exception {
JSerialCommDeviceAddress remote = (JSerialCommDeviceAddress) remoteAddress;
SerialPort commPort = SerialPort.getCommPort(remote.value());
if (!commPort.openPort()) {
throw new IOException("Could not open port: " + remote.value());
}
deviceAddress = remote;
serialPort = commPort;
}
use of com.fazecast.jSerialComm.SerialPort in project openpos-framework by JumpMind.
the class RS232JSerialCommConnectionFactory method openSerialPort.
protected PeripheralConnection openSerialPort(String portName, Map<String, Object> settings) {
SerialPort port = SerialPort.getCommPort(portName);
int connectTimeout = getIntValue(CONNECT_TIMEOUT, 10000, settings);
int baudRate = getIntValue(BAUD_RATE, 19200, settings);
int dataBits = getIntValue(DATA_BITS, 8, settings);
int stopBits = getIntValue(STOP_BITS, 1, settings);
int parity = getIntValue(PARITY, 0, settings);
port.setBaudRate(baudRate);
port.setNumDataBits(dataBits);
port.setNumStopBits(stopBits);
port.setParity(parity);
port.setComPortTimeouts(SerialPort.TIMEOUT_NONBLOCKING, connectTimeout, connectTimeout);
boolean success = port.openPort();
if (!success) {
throw new PrintException("Failed to open serial port " + portName + " settings=" + settings + " - reason unknown.");
}
PeripheralConnection connection = new PeripheralConnection();
connection.setIn(port.getInputStream());
connection.setOut(port.getOutputStream());
connection.setRawConnection(port);
return connection;
}
use of com.fazecast.jSerialComm.SerialPort in project openpos-framework by JumpMind.
the class RS232JSerialCommConnectionFactory method close.
@Override
public void close(PeripheralConnection peripheralConnection) {
if (peripheralConnection.getRawConnection() instanceof SerialPort) {
SerialPort serialPort = (SerialPort) peripheralConnection.getRawConnection();
serialPort.closePort();
}
}
Aggregations