Open mwiht opened 5 years ago
Sure, it just might be a few days. In the meantime, take a look at the DataReceived event on the XBeeNode class (s2 in your case). Generally speaking, the raw frame information isn’t always available as that is abstracted by the handlers. However, if there is information being hidden or lost I can expose that.
I’ll take a better look at this when I have time.
Cheers
From: mwiht notifications@github.com Sent: Tuesday, May 21, 2019 12:48 AM To: jefffhaynes/XBee Cc: Subscribed Subject: [jefffhaynes/XBee] Request for additional documentation (#58)
Thank you for creating this library! I'm a teacher and want to use your library to get my programming students working with electronics. Unfortunately much of the supplied documentation and demo app you included with the library goes over my head. This isn't really an issue, so much as a request to update the supplied documentation. The current documentation goes into depth on how to send configuration commands to xbees, but I haven't been able to decipher the most basic features: how to read serial and pin state changes from remote radios.
I'm trying to create my first UWP application with a raspberry pi running windows 10 IOT. I've configured a coordinator and router using XCTU. The rpi is connected to the coordinator. The router is connected to an arduino which sends both updates on pin state changes (xbee frame type 92) as well as sending periodic temperature readings as a serial string (xbee frame type 90).
I think I figured out how to get the rpi and xbee talking through the rpi UART using the code below. When I run the last line s2.GetSerialNumberAsync(); the output window in visual studio lights up with a wealth of information, so I know the xbee and rpi are talking. What I can't figure out is how to intercept and isolate the specific information I need from the frame. The frame specification states that a lot of information is received with each pin state change. For example, the 64bit address of the radio that sent the data, the length, the pin state sample itself, etc. I know your library is decoding this information somewhere because I can see it zooming by in the output window. I can't figure out how to intercept it and access each component of the frame.
Would you mind updating the readme file with an example of how to create an event handler that will read pin changes and serial data and store each piece of information from the frame in some easily accessible way? Thank you again for creating this library and for any assistance you can offer. I know my students will have a blast with this if I can figure it all out for myself :)
Here is how I'm making the connection between the coordinator and rpi and all I've managed to do so far:
public void readXbee() { Task.Run(async () => { string aqs = SerialDevice.GetDeviceSelector("UART0"); / Find the selector string for the serial device / var dis = await DeviceInformation.FindAllAsync(aqs); / Find the serial device with our selector string / SerialDevice SerialPort = await SerialDevice.FromIdAsync(dis[0].Id); / Create a serial device with our selected device /
/* Configure serial settings */
SerialPort.WriteTimeout = TimeSpan.FromMilliseconds(1000);
SerialPort.ReadTimeout = TimeSpan.FromMilliseconds(1000);
SerialPort.BaudRate = 9600;
SerialPort.Parity = SerialParity.None;
SerialPort.StopBits = SerialStopBitCount.One;
SerialPort.DataBits = 8;
//taken from the xbee library demo app:
SerialDeviceWrapper sdw = new SerialDeviceWrapper(SerialPort);
//xbee library:
var controller = new XBeeController(SerialPort);
await XBeeController.FindControllersAsync(9600);
var s2 = new XBeeSeries2(controller);
var serial = await s2.GetSerialNumberAsync(); //this makes my output window light up with information I don't know how to access
}
}
Requesting an example of some event handler that does something like this: magic_handler_AutomaticallyRunWhenDataReceived(FrameInformation e) { if(e.frametype==92) { Console.writeline(e.pinState); Console.writeline(e.Address); }
if(e.frametype==90) { Console.writeline(e.StringData); Console.writeline(e.Address); } }
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/jefffhaynes/XBee/issues/58?email_source=notifications&email_token=ACKIUR36O5JUZPCSXDNVKOTPWN5IZA5CNFSM4HOHKLA2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4GU3YCNA, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ACKIUR6R76EH7NIRXBJAOXTPWN5IZANCNFSM4HOHKLAQ.
Thank would be great. No rush. I have all summer to play with it. I did look at DataReceived, but I don't think I was using it properly as I couldn't get it to compile. I'll take another stab at it. Thanks again for your consideration.
Ok, I think I've got this figured out. This example seems to be working for me.
In this example, the coordinator is attached to the computer (or raspberry pi). Other xbee's are configured as Routers in remote locations. The routers send pin changes and serial strings to the coordinator which this code will intercept and interpret. This code does not configure any of the radios. The examples in your demo app show how to do some of that. But I just use XCTU from the DIGI website to configure them.
Calling the StartXbee method will get everything rolling by opening and configuring the serial port the coordinator is attached to and subscribing to events which be be raised when data, samples, and pin state changes are received. There are a few things in here I still don't understand and haven't tested. I noted them in the comments where applicable. Having this example in the documentation would have really helped a noob like me understand a little more about how the library works, especially how the Received events work. so maybe someone else will find it helpful too ;) Thanks so much for building it! Pouring through your code trying to figure it all out really gave me an appreciation for how it works. You've put in a lot of work and I think it's awesome. I may hit you up again later, if you don't mind, as I delve in a little deeper.
RX EXAMPLE CODE:
public sealed partial class MainPage : Page { public XBeeSeries2 s2; public SerialDevice SerialPort; public XBeeController controller;
public void StartXbee()
{
Task.Run(async () =>
{
#region Serial Configuration
string aqs = SerialDevice.GetDeviceSelector("UART0"); //UART0 is for raspberry pi. Use "COM3" for a computer where 3 is the com port the xbee is on
var dis = await DeviceInformation.FindAllAsync(aqs); //Find the serial device with our selector string
SerialPort = await SerialDevice.FromIdAsync(dis[0].Id); //Create an serial device with our selected device
/* Configure serial settings */
SerialPort.WriteTimeout = TimeSpan.FromMilliseconds(1000);
SerialPort.ReadTimeout = TimeSpan.FromMilliseconds(1000);
SerialPort.BaudRate = 9600;
SerialPort.Parity = SerialParity.None;
SerialPort.StopBits = SerialStopBitCount.One;
SerialPort.DataBits = 8;
#endregion //END Serial Configuration
controller = new XBeeController(SerialPort); //create an xbee controller object
await XBeeController.FindControllersAsync(9600);
s2 = new XBeeSeries2(controller); //I don't know what this does, but it doesn't seem to work without it
var serial = await s2.GetAddressAsync(); //I don't know what this does, but it doesn't seem to work without it
//Subscribe to xbee rx events:
controller.SampleReceived += Xbee_SampleReceived;
controller.SensorSampleReceived += Xbee_SensorSampleReceived;
controller.DataReceived += Xbee_DataReceived;
});
}
#region xbee rx events
private void Xbee_DataReceived(object sender, XBee.DataReceivedEventArgs e)
{
//This event fires when a serial string is sent by a radio
//The object e contains access to all facets of the serial event. Example e.Address.LongAddress.Value.ToString("X") would print the hex address of the radio that sent the serial string. e.Data would return an array of bytes containing the string message.
}
private void Xbee_SampleReceived(object sender, SampleReceivedEventArgs e) { //The object e provides access to all facets of the sample. Example below:
//if DIO 0 is included in the list of pins that are high (litterally read like this: if a query of the list looking for dio:0 != none)
if ((e.DigitalSampleState & XBee.Frames.DigitalSampleState.Input0) != XBee.Frames.DigitalSampleState.None)
{
//do something
}
}
private void Xbee_SensorSampleReceived(object sender, SensorSampleReceivedEventArgs e)
{
//I haven't expirimented with this one, but it should work like the others
}
#endregion //END xbee rx events
Thank you for creating this library! I'm a teacher and want to use your library to get my programming students working with electronics. Unfortunately much of the supplied documentation and demo app you included with the library goes over my head. This isn't really an issue, so much as a request to update the supplied documentation. The current documentation goes into depth on how to send configuration commands to xbees, but I haven't been able to decipher the most basic features: how to read serial and pin state changes from remote radios.
I'm trying to create my first UWP application with a raspberry pi running windows 10 IOT. I've configured a coordinator and router using XCTU. The rpi is connected to the coordinator. The router is connected to an arduino which sends both updates on pin state changes (xbee frame type 92) as well as sending periodic temperature readings as a serial string (xbee frame type 90).
I think I figured out how to get the rpi and xbee talking through the rpi UART using the code below. When I run the last line s2.GetSerialNumberAsync(); the output window in visual studio lights up with a wealth of information, so I know the xbee and rpi are talking. What I can't figure out is how to intercept and isolate the specific information I need from the frame. The frame specification states that a lot of information is received with each pin state change. For example, the 64bit address of the radio that sent the data, the length, the pin state sample itself, etc. I know your library is decoding this information somewhere because I can see it zooming by in the output window. I can't figure out how to intercept it and access each component of the frame.
Would you mind updating the readme file with an example of how to create an event handler that will read pin changes and serial data and store each piece of information from the frame in some easily accessible way? Thank you again for creating this library and for any assistance you can offer. I know my students will have a blast with this if I can figure it all out for myself :)
Here is how I'm making the connection between the coordinator and rpi and all I've managed to do so far:
public void readXbee() { Task.Run(async () => { string aqs = SerialDevice.GetDeviceSelector("UART0"); / Find the selector string for the serial device / var dis = await DeviceInformation.FindAllAsync(aqs); / Find the serial device with our selector string / SerialDevice SerialPort = await SerialDevice.FromIdAsync(dis[0].Id); / Create a serial device with our selected device /
}
Requesting an example of some event handler that does something like this: magic_handler_AutomaticallyRunWhenDataReceived(FrameInformation e) { if(e.frametype==92) { Console.writeline(e.pinState); Console.writeline(e.Address); }
if(e.frametype==90) { Console.writeline(e.StringData); Console.writeline(e.Address); } }