[title]CDC to SerialPort Bridge[/title]
http://code.tinyclr.com/project/397/cdc-to-serialport-bridge/
[line]
This is a simple USB CDC port (virtual USB COM port) to Serial bridge (everything that is coming from the USB virtual COM port is transfered to any COM port on the FEZ, and vice-versa).
Why ?
Sometimes, you need to have your application talk directly with a device connected to your Fez (shield with serial interface for an example), for test purposes or to upgrade its firmware. It does not replace a regular FTDI cable than should be prefered when you have one available, but can be use to talk to something already connected with a serial port (UART) to your Fez.
How ?
It seem pretty simple to do, however it was not to make it reliable and as real-time as possible (not loosing a single data byte for full speed 19200 bits/s full-duplex without handshaking and even more with handshaking). To make something as close to possible with real-time, your enemy is garbage collector. If it runs while you UART receive buffer is full, you will most likely loose its contents. Therefore, to avoid that, no dynamic allocation is made here, and no event is used to receive UART data (wich is putting things on the stack, to be garbage collected at some point…). I found out anyway than reveiving serial data using events was not faster than a simple loop in a separate thread.
You may prefer to use COM2 on your FEZ if you can, since only this port has hardware handshaking wires available if you need it (speeds faster than 19200bits/s). Up to 19200bits/s or using software handshaking (XON/XOFF, if you device supports it), any FEZ com port would be fine
You will need a CDC driver on your computer :
- Either you are debugging with USB and wish to share the USB port between the debugging interface and the CDC port (remove the first line of the main()), use this driver : http://www.ghielectronics.com/downloads/NETMF/Library%20Documentation/GHI_NETMF_Interface_with_CDC.zip
- Either you want a standalone CDC driver (without GHI drivers), since you are using serial debugging or to deploy at your customer premises, then use this one : http://www.ghielectronics.com/downloads/NETMF/Library%20Documentation/CDC_Driver.inf
Updated 12/15/2011 to v0.2 : now stands in a clean class, disposable.
As usual, please submit bug reports to opensource (at) grisambre (dot) net !