Just before a PDA with wifi features, so instead of using a PC to control the Smart car via ZigBee, it's more convenient to control it with a PDA, but since the. NET MF Development Board does not directly support WiFi, we have to control it indirectly, that is, PDA control pc, PC through ZigBee control intelligent car.
For our developers, WiFi is the same as the normal cable interface, is the socket programming. We only need to build a simple TCP client on the PDA, the PC to build a TCP server side, the PDA to send the relevant instructions, the PC received through the ZigBee forward to the smart car.
PDA ===> Wifi (TCP/IP) ===> PC ===> Zigbee (serial 232/ttl) ===> intelligent car
PC through ZigBee control intelligent car, in my last blog "ZigBee Remote control intelligent car" has been introduced, so here is skipped.
We first develop the program on the PDA (operating system Windows Mobile 5.0), the development language we choose C #, the relevant code is as follows:
Public Frmmain ()
{
InitializeComponent ();
Connect ("192.168.1.2", 7722);
}
public void Connect (string server,int port)
{
Sock = new Socket (AddressFamily.InterNetwork, SocketType.Stream, protocoltype.tcp);
if (ipendpoint!= null) sock. Connect (Getendpoint (server, port));
}
private void Btnforward_click (object sender, EventArgs e)
{
if (sock!= null) sock. Send (New byte[] {48});
}
private void Btnleft_click (object sender, EventArgs e)
{
if (sock!= null) sock. Send (New byte[] {49});
}
private void Btnright_click (object sender, EventArgs e)
{
if (sock!= null) sock. Send (New byte[] {50});
}
private void Btnback_click (object sender, EventArgs e)
{
if (sock!= null) sock. Send (New byte[] {51});
}
private void Btnstop_click (object sender, EventArgs e)
{
if (sock!= null) sock. Send (new byte[] {52});
}
The results of the compilation run are as follows: