Hey guys, quick question I was hoping you pros could help me with.
Playing with a Spider mainboard at the moment…is there an efficient way I can feed it commands directly from the PC it’s plugged into?
For example, suppose I’ve got a motor plugged in and I want to spin the motor left on F1 keypress and spin the motor right on F2 keypress. Would I be able to achieve this?
I found the following example for sending Hello World to the PC
using System.Threading;
using GHI.Usb;
using GHI.Usb.Client;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware.UsbClient;
public class Program
{
public static void Main()
{
// Start Cdc
Cdc vsp = new Cdc();
Controller.ActiveDevice = vsp;
// Send "Hello world!" to PC every second. (Append a new line too)
byte[] bytes = System.Text.Encoding.UTF8.GetBytes("Hello world!\r\n");
while (true)
{
// Check if connected to PC
if (Controller.State !=
UsbController.PortState.Running)
{
Debug.Print("Waiting to connect to PC...");
}
else
{
vsp.Stream.Write(bytes, 0, bytes.Length);
}
Thread.Sleep(1000);
}
}
}
Seems pretty straightforward…what I’m unsure on is how I would send data from the other end, PC -> board.
as @ Mike says, your device will simply appear as a Serial Port on the PC side, and you will have an app that sends data over that serial port from the PC and you’ll then react appropriately in your code on the spider. You could use simple text commands (like “L” or “R” for spinning motor left or right) or it could be more complex as you need - the good thing is that you get to manage that in your PC code. Text commands are always a good place to start because you don’t need anything more than TeraTerm connecting to a serial port, and you can free type it rather than have to write an app for the PC side to start.