I test the Xbee module today.
I use the domino with a Xbee to send a text to the Spider with a xbee module and shows the text in the display. It works fine. But I have a basic question.
I use two methods to do that, both can work.
I don’t know which one is better,
or some one can give me a better example?
The domino send the text every 1000 ms.
Thanks.
1.
namespace GadgeteerApp1
{
public partial class Program
{
// This method is run when the mainboard is powered up or reset.
public static byte[] input = new byte[9];
void ProgramStarted()
{
string test = "test";
var font = Resources.GetFont(Resources.FontResources.small);
xBee.SerialLine.Open();
while (true)
{
int count = xBee.SerialLine.Read(input, 0, input.Length);
if (count > 0)
{
char[] chars = Encoding.UTF8.GetChars(input);
string str = new string(chars, 0, count);
Debug.Print(str);
led.BlinkOnce(Colors.Blue);
display.SimpleGraphics.DisplayText(str, font, Colors.Blue, 150, 150);
Debug.Print("Program Started");
Thread.Sleep(500);
display.SimpleGraphics.Clear();
}
}
}
}
}
namespace GadgeteerApp1
{
public partial class Program
{
// This method is run when the mainboard is powered up or reset.
public static byte[] input = new byte[9];
GT.Timer timer = new GT.Timer(500);
void ProgramStarted()
{
string test = "test";
var font = Resources.GetFont(Resources.FontResources.small);
xBee.SerialLine.Open();
timer.Tick += new GT.Timer.TickEventHandler(timer_Tick);
timer.Start();
}
void timer_Tick(GT.Timer timer)
{
var font = Resources.GetFont(Resources.FontResources.small);
int count = xBee.SerialLine.Read(input, 0, input.Length);
if (count > 0)
{
char[] chars = Encoding.UTF8.GetChars(input);
string str = new string(chars, 0, count);
Debug.Print(str);
led.BlinkOnce(Colors.Blue);
display.SimpleGraphics.DisplayText(str, font, Colors.Blue, 150, 150);
Debug.Print("Program Started");
Thread.Sleep(500);
display.SimpleGraphics.Clear();
}
}
}
}