Search in sources :

Example 1 with SerialPort

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));
}
Also used : SerialPort(com.fazecast.jSerialComm.SerialPort) SerialConfig(me.retrodaredevil.io.serial.SerialConfig) JSerialIOBundle(me.retrodaredevil.io.serial.JSerialIOBundle)

Example 2 with SerialPort

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();
}
Also used : SerialPort(com.fazecast.jSerialComm.SerialPort) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream)

Example 3 with SerialPort

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;
}
Also used : SerialPort(com.fazecast.jSerialComm.SerialPort) IOException(java.io.IOException)

Example 4 with SerialPort

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;
}
Also used : SerialPort(com.fazecast.jSerialComm.SerialPort)

Example 5 with SerialPort

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();
    }
}
Also used : SerialPort(com.fazecast.jSerialComm.SerialPort)

Aggregations

SerialPort (com.fazecast.jSerialComm.SerialPort)5 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 JSerialIOBundle (me.retrodaredevil.io.serial.JSerialIOBundle)1 SerialConfig (me.retrodaredevil.io.serial.SerialConfig)1