Search in sources :

Example 1 with XBee

use of com.rapplogic.xbee.api.XBee in project openhab1-addons by openhab.

the class DiyOnXBeeBinding method updated.

@Override
public void updated(Dictionary<String, ?> properties) throws ConfigurationException {
    {
        final String serialPort = (String) properties.get("serialPort");
        if (StringUtils.isNotBlank(serialPort)) {
            this.serialPort = serialPort;
        }
    }
    {
        final String baudRate = (String) properties.get("baudRate");
        if (StringUtils.isNotBlank(baudRate)) {
            this.baudRate = Integer.parseInt(baudRate);
        }
    }
    String canonical = serialPort;
    try {
        // This code below enables to use a device name in
        // /dev/serial/by-id/... on linux
        File device = new File(serialPort);
        if (device.canRead()) {
            canonical = device.getCanonicalPath();
        }
    } catch (IOException e1) {
        logger.info("unable to get canonical path for '{}'", serialPort);
        canonical = serialPort;
    }
    xbeeSetupLock.lock();
    try {
        if (xbee != null) {
            xbee.removePacketListener(this);
            xbee.close();
            xbee = null;
        }
        xbee = new XBee();
        try {
            logger.info("opening XBee communication on '{}'", canonical);
            xbee.open(canonical, baudRate);
        } catch (XBeeException e) {
            logger.error("failed to open connection to XBee module", e);
            xbee = null;
            return;
        }
    } finally {
        xbeeSetupLock.unlock();
    }
    xbee.addPacketListener(this);
}
Also used : XBee(com.rapplogic.xbee.api.XBee) XBeeException(com.rapplogic.xbee.api.XBeeException) IOException(java.io.IOException) File(java.io.File)

Aggregations

XBee (com.rapplogic.xbee.api.XBee)1 XBeeException (com.rapplogic.xbee.api.XBeeException)1 File (java.io.File)1 IOException (java.io.IOException)1