Digital input/output
If your IO line is configured as digital output, you can set its state (high/low) easily. All the XBee device classes provide the method, setDIOValue(IOLine, IOValue), with the desired IO line as the first parameter and an IOValue as the second. The IOValue enumerator includes HIGH and LOW as possible values.
Setting digital output values
[...] // Set the DIO2_AD2 line low. myXBeeDevice.setDIOValue(IOLine.DIO2_AD2, IOValue.LOW); // Set the DIO2_AD2 line high. myXBeeDevice.setDIOValue(IOLine.DIO2_AD2, IOValue.HIGH); [...]
The setDIOValue() method may fail for the following reasons:
- ACK of the command sent is not received in the configured timeout, throwing a TimeoutException.
- Other errors caught as XBeeException:
- The operating mode of the device is not API or API_ESCAPE, throwing an InvalidOperatingModeException.
- The response of the command is not valid, throwing an ATCommandException.
- There is an error writing to the XBee interface, throwing a generic XBeeException.
You can also read the current status of the pin (high/low) by issuing the method getDIOValue(IOLine). The parameter of the method must be the IO line to be read.
Reading digital input values
[...] // Get the value of the DIO2_AD2. IOValue value = myXBeeDevice.getDIOValue(IOLine.DIO2_AD2); [...]
- ACK of the read command is not received in the configured timeout, throwing a TimeoutException.
- Other errors caught as XBeeException:
- If the operating mode of the device is not API or API_ESCAPE, throwing an InvalidOperatingModeException.
- If the received response does not contain the value for the given IO line, throwing a OperationNotSupportedException. This can happen (for example) if you try to read the DIO value of an IO line that is not configured as Digital Input.
- If the response to the read command is not valid, throwing an ATCommandException.
- If there is an error writing to the XBee interface, throwing a generic XBeeException.
Handling DIO IO Lines example
The XBee Java Library includes two sample applications that demonstrate how to handle DIO lines in your local and remote XBee Devices. The examples are located in the following path:
/examples/io/LocalDIOSample
/examples/io/RemoteDIOSample