cdctool

When building devices with USB capable microcontrollers, a quick and simple option for communicating with a host PC is to use CDC, a virtual serial port. This handy mechanism is built into all modern PC operating systems. However, the way you open a serial port, set line settings, and start speaking serial are very different between Microsoft Windows and POSIX based platforms. This library and program bridges the differences between the two APIs and supplies a console tool for making communication in scripts much simpler.

CDCTool is a cross platform library and command line tool for sending and receiving short amounts of text from a serial connection. It wraps the separate Win32 and POSIX serial communications APIs into a single package. The library eases cross platform serial coding. The command line tool is useful for sending quick messages or for shell scripting.

Links

Example (Windows)

$ echo "V" | cdctool COM4
Bumble-B 0.4 (userial 1.6)

Example (Linux)

$ echo "V" | cdctool /dev/ttyACM0
Bumble-B 0.4 (userial 1.6)

UPDATE: Three new features are in the works:

  1. Interactive mode
    Currently the cdctool command line program does this: open, write, read, close. It is not particularly friendly for an interactive session on a terminal. Interactive mode will parse input lines from the terminal and send them individually.
  2. Discovery
    This feature will scan through com ports sending a specified command. It will match each result against a specified regular expression, and return a list of ports that match the query. This library and tool are much more useful if your program doesn't need to know the exact name of the port needed.
  3. SWIG Bindings
    Bindings for many scripting languages are planned through SWIG. The first one with complete support will be Java.

UPDATE 2: Interactive mode is available in cdctool, version 0.0.3. Use the -a switch on the command line.

UPDATE 3: The discovery feature is available in cdctool 0.0.5. A new command line program "cdcdiscover" and related library routines can be used to find devices. It takes two arguments, a command to send to serial ports that it finds, and a regular expression to match against the results. Example:$ cdcdiscover V Bumble-B
COM4
This feature enables scripts and programs to communicate with serial devices without knowing the name of the port ahead of time. The same scripts can therefore be used without changes on multiple platforms.