jefffhaynes / XBee

A .NET library for XBee wireless controllers
MIT License
40 stars 17 forks source link

I'm a beginner, please help #22

Closed xhr0428 closed 7 years ago

xhr0428 commented 7 years ago

Hi, I just started with this library. I was running the Tester example using 2 S2C modules with ZigBee firmware. I found the first character of my serial message was always missing. Then I checked the addresses in dataFrame, it looks like the first byte (00) of high part of the 64-bit address is not taken and the first byte of the 16-bit address is added as the last byte of the 64-bit address. Similarly, probably the first character of the serial message is actually used for the field before data, i.e. Receive options? How should I fix this or did I do anything wrong? Thank you for your help.

private static void Main(string[] args) { MainAsync(); Console.ReadKey(); _xbee.Dispose(); } private static async void MainAsync() { _xbee = new XBeeController("COM6", 9600); await _xbee.OpenAsync("COM6", 9600); _xbee.DataReceived += (sender, eventArgs) => Console.WriteLine("Received {0} bytes", eventArgs.Data.Length); }

jefffhaynes commented 7 years ago

What API mode is your XBee in?


From: xhr0428 notifications@github.com Sent: Thursday, May 11, 2017 11:24:23 PM To: jefffhaynes/XBee Cc: Subscribed Subject: [jefffhaynes/XBee] I'm a beginner, please help (#22)

Hi, I just started with this library. I was running the Tester example using 2 S2C modules with ZigBee firmware. I found the first character of my serial message was always missing. Then I checked the addresses in dataFrame, it looks like the first byte (00) of high part of the 64-bit address is not taken and the first byte of the 16-bit address is added as the last byte of the 64-bit address. Similarly, probably the first character of the serial message is actually used for the field before data, i.e. Receive options? How should I fix this or did I do anything wrong? Thank you for your help.

private static void Main(string[] args) { MainAsync(); Console.ReadKey(); _xbee.Dispose(); } private static async void MainAsync() { _xbee = new XBeeController("COM6", 9600); await _xbee.OpenAsync("COM6", 9600); _xbee.DataReceived += (sender, eventArgs) => Console.WriteLine("Received {0} bytes", eventArgs.Data.Length); }

— 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/22, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AJSKR-fO09Dsk_4O_SbEts82cqPKkjAPks5r4_sXgaJpZM4NY4vf.

xhr0428 commented 7 years ago

Hi, thanks for the reply. Coordinator is in API mode 1, end device is in transparent mode.

jefffhaynes commented 7 years ago

Hm, everything looks correct. Is COM6 a normal serial port? Any chance there's something screwy going on with the driver?

xhr0428 commented 7 years ago

COM6 is the com for the coordinator. Using the same com I can get complete messagen in xctu.

jefffhaynes commented 7 years ago

Can you please add this code and see what you get? Depending on what type of program this is, you may need to use Debug instead of Console.

_xbee.FrameMemberSerializing += XbeeOnFrameMemberSerializing;
_xbee.FrameMemberSerialized += XbeeOnFrameMemberSerialized;
_xbee.FrameMemberDeserializing += XbeeOnFrameMemberDeserializing;
_xbee.FrameMemberDeserialized += XbeeOnFrameMemberDeserialized;
private static void XbeeOnFrameMemberSerializing(object sender, MemberSerializingEventArgs e)
{
    Console.CursorLeft = e.Context.Depth * 4;
    Console.WriteLine("S-Start: {0}", e.MemberName);
}

private static void XbeeOnFrameMemberSerialized(object sender, MemberSerializedEventArgs e)
{
    Console.CursorLeft = e.Context.Depth * 4;
    var value = e.Value ?? "null";
    Console.WriteLine("S-End: {0} ({1})", e.MemberName, value);
}

private static void XbeeOnFrameMemberDeserializing(object sender, MemberSerializingEventArgs e)
{
    Console.CursorLeft = e.Context.Depth * 4;
    Console.WriteLine("D-Start: {0}", e.MemberName);
}

private static void XbeeOnFrameMemberDeserialized(object sender, MemberSerializedEventArgs e)
{
    Console.CursorLeft = e.Context.Depth * 4;
    var value = e.Value ?? "null";
    Console.WriteLine("D-End: {0} ({1})", e.MemberName, value);
}
xhr0428 commented 7 years ago

Hi, I tried the code. Here is what appeared in the console. 0 in FrameId should be the starting byte of the long address. Last byte of long address (DD) should be the first byte of the short address. (E8) in short address should be SourceEndpoint. The number (97) in options is actually the first character of the serial message. It looks like the data package is not divided correctly. There is one byte shifted.

Running D-Start: StartDelimiter D-End: StartDelimiter (FrameDelimiter) D-Start: Length D-End: Length (25) D-Start: Payload D-Start: FrameType D-End: FrameType (RxIndicatorExplicitExt) D-Start: Content D-Start: FrameId D-End: FrameId (0) D-Start: Source D-Start: Value D-End: Value (1414693511956423645) D-End: Source (13A20040F63663DD) D-Start: ShortAddress D-Start: Value D-End: Value (58344) D-End: ShortAddress (E3E8) D-Start: SourceEndpoint D-End: SourceEndpoint (232) D-Start: DestinationEndpoint D-End: DestinationEndpoint (0) D-Start: ClusterId D-End: ClusterId (4545) D-Start: ProfileId D-End: ProfileId (1281) D-Start: Options D-End: Options (97) D-Start: Data D-End: Data (System.Byte[]) D-End: Content (XBee.Frames.RxIndicatorExplicitExtFrame) D-End: Payload (XBee.FramePayload) D-Start: Checksum D-End: Checksum (187) D-Start: StartDelimiter Received 6 bytes

jefffhaynes commented 7 years ago

Ah! I've never actually used an explicit rx frame before. There seems to be a bug as there should not be a frame ID field. Let me fix and republish.

On Sat, May 13, 2017 at 1:27 AM, xhr0428 notifications@github.com wrote:

Hi, I tried the code. Here is what appeared in the console. 0 in FrameId should be the starting byte of the long address. Last byte of long address (DD) should be the first byte of the short address. (E8) in short address should be SourceEndpoint. The number (97) in options is actually the first character of the serial message. It looks like the data package is not divided correctly. There is one byte shifted.

Running D-Start: StartDelimiter D-End: StartDelimiter (FrameDelimiter) D-Start: Length D-End: Length (25) D-Start: Payload D-Start: FrameType D-End: FrameType (RxIndicatorExplicitExt) D-Start: Content D-Start: FrameId D-End: FrameId (0) D-Start: Source D-Start: Value D-End: Value (1414693511956423645) D-End: Source (13A20040F63663DD) D-Start: ShortAddress D-Start: Value D-End: Value (58344) D-End: ShortAddress (E3E8) D-Start: SourceEndpoint D-End: SourceEndpoint (232) D-Start: DestinationEndpoint D-End: DestinationEndpoint (0) D-Start: ClusterId D-End: ClusterId (4545) D-Start: ProfileId D-End: ProfileId (1281) D-Start: Options D-End: Options (97) D-Start: Data D-End: Data (System.Byte[]) D-End: Content (XBee.Frames.RxIndicatorExplicitExtFrame) D-End: Payload (XBee.FramePayload) D-Start: Checksum D-End: Checksum (187) D-Start: StartDelimiter Received 6 bytes

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jefffhaynes/XBee/issues/22#issuecomment-301226546, or mute the thread https://github.com/notifications/unsubscribe-auth/AJSKR7D8YRMQm3Ra2eIBtVLnaXSOEyqdks5r5T9AgaJpZM4NY4vf .

-- If you want to build a ship, don't drum up people together to collect wood and don't assign them tasks and work, but rather teach them to long for the endless immensity of the sea.

Antoine de Saint-Exupery

jefffhaynes commented 7 years ago

Sorry about that, please try 4.2.

xhr0428 commented 7 years ago

It works. Thanks

jefffhaynes commented 7 years ago

Great, glad to hear it.


From: xhr0428 notifications@github.com Sent: Saturday, May 13, 2017 5:44:36 PM To: jefffhaynes/XBee Cc: Jeff Haynes; Comment Subject: Re: [jefffhaynes/XBee] I'm a beginner, please help (#22)

It works. Thanks

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/jefffhaynes/XBee/issues/22#issuecomment-301276708, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AJSKRyH6dB3DbKEJ8zmvtL0xHevDsDiOks5r5iREgaJpZM4NY4vf.