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);
}
Aggregations