Actions

USB to Serial

From SharedSkies

With the disappearance of serial hardware on off-the-shelf computers, we are increasingly reliant on USB-to-Serial converters to integrate older serial technology with observatory operations. Indeed, even recently manufactured hardware may present a USB interface that is underneath a converter to hardware serial.

Fortunately, the Linux kernel has built-in support for the FTDI hardware that is used by Optec, Software Bisque, Planewave and Sidereal Technologies. This is a robust and reliable solution and we use their plug-in versions where we need to add serial ports to an existing computer.

When the udev manager detects a converter it assigns it to one of several devices labeled /dev/ttyUSBx where x is 0, 1, 2 ... and so on. The order of the assignment will depend on the order of detection, and is not fixed. This presents a small problem with software that is looking for a particular device. The solution is to create a rule in a file located in /etc/udev/rules.d that identifies specific converters and assigns their device through a softlink to a static device name.

We use the file

61-ttyUSB-special.rules

which contains for example the following lines

# Optec IFW USB to serial converter
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="FTWLM5CH", SYMLINK+="ifw"
LABEL="ttyUSB_rules_end"


We note that the subsystem is not "tty", but "usb" and that the proper labels have "S" in them.

The helpful command to figuring out what to put here is "udevadm info" which will return all sorts of details about the devices. So for example,

udevadm info /dev/ttyUSB0 

we see

P: /devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.5/1-1.5:1.0/ttyUSB0/tty/ttyUSB0
N: ttyUSB0
S: ifw
S: serial/by-id/usb-FTDI_UC232R_FTE19PSH-if00-port0
S: serial/by-path/pci-0000:00:1a.0-usb-0:1.5:1.0-port0
E: DEVLINKS=/dev/ifw /dev/serial/by-id/usb-FTDI_UC232R_FTE19PSH-if00-port0 /dev/serial/by-path/pci-0000:00:1a.0-usb-0:1.5:1.0-port0
E: DEVNAME=/dev/ttyUSB0
E: DEVPATH=/devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.5/1-1.5:1.0/ttyUSB0/tty/ttyUSB0
E: ID_BUS=usb
E: ID_MODEL=UC232R
E: ID_MODEL_ENC=UC232R
E: ID_MODEL_FROM_DATABASE=FT232 USB-Serial (UART) IC
E: ID_MODEL_ID=6001

which has the information we need but not the rules keywords. To get those, take the full path given in the first line and use it again with different command line keys


udevadm info -a -p /devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.5/1-1.5:1.0/ttyUSB0/tty/ttyUSB0

to return

   KERNELS=="1-1.5"
   SUBSYSTEMS=="usb"
   DRIVERS=="usb"
   ATTRS{bDeviceSubClass}=="00"
   ATTRS{bDeviceProtocol}=="00"
   ATTRS{devpath}=="1.5"
   ATTRS{idVendor}=="0403"
   ATTRS{speed}=="12"
   ATTRS{bNumInterfaces}==" 1"
   ATTRS{bConfigurationValue}=="1"
   ATTRS{bMaxPacketSize0}=="8"
   ATTRS{busnum}=="1"
   ATTRS{devnum}=="12"
   ATTRS{configuration}==""
   ATTRS{bMaxPower}=="100mA"
   ATTRS{authorized}=="1"
   ATTRS{bmAttributes}=="a0"
   ATTRS{bNumConfigurations}=="1"
   ATTRS{maxchild}=="0"
   ATTRS{bcdDevice}=="0600"
   ATTRS{avoid_reset_quirk}=="0"
   ATTRS{quirks}=="0x0"
   ATTRS{serial}=="FTE19PSH"
   ATTRS{version}==" 2.00"
   ATTRS{urbnum}=="16"
   ATTRS{ltm_capable}=="no"
   ATTRS{manufacturer}=="FTDI"
   ATTRS{removable}=="removable"
   ATTRS{idProduct}=="6001"
   ATTRS{bDeviceClass}=="00"
   ATTRS{product}=="UC232R"

The rule line can be changed for various USB serial converters. Since most have the same vendor and model, it's the serial number that distinguishes them. The software would be written to use the soft link that is created by the rule, in this case /dev/ifw for the filter wheel. We can use a similar technique to identify more than one Apogee camera if we ever have that.


Finally, when new rules are installed it may help to unplug and replug the USB device. These commands will often have the same effect:

 udevadm control --reload-rules
 udevadm trigger