Search in sources :

Example 1 with XBeeDevice

use of com.digi.xbee.api.XBeeDevice 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());
    }
}
Also used : XBeeException(com.digi.xbee.api.exceptions.XBeeException) XBeeDevice(com.digi.xbee.api.XBeeDevice) RemoteXBeeDevice(com.digi.xbee.api.RemoteXBeeDevice) TimeoutException(com.digi.xbee.api.exceptions.TimeoutException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

RemoteXBeeDevice (com.digi.xbee.api.RemoteXBeeDevice)1 XBeeDevice (com.digi.xbee.api.XBeeDevice)1 TimeoutException (com.digi.xbee.api.exceptions.TimeoutException)1 XBeeException (com.digi.xbee.api.exceptions.XBeeException)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1