Main Site Documentation

ZigBee Write & Writeline Command


#1

Hello,
The issue is that the ZigBee write and writeline command appear to work but the data does not arrive on my corresponding radio. The 2 radios work fine through x-ctu and also work fine over a normal c#4.5 console app. However when I plug one radio into the fez board it does not work/send/receive data from my other radio on x-ctu. Make sense? All/any suggestions gratefully accepted.
Thanks.
Here is the code (NEMF 4.1 code) -

using


System;

using


System.IO.Ports;

using


System.Text;

using


System.Threading;

using


Microsoft.SPOT;

using


GHIElectronics.Gadgeteer;

using


Microsoft.SPOT.Presentation.Controls;

using


Serial = Gadgeteer.Interfaces.Serial;

using


Gadgeteer.Modules.GHIElectronics;

using


Timer = Gadgeteer.Timer;

 

namespace


ZigbeeTester1

{



public partial class Program

{



// This method is run when the mainboard is powered up or reset. 



void ProgramStarted()

{



/*******************************************************************************************

Modules added in the Program.gadgeteer designer view are used by typing 

their name followed by a period, e.g. button. or camera.



Many modules generate useful events. Type +=<tab><tab> to add a handler to an event, e.g.:

button.ButtonPressed +=<tab><tab>



If you want to do something periodically, use a GT.Timer and handle its Tick event, e.g.:

GT.Timer timer = new GT.Timer(1000); // every second (1000ms)

timer.Tick +=<tab><tab>

timer.Start();

*******************************************************************************************/

 



// Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.



Debug.Print("Program Started");



//XbeeTester2();





if(XbeeTester())

led.TurnBlue();



else

led.TurnRed();



}





bool XbeeTester()

{

xBee.Configure(9600, 

Serial.SerialParity.None, Serial.SerialStopBits.One, 8);

xBee.SerialLine.Encoding = 

Encoding.UTF8;

xBee.SerialLine.LineReceived += 

new Serial.LineReceivedEventHandler(SerialLine_LineReceived);

xBee.SerialLine.DataReceived += 

new Serial.DataReceivedEventHandler(SerialLine_DataReceived);







try

{



}



catch(Exception ex)

{



string s = "";

}





Thread.Sleep(1000);

button.ButtonReleased += 

new Button.ButtonEventHandler(button_ButtonReleased);



return true;

}



void button_ButtonReleased(Button sender, Button.ButtonState state)

{





xBee.SerialLine.ReadTimeout = 100000;

xBee.SerialLine.WriteTimeout = 100000;

xBee.SerialLine.Open();

xBee.SerialLine.WriteLine(

"boooo\n");

xBee.SerialLine.Flush();



byte[] bytes = Encoding.UTF8.GetBytes("zzz\n"); ;

xBee.SerialLine.Write(bytes, 0, bytes.Length);





}

 



void SerialLine_DataReceived(Serial sender, SerialData data)

{

}



void SerialLine_LineReceived(Serial sender, string line)

{



}



void SerialPortErrorReceived(object sender, SerialErrorReceivedEventArgs e)

{



throw new NotImplementedException();

}

}

}

#2

Using code tags will make your post more readable. This can be done in two ways:[ol]
Click the “101010” icon and paste your code between the

 tags or...
Select the code within your post and click the "101010" icon.[/ol]
(Generated by QuickReply)

#3

are you on the right serial port?


#4

I had this reply from another source… so just working through this suggestion.

That is a definite sticking point and there are two ways to solve it. The easiest is to use Paul Mineau’s XBee Client Library. See this post and the comments: http://wp.me/p1TEdE-nN
The XBee Client Library is here: http://xbeeclient.codeplex.com/
Else you can parse the byte stream manually. The code is available in Paul’s Code Plex site.


#5

Series 1 or Series 2 XBee?

I recommend using the xbee library on Codeplex. Note that the hardware reset pin is NOT brought out properly on the GHI module, so you’ll need to solder a wire from the wake pin to one of the gadgeteer pins. It’s an annoying problem that I’ve mentioned about on these forums before, but GHI hasn’t run an updated revision of the board yet. Ugh.

You’ll need the wake pin because the devices tend to go to sleep (even if you specifically tell them not to). It’s odd.


#6

Hi Jay,
(Series 2)

I received this advice aswell… apparently Microsoft are about to deliver 4.3 version. He sounded like they will try to fix this problem, which is with line received event handler. You can also parse bytes in the data received event, but XBee Client is much easier. I used the line received event in this example, http://wp.me/p1TEdE-m0 , but I had to run in the debugger to get it to work.

We couldn’t get the XBee working using the client library mentioned and running in debugger mode isn’t really a solution…
It will take a while for GHI to release the SDK for 4.3 so we could be waiting ages to get XBee to work. argh

I’m not sure where to begin with your advice? Could you post an image?
This problem is really slowing down a project I’m working on… we’ve had to resort to using RJ45 ethernet module instead of wireless :-/

Thanks


#7

@ andre.m -
Hi,
Thanks for your advice, I will pass this onto the developer…
We are using X2 FEZ mainboards & X2 XBee 2mW Module with Chip Antenna (Series ZB)
The alternative RF chips look interesting, no reason why serial from netmf core shouldn’t work with the above setup?
We are working towards a pitch to investors and we would really like to show a wireless solution so I’m trying my hardest to find a solution for the developer.
Thanks, Jason


#8

@ andre.m -

Hi,
Weve had a few problems with gadgeteer, its been a pain staking process to code up the communication layer at the low level using the limited micro frame work class set.

We have a Hub that is the coordinator and device that is the router in a mesh network using nodes to allow constant communication with the devices.
I not sure what language we are using to code the Xbee chips, I thought they where setup using XCTU?

Would you advice against using .Net Framework commercially?
Our competitors use Linux, I choose gadgeteer because it looked like a robust platform to build a prototype and I was hoping we could use it commercially.

We where thinking about designing and manufacturing custom PCBs specific for our requirements and porting .Net framework, for example we only use a third of the ports on the Fez spider and we need to reduce the costs.

Sorry to go off topic but these are related problems with what we are doing.
Weve got an idea to solve a problem but it requires hardware and software.
Weve designed the user experience and are working backwards to the technology, easier said than done :-/

Thanks for taking the time to reply, going to print out your responses and chat through with our developers.

Jason


#9

@ jason1013pantone - .Net is used commercially more than you think…

I happy send serial data between boards with xbees without issue.

Can you give a short explanation on your goal?


#10

I guess I’m a little confused by what you’re trying to do. I looked at your source code, and it looks like you’re trying to program the XBee API by hand.

Don’t reinvent the wheel. If you’re using Series 2 XBees, just use the open-source XBee library that already has proven functionality: http://xbee.codeplex.com/

It does’t use any Gadgeteer-specific functionality (like the troublesome LineReceived event), so you shouldn’t have any problems receiving data from the XBees.


#11

Hi All,

Thanks for all your feedback, you can probably tell I’m not a developer, I’ve setup the project with a friend and we’ve got a developer on-board doing coding in his spare time, unfortunately he hasnt managed to setup and implement the XBee chips using the client librarys mentioned.

Its reassuring to hear about Netmf and that there are plenty of commercial projects out there. I feel totally out of my depth with this aspect of the project, but still liking the learning curve :slight_smile:

I would really like to get the XBee chips working so if anyone can help with the project I would be really grateful… I dont want to try and reinvent the wheel, so do you think we arent setting up the XBee chips correctly?

My background is product design, I’ve designed and built the prototypes to house the GHI components, and it would be really cool to see the prototype products work without using cables… The ZigBee part of the project is a real bottleneck so any advice on how did get this setup would be much appreciated.

Thanks, Jason


#12

@ jason1013pantone - Hi Jason, cool looking enclosures :slight_smile:

From what you have spoken about it should be really easy (famous last words i know)
I speak a colonial version of the Queens English as i’m not far from you up the A1…so if you want to ping me an email justin at ingenuitymicro dot com i’m sure i can help you out :slight_smile:


#13

@ Justin - Thanks Justin, we bought a Solidoodle 3D printer to make the enclosures.
Thats wicked, I’ll send you an email with more info.
Cheers