use of com.digi.xbee.api.exceptions.TimeoutException in project JMRI by JMRI.
the class AddNodeFrame method addButtonActionPerformed.
/**
* Method to handle add button
*/
@Override
public void addButtonActionPerformed() {
if (nodeAddr64Field.getText().equals("") && nodeAddrField.getText().equals("")) {
// no address, just return.
return;
}
// Check that a node with this address does not exist
// if the 64 bit address field is blank, use the "Unknown" address".
XBee64BitAddress guid;
if (!(nodeAddr64Field.getText().equals(""))) {
byte[] GUID = jmri.util.StringUtil.bytesFromHexString(nodeAddr64Field.getText());
guid = new XBee64BitAddress(GUID);
} else {
guid = XBee64BitAddress.UNKNOWN_ADDRESS;
}
// if the 16 bit address field is blank, use the "Unknown" address".
XBee16BitAddress address;
if (!(nodeAddrField.getText().equals(""))) {
byte[] addr = jmri.util.StringUtil.bytesFromHexString(nodeAddrField.getText());
address = new XBee16BitAddress(addr);
} else {
address = XBee16BitAddress.UNKNOWN_ADDRESS;
}
String Identifier = nodeIdentifierField.getText();
// create the RemoteXBeeDevice for the node.
RemoteXBeeDevice remoteDevice = new RemoteXBeeDevice(xtc.getXBee(), guid, address, Identifier);
// get a XBeeNode corresponding to this node address if one exists
curNode = (XBeeNode) xtc.getNodeFromXBeeDevice(remoteDevice);
if (curNode != null) {
javax.swing.JOptionPane.showMessageDialog(this, Bundle.getMessage("Error1", remoteDevice), Bundle.getMessage("AddNodeErrorTitle"), JOptionPane.ERROR_MESSAGE);
return;
}
try {
// and then add it to the network
xtc.getXBee().getNetwork().addRemoteDevice(remoteDevice);
// create node (they register themselves)
XBeeNode node = new XBeeNode(remoteDevice);
xtc.registerNode(node);
parent.nodeListChanged();
} catch (TimeoutException toe) {
log.error("Timeout adding node {}.", remoteDevice);
javax.swing.JOptionPane.showMessageDialog(this, Bundle.getMessage("Error3"), Bundle.getMessage("AddNodeErrorTitle"), JOptionPane.ERROR_MESSAGE);
log.error("Error creating XBee Node, constructor returned null");
return;
} catch (XBeeException xbe) {
log.error("Exception adding node {}.", remoteDevice);
javax.swing.JOptionPane.showMessageDialog(this, Bundle.getMessage("Error3"), Bundle.getMessage("AddNodeErrorTitle"), JOptionPane.ERROR_MESSAGE);
log.error("Error creating XBee Node, constructor returned null");
return;
}
this.dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
}
use of com.digi.xbee.api.exceptions.TimeoutException in project JMRI by JMRI.
the class XBeeSensorManager method ioSampleReceived.
// IIOSampleReceiveListener methods
@Override
public synchronized void ioSampleReceived(RemoteXBeeDevice remoteDevice, IOSample ioSample) {
if (log.isDebugEnabled()) {
log.debug("recieved io sample {} from {}", ioSample, remoteDevice);
}
XBeeNode node = (XBeeNode) tc.getNodeFromXBeeDevice(remoteDevice);
for (int i = 0; i <= 8; i++) {
if (!node.getPinAssigned(i) && ioSample.hasDigitalValue(IOLine.getDIO(i))) {
// get pin direction
// assume disabled as default.
IOMode mode = IOMode.DISABLED;
try {
mode = remoteDevice.getIOConfiguration(IOLine.getDIO(i));
} catch (TimeoutException toe) {
log.debug("Timeout retrieving IO line mode for {} on {}", IOLine.getDIO(i), remoteDevice);
// is this a hidden terminal? This was triggered by an
// IO Sample, so we know we can hear the other node, but
// it may not hear us. In this case, assume we are
// working with an input pin.
mode = IOMode.DIGITAL_IN;
} catch (InterfaceNotOpenException ino) {
log.error("Interface Not Open retrieving IO line mode for {} on {}", IOLine.getDIO(i), remoteDevice);
} catch (XBeeException xbe) {
log.error("Error retrieving IO line mode for {} on {}", IOLine.getDIO(i), remoteDevice);
}
if (mode == IOMode.DIGITAL_IN) {
// thisis an input, check to see if it exists as a sensor.
node = (XBeeNode) tc.getNodeFromXBeeDevice(remoteDevice);
// Sensor name is prefix followed by NI/address
// followed by the bit number.
String sName = prefix + typeLetter() + node.getPreferedName() + ":" + i;
XBeeSensor s = (XBeeSensor) getSensor(sName);
if (s == null) {
// the sensor doesn't exist, so provide a new one.
try {
provideSensor(sName);
if (log.isDebugEnabled()) {
log.debug("DIO {} enabled as sensor", sName);
}
} catch (java.lang.IllegalArgumentException iae) {
// if provideSensor fails, it will throw an IllegalArgumentException, so catch that,log it if debugging is enabled, and then re-throw it.
if (log.isDebugEnabled()) {
log.debug("Attempt to enable DIO {} as sensor failed", sName);
}
throw iae;
}
}
}
}
}
}
use of com.digi.xbee.api.exceptions.TimeoutException in project JMRI by JMRI.
the class ConnectionConfigXml method unpackElement.
@Override
protected void unpackElement(Element shared, Element perNode) {
List<Element> l = shared.getChildren("node");
// Trigger initialization of this Node to reflect these parameters
XBeeConnectionMemo xcm = (XBeeConnectionMemo) adapter.getSystemConnectionMemo();
XBeeTrafficController xtc = (XBeeTrafficController) xcm.getTrafficController();
for (int i = 0; i < l.size(); i++) {
Element n = l.get(i);
byte[] GUID = jmri.util.StringUtil.bytesFromHexString(findParmValue(n, "GUID"));
XBee64BitAddress guid = new XBee64BitAddress(GUID);
byte[] addr = jmri.util.StringUtil.bytesFromHexString(findParmValue(n, "address"));
XBee16BitAddress address = new XBee16BitAddress(addr);
String Identifier = findParmValue(n, "name");
// create the RemoteXBeeDevice for the node.
RemoteXBeeDevice remoteDevice = new RemoteXBeeDevice(xtc.getXBee(), guid, address, Identifier);
// Check to see if the node is a duplicate, if it is, move
// to the next one.
// get a XBeeNode corresponding to this node address if one exists
XBeeNode curNode = (XBeeNode) xtc.getNodeFromXBeeDevice(remoteDevice);
if (curNode != null) {
log.info("Read duplicate node {} from file", remoteDevice);
continue;
}
try {
// and then add it to the network
xtc.getXBee().getNetwork().addRemoteDevice(remoteDevice);
// create node (they register themselves)
XBeeNode node = new XBeeNode(remoteDevice);
String polled = findParmValue(n, "polled");
node.setPoll(polled.equals("yes"));
xtc.registerNode(node);
// if there is a stream port controller stored for this
// node, we need to load that after the node starts running.
// otherwise, the IOStream associated with the node has not
// been configured.
String streamController = findParmValue(n, "StreamController");
if (streamController != null) {
try {
// Class.forName cast is unchecked at this point
@SuppressWarnings("unchecked") java.lang.Class<jmri.jmrix.AbstractStreamPortController> T = (Class<AbstractStreamPortController>) Class.forName(streamController);
node.connectPortController(T);
} catch (java.lang.ClassNotFoundException cnfe) {
log.error("Unable to find class for stream controller : {}", streamController);
}
}
} catch (TimeoutException toe) {
log.error("Timeout adding node {} from configuration file.", remoteDevice);
} catch (XBeeException xbe) {
log.error("Exception adding node {} from configuration file.", remoteDevice);
}
}
}
use of com.digi.xbee.api.exceptions.TimeoutException in project JMRI by JMRI.
the class XBeeTrafficController method connectPort.
/**
* Make connection to existing PortController object.
*/
@Override
@SuppressFBWarnings(value = { "UW_UNCOND_WAIT", "WA_NOT_IN_LOOP" }, justification = "The unconditional wait outside of a loop is used to allow the hardware to react to a reset request.")
public void connectPort(AbstractPortController p) {
// Attach XBee to the port
try {
if (p instanceof XBeeAdapter) {
XBeeAdapter xbp = (XBeeAdapter) p;
xbee = new XBeeDevice(xbp);
xbee.open();
xbee.reset();
try {
synchronized (this) {
wait(2000);
}
} catch (java.lang.InterruptedException e) {
}
xbee.addPacketListener(this);
xbee.addModemStatusListener(this);
xbee.addDataListener(this);
} else {
throw new java.lang.IllegalArgumentException("Wrong adapter type specified when connecting to the port.");
}
} catch (TimeoutException te) {
log.error("Timeout durring communication with Local XBee on communication start up. Error was {} cause {} ", te, te.getCause());
} catch (XBeeException xbe) {
log.error("Exception durring XBee communication start up. Error was {} cause {} ", xbe, xbe.getCause());
}
}
Aggregations