I’m using the FEZ Raptor mainboard with .NET micro framework 4.3 and would like to connect a micro spectrometer via USB to my mainboard. I’m using a USB Client DP module for powering my Raptor.
Now my question: Is it possible to connect my spectrometer with the mainboard via USB Serial SP module or is it only for powering? I was wondering, because the classes of these module allow to read and write data but I read only to connect ONE red module to the board. I don’t want to connect the module to my pc for powering. It’s just for the spectrometer.
Hi again.
It’s the same problem. How can I use the USB Host module to communicate with an usb device?
First step is to send a command as a string/byte[] to the device and get the measerument results back as byte[].
In my oppinion the documentation is not really clear, and it would be great to get some help
It communicates via usb and if i connect it directly to my pc it appears as serial com port. But im not sure how to use the serial controller from the documentation to send some data. The receiving event is clear.
it writes data to the serial port that is connected.
Look at it in full context:
private static void usbSerial_DataReceived(UsbSerial sender, UsbSerial.DataReceivedEventArgs e)
{
for (int i = 0; i < e.Data.Length; i++)
Debug.Print(e.Data[i].ToString());
sender.Write(e.Data);
}
this is fired, when the controller receives data on the serial port. “sender” is the object within the handler, where the data arrived, and “e” is the “event args” parameter. You can see that in this case it simply takes the received data and spits it back out the same serial port (this is just a testing scenario, you wouldn’t do that).
well if you do, you’d send the data you want. There’s a good chance that this is a good test, but it is NOT likely to be all you want/need to get this working. But it should at least prove things work…
[ to explain further - it is unlikely that your app will just send the same response when it receives data. You will need to enhance your program logic significantly above what this example shows, but the concept is at least demonstrated to you. ]
There’s not an event for data sending… that doesn’t make sense, usually your app is sending on your request
You also wouldn’t likely put a send routine in the connected event handler - because that only fires once, when the device gets connected. You CAN but you wouldn’t generally - there might be specific devices where that makes sense, that need an initialisation command sent for example, but again it’s unlikely that this would be the only place you send data out the serial pipe.
What you might want to try is figuring out what the “usual” communication path with this device is, and then look at what normally triggers that. For example you might find that you need a timer to periodically request status, or you might have a looping execution mechanism that gets started in the connected event handler, or it might be user intervention based (press a button to start communications, press a different one to take a reading etc). Depending on how your device works and how you want the app to work will drive how you should approach it…