LucidControl USB IO Module with Constant Device Name

The LucidControl USB IO Modules are the analog and digital data acquisition and control solutions which covers most kind of input and output signals.

In order to be most flexible the USB IO Modules work under Windows and Linux computers and also on small computers like the Beagle Bone Black or the RaspberryPi series.

Using standard interfaces like USB/CDM profile allows that each USB IO Module can be accessed as a serial device. The big advantage of this procedure is that most operating systems provide standard drivers for the CDM profile and no third party software is necessary.

The USB/CDM profile provides an interface as it is known from serial ports and the same commands can be used. This makes USB IO Modules being accessible by e.g. using the fopen function in C programming language. There are tools available which redirect the traffic of the ports ports between computers connected to a network which makes it easy to control a USB IO Module remotely.

On Windows operating systems serial devices are installed as COM ports. Under Linux based OS USB/CDM compatible devices are installed as ttyACM instances.

USB IO Module connected to a RaspberryPi B+

USB Digital Input Module and USB Digital Output Module connected to a RaspberryPi B+

Problem with changing device names

Assuming that multiple identical devices (like our USB IO Modules in the picture above) are connected to a computer it must be ensured that the devices are not mixed up and the operating system assigns a fixed device name to a device e.g. after a restart.

A temperature controlling application can for example consist of a Pt1000 temperature measurement module and an USB Digital Output Module which controls some valves or pumps depending on the measured temperatures.

The two USB IO Modules must be accessible by a constant device name like COM10 which must not change over time e.g. after a re-boot of the system because the application is not aware if a device name change.

In the following it is described how to ensure fixed device names especially running Linux. Even if this article concentrates on or USB IO Modules, the described principle can be used for most kind of serial devices.

How does the OS identify a USB device

All USB devices provide a vendor ID (VID) and a product ID (PID) which are unique. By using these two values the manufacturer and the device can be identified.

If more than one identical devices (all our USB IO Modules have same VID and PID) are connected a computer the devices can be distinguished by the USB serial number which is unique for each USB IO Module. The USB serial number consists of the device class (e.g. USB Digital Output Module), the device type (e.g. 10V type), and a internal serial number of the USB IO Module.

./LucidIoCtrl -d/dev/ttyACM0 -i
DEVICE CLASS: 0000 (DIGITAL INPUT 4 CHANNELS)
DEVICE TYPE: 1001 (10V)
SERIAL NUMBER: 8C010000
FIRMWARE REVISION: 0009
HARDWARE REVISION: 01

The example above uses the LucidIoCtrl command line tool and identifies the USB IO Module connected to /dev/ttyACM0. The USB serial number is “000010018C010000” which is a concatenation of device class, device type, and device serial number.

Situation with Windows

Computers running a Windows operating system install the device and store the installed comport name in the registry. During a system restart the same comport is assigned if an existing device entry is found in the registry. The user can change the settings e.g. the comport number which is stored in the registry also.

Create fixed device names with Linux

Linux assigns a device name during boot time and there is no automatic mechanism that a certain device is installed with a fixed device name. The device which is detected first gets e.g. /dev/ttyACM0, the second one /dev/ttyACM1 and after a re-boot this can change. Hence this device name can not reliably be used when more than one USB IO Module is connected to the computer because it is some kind of random.

Under Linux a bit more attention is needed in order to fix the serial port device name but this gives also more flexibility as it is described here.

The following tools are necessary to create fixed device names:

  • For identification of the devices the lsusb package is required
  • For creating a symbolic link the udev package is needed

Both packages can be installed by:
sudo apt-get install usbutils
sudo apt-get install udev

The installed USB IO Modules can be identified by:
sudo lsusb -d16D0:0821 -v | grep iSerial
iSerial 3 1000120091010000
iSerial 3 000010018C010000

This command returns the serial numbers of all connected LucidControl USB IO Modules. In this example the output shows two devices. In order to identify a certain module it might be necessary to connect only this module to the computer during the identification.

After the device was identified a udev rule can be added.

sudo nano /etc/udev/rules.d/99-input.rules

Add the following line

SUBSYSTEM=="tty", ATTRS{idVendor}=="16d0", ATTRS{idProduct}=="0821", ATTRS{serial}=="000010018C010000", SYMLINK+="lucidDi0"

This udev rule creates a symbol link /dev/lucidDi0 for this device. The symbol link is a constant device name which is assigned to this device when the computer boots or the device is plugged in.

If the values ATTRS{idVendor} or ATTRS{idProduct} contain hexadecimal values they must be entered in lower case letters. This does not apply to ATTRS{serial} as you an see in the udev rule above.

In addition to Windows computers where a comport has always the pattern “COMn” where n is a number, a symbolic link can be more descriptive.

Click here to add your own text