Setting digital outputs

In addition to sending messages, the XBee service now supports setting remote digital outputs on an XBee module. Remote outputs are set/cleared by sending a remote digital IO configuration command to a specific XBee device. This method only allows one output’s state to be configured per operation. To use the feature, configure one of your XBee routers or end devices such that one or more of its pins support digital outputs. The following code samples shows the step required to change the state of a digital output on a remote XBee device.

Assuming the following code is in your project:

// Ensure the following aliases are defined
using xbee = SoCGadget.Robotics.XBee.Proxy;

/// <summary>
/// XBeeService partner
/// (Created for you by Visual Studio)
/// </summary>
[Partner( "XBeeService", Contract = xbee.Contract.Identifier, CreationPolicy = PartnerCreationPolicy.UseExistingOrCreate )]
xbee.XBeeServiceOperations _xBeeServicePort = new xbee.XBeeServiceOperations();

Build up an XBeeAddress64 object to point to your end device. We are using the XBee’s 64-bit addressing mode so the low/high address values are the serial number low/high values of the end device (SL, SH). The hex numbers here are my device's serial numbers, yours will be different.

    xbee.XBeeAddress64 endPointAddr = new xbee.XBeeAddress64
        AddressHigh = 0x13a200,
        AddressLow = 0x4030d088

Now set digital output number 1 on the device to TRUE:

    xbee.DeviceOutput xbeeMsg = new xbee.DeviceOutput
        DestinationAddress = endPointAddr,
        OutputNumber = 1,
        OutputState = true

    xbee.DeviceOutputUpdate update;
    yield return _xBeeServicePort.DeviceOutputUpdate( xbeeMsg, out update );
    yield return Arbiter.Choice<DefaultUpdateResponseType, W3C.Soap.Fault>( update.ResponsePort,
        delegate( DefaultUpdateResponseType response )
            // Success
        delegate( W3C.Soap.Fault fault )
            LogError( fault );

The service supports setting state on digital output numbers 0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 12, and 13. The others are not yet supported by the XBee firmware.

Last edited Oct 16, 2011 at 2:25 AM by jmckelvey, version 2


No comments yet.