Sampling IO and retrieve message on UART

Apr 16, 2013 at 2:27 PM
I sends periodically samples IO from one XBee (ZigBee End Device API – Firmware 29A7) installed on an X-BIB USB card to another XBee (ZigBEE Coordinator API – Firmware 21A7) installed on an X-BIB-USB card.
I try to retrieve the IO message on the coordinator UART with GBee library but I receive nothing.

I receive the samples IO periodically on the coordinator (I see the received led which flashes periodically when I press a switch) but I have no event on the Coordinator (No event data received).

If I send a message « Hello from Coordinator » with GBee API from Coordinator to End device I have a GBee event and I receive the message.

If I send a message « Hello from End Device » with GBee API from End device to the Coordinator I have a GBee event and I receive the message.

ZigBee Coordinator API - Firmware 21A7 (default parameters) and this settings:
AP=2

ZigBee End Device API - Firmware 29A7 (default parameters) and this settings:
AP = 2
IR = 1000 sample every 4s
IC = F Digital change detection
V+=0 Supply voltage high
PR=1FFF pull up resistor
D0 = 3 digital input
D1 = 3 digital input
D2 = 3 digital input
D3 = 3 digital input

I do not know where the problem is.
Is it possible that GBee library filters this type of message?

Best regards
Christian
Coordinator
Apr 22, 2013 at 9:53 AM
Hello Christian,

You are on the right track all you need are some little hints. You are receiving data using the DataReceived event right? This event is fired when XBee receives a Data packet from other node. What you are looking for are I/O sample packets. Those are different type of packets and there is no IOSampleReceived event so you need to add your own listener. First of all create a class that derives from IPacketListener interface, e.g.
    public class IoSampleListener : IPacketListener
    {
        public bool Finished { get { return false; } }

        public void ProcessPacket(XBeeResponse packet)
        {
            if (packet is IoSampleResponse)
                ProcessIoSample(packet as IoSampleResponse);
        }

        private void ProcessIoSample(IoSampleResponse packet)
        {
            // TODO: your code here
        }

        public XBeeResponse[] GetPackets(int timeout)
        {
            throw new System.NotSupportedException();
        }
    }
Add this listener to your XBee client object
xBee.AddPacketListener(new IoSampleListener());
This listener will process every incoming frame and invoke your code only for those that are I/O samples. If you encounter problem you can turn on the logger like this:
NETMF.OpenSource.XBee.Util.Logger.Initialize(Debug.Print, LogLevel.All);
Apr 3 at 3:50 PM
Hi,

I have a question about this listener. It feels like it might be more of a C# question but it would probably be helpful to be answered here. I'd like to use these packets in a different class within my namespace.

I haven't tested it yet but I think this is what I'd like to do:
namespace xbeeDemo
{
    public class IoSampleListener : IPacketListener
    {
        public void ProcessPacket(XBeeResponse packet)
        {
            if (packet is IoSampleResponse)
            {
                ProcessIoSample(packet as IoSampleResponse);
            }
        }

        public IoSampleResponse ProcessIoSample(IoSampleResponse packet)
        {
            // TODO: your code here
            return packet; 
        }

        public XBeeResponse[] GetPackets(int timeout)
        {
            throw new System.NotSupportedException();
        }
    }
    
    class Program
    {
        static void Main(string[] args)
        {
             // Create an object of type MyCustomClass.
            IoSampleListener  myListener = new IoSampleListener();
            xBee.AddPacketListener(myListener);
            
             // Call a public method. 
             IoSampleResponse result = myListener.ProcessIoSample();
          }    
    }
}
Do you see anything immediately wrong with this approach?

Thanks,
~Shane
Coordinator
Apr 3 at 4:08 PM
Yes this is C# basics question. You can (should) write your code in your own namespace and use code from other namespaces by adding 'usings' at the top of the file.