Communicating with Compact-Line on Linux
Reading measurements in ASCII from the Compact-Line on Linux is really easy, as the sensor presents itself as a serial port. On Linux (and other UNIX-like operating system) ports are made available as pseudo files in the filesystem.
When the sensor is connected you can use the dmesg
command to show if the sensor is detected and under what port (file) name. Below we can see (on the last line), that our sensor is attached as ttyUSB0
.
[ 300.165606] usb 1-2: new full-speed USB device number 7 using xhci_hcd
[ 300.325200] usb 1-2: New USB device found, idVendor=0403, idProduct=6001, bcdDevice= 6.00
[ 300.325206] usb 1-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 300.325210] usb 1-2: Product: FT232R USB UART
[ 300.325213] usb 1-2: Manufacturer: FTDI
[ 300.325215] usb 1-2: SerialNumber: A105FZ62
[ 300.364138] usbcore: registered new interface driver usbserial_generic
[ 300.364148] usbserial: USB Serial support registered for generic
[ 300.367345] usbcore: registered new interface driver ftdi_sio
[ 300.367361] usbserial: USB Serial support registered for FTDI USB Serial Device
[ 300.367457] ftdi_sio 1-2:1.0: FTDI USB Serial Device converter detected
[ 300.367491] usb 1-2: Detected FT232RL
[ 300.367817] usb 1-2: FTDI USB Serial Device converter now attached to ttyUSB0
The sensor is now available as the pseudo file /dev/ttyUSB0
in my filesystem. It’s a good idea to check the permissions of this file if you intend to open the file as a non root user (which is recommended). On my Linux laptop, my user needs to be a member of the group dialout
to gain access.
$ ls -l /dev/ttyUSB0
crw-rw---- 1 root dialout 188, 0 Jun 4 20:41 /dev/ttyUSB0
Before you can read ASCII data from the sensor, it must be put into ASCII mode. This can be done by writing ASON to the sensor. For this I use the terminal program microcom , which is available from the standard repositories on Ubuntu Linux. Other Linux distributions might have other terminal applications available.
microcom -p /dev/ttyUSB0 -s 38400
From the Compact-Line datasheet it can be seen that the ASCII string “ASON” send to the sensor will enable ASCII mode, and then the measurements are shown in plain-text in the running terminal application.
In later posts we will demonstrate how to communicate with the Compact-Line sensor from scripting- and compiled languages.