Search in sources :

Example 1 with InterfaceNotOpenException

use of com.digi.xbee.api.exceptions.InterfaceNotOpenException 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;
                    }
                }
            }
        }
    }
}
Also used : InterfaceNotOpenException(com.digi.xbee.api.exceptions.InterfaceNotOpenException) IOMode(com.digi.xbee.api.io.IOMode) XBeeException(com.digi.xbee.api.exceptions.XBeeException) TimeoutException(com.digi.xbee.api.exceptions.TimeoutException)

Aggregations

InterfaceNotOpenException (com.digi.xbee.api.exceptions.InterfaceNotOpenException)1 TimeoutException (com.digi.xbee.api.exceptions.TimeoutException)1 XBeeException (com.digi.xbee.api.exceptions.XBeeException)1 IOMode (com.digi.xbee.api.io.IOMode)1