This project has moved. For the latest updates, please go here.

Retrieving IO data in a different way

May 7, 2014 at 5:07 AM
Edited May 7, 2014 at 5:08 AM
My goal is to have my coordinator Xbee poll one of the nodes and report back the value on the ADC. I know I can do with with the ISampleListner Class but there are some reasons I can't do this for my particular project. Instead I think I can use the Xbee.API.Send() command. So I have two questions:
When I execute this command:
                AtResponse allNodes = xbee.Api.Send(NETMF.OpenSource.XBee.Api.Zigbee.AtCmd.NodeDiscover).GetResponse();
There are frequently timeout exceptions. Any idea on how to fix this?
Secondly

When I do get the address back I do this:
                if(allNodes.Value.Length > 0) //found a node
                {
                    for (int ii = 0; ii < nodeAddress.Address.Length; ii++) //decode it
                    {
                        sb.Append(allNodes.Value[ii]);
                        nodeAddress.Address[ii] = allNodes.Value[ii];
                    }
                    //NETMF.OpenSource.XBee.Api.Zigbee.AtCmd atCMD = new NETMF.OpenSource.XBee.Api.Zigbee.AtCmd;
                    //string atTemCMD = atCMD.ToString();
                    ushort atCommandGetDIO = 17456;

                   AtResponse RSSI = xbee.Api.Send(NETMF.OpenSource.XBee.Api.Zigbee.AtCmd.ReceivedSignalStrength).GetResponse();
                    XBeeRequest xbeeRequest1 = xbee.Api.CreateRequest(atCommandGetDIO, nodeAddress, timeout[1]);

                    Debug.Print(xbeeRequest1.ToString());
                    XBeeResponse response = xbee.Api.Send(xbeeRequest1).GetResponse();
                    Debug.Print(response.ToString());                   
                 }
Again, All I want is the node at the given address to report it's ADC value. Doing this does return a value but I don't think it is the correct value. Is this a valid approach? Is there anything else I should be doing here?
Thanks,
~Shane
May 9, 2014 at 7:24 PM
Ok I figured this one out. There is a lot of good information here: https://xbee.codeplex.com/discussions/444243 and here http://examples.digi.com/wp-content/uploads/2012/07/XBee_ZB_ZigBee_AT_Commands.pdf . I realized that I was trying to poll the register status of the pin, rather than the value. What I was trying to do was get the value.

Here is the new code that works with no exceptions:
            XBeeAddress64 nodeInfo = new XBeeAddress64();
            NETMF.OpenSource.XBee.Api.Common.DiscoverResult[] nodes = new NETMF.OpenSource.XBee.Api.Common.DiscoverResult[2];
            try
            {

                nodes = xBee.Api.DiscoverNodes();
            }
            catch (Exception Ex)
            {
                Debug.Print("Error : " + Ex.Message.ToString()); 
            }

            if (xBee.Api.IsConnected())
            {
                if (nodes.Length > 0)
                {
                    nodeInfo = nodes[0].NodeInfo.SerialNumber;

                    try
                    {
                        XBeeResponse value = xBee.Api.Send(NETMF.OpenSource.XBee.Api.Zigbee.AtCmd.ForceSample).To(nodeInfo).Timeout(1000).GetResponse();
                    }
                    catch (Exception ex)
                    {
                        Debug.Print("Error : " + ex.Message.ToString());
                    }
                }
            }
            else
            {
                Debug.Print("no xbee's connected" + "\r\n");
            }
        }