I recently plugged in an USB embedded device(mbed lpc1768) using a normal USB cable to a Windows 7 desktop. According to the docs that came with the program running on the device it communicates with the host(desktop) over a USB Virtual Serial Port.
Where do I start if I need to read/write data using c#? Could I use the SerialPort .NET class or do I need to use the LibUsbDotNet library or perhaps something else?
It is excellent news when I find out that a USB device communicates in VCP rather than USB-HID, because serial connections are easy to understand.
If the device is operating in
VCP
(Virtual Com Port), then it is as easy as using theSystem.IO.Ports.SerialPort
type. You will need to know some basic information about the device, most of which can be gleaned from Windows Management (Device Manager). After constructing like so:You may or may not need to set some additional flags, such as Request to send (RTS) and Data Terminal Ready (DTR)
Then, open the port.
port.Open();
To listen, you can attach an event handler to
port.DataReceived
and then useport.Read(byte[] buffer, int offset, int count)
To send, you can use
port.Write(byte[] buffer, int offset, int count)