Search in sources :

Example 1 with NRSerialPort

use of gnu.io.NRSerialPort in project openhab1-addons by openhab.

the class BenqProjectorSerialTransport method serialConnect.

private boolean serialConnect() {
    logger.debug("Running connection setup");
    try {
        logger.debug("Setting up socket connection to " + this.serialDevice);
        this.serialPort = new NRSerialPort(this.serialDevice, this.serialSpeed);
        this.serialPort.connect();
        this.projectorReader = new BufferedReader(new InputStreamReader(this.serialPort.getInputStream()));
        this.projectorWriter = new PrintWriter(this.serialPort.getOutputStream(), true);
        logger.debug("Serial connection setup successfully!");
        return true;
    } catch (Exception e) {
        logger.error("Unable to connect to device: " + this.serialDevice, e);
    }
    return false;
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) NRSerialPort(gnu.io.NRSerialPort) PrintWriter(java.io.PrintWriter)

Example 2 with NRSerialPort

use of gnu.io.NRSerialPort in project openremote by openremote.

the class NrJavaSerialChannel method doConnect.

@Override
protected void doConnect(SocketAddress remoteAddress, SocketAddress localAddress) throws Exception {
    NrJavaSerialAddress remote = (NrJavaSerialAddress) remoteAddress;
    final NRSerialPort serial = new NRSerialPort(remote.value(), remote.getBaudRate());
    serial.connect();
    serialPort = serial.getSerialPortInstance();
    if (serialPort == null) {
        // No exception is thrown on connect failure so throw one
        throw new ConnectTimeoutException("Failed to establish connection to COM port: " + remote.value());
    }
    serialPort.enableReceiveTimeout(config().getOption(io.netty.channel.rxtx.RxtxChannelOption.READ_TIMEOUT));
    deviceAddress = remote;
}
Also used : NRSerialPort(gnu.io.NRSerialPort) ConnectTimeoutException(io.netty.channel.ConnectTimeoutException)

Aggregations

NRSerialPort (gnu.io.NRSerialPort)2 ConnectTimeoutException (io.netty.channel.ConnectTimeoutException)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 PrintWriter (java.io.PrintWriter)1