bashserial-portusbserial

How to read data from serial-to-usb device?


I have a sensor device connected to my Ubuntu 20 machine using a serial to usb cable. I understand that to stream data from it I need to run the following commands:

  1. Enter root with sudo -I.
  2. Setup a virtual COM port with stty -F /dev/ttyACM0 9600 cs8 -cstopb -parenb.
  3. Send a command to the device to initiate data streaming with echo -e "some_string" > /dev/ttyACM0.
  4. Stream data with cat < /dev/ttyACM0.

However, I cannot be sure that my device is connected as /dev/ttyACM0. How can I set this up? Currently it has the path /dev/bus/usb/001/005, although the last number changes every time the device is plugged in.

In response to the comment below, here is the output I get when I disconnect the device and run dmesg | tail (I've edited some real values):

[89092.291151] usb 1-1: USB disconnect, device number 11
[89100.310893] usb 1-1: new full-speed USB device number 12 using xhci_hcd
[89100.467562] usb 1-1: New USB device found, idVendor=SOME_ID, idProduct=SOME_PRODUCT, bcdDevice=SOME_BCD_DEVICE
[89100.467565] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[89100.467567] usb 1-1: Product: SOME_PRODUCT
[89100.467569] usb 1-1: Manufacturer: SOME_MANUFACTURER

EDIT: I have just found that I can use sudo modprobe usbserial vendor=SOME_ID product=SOME_PRODUCT to make ttyUSB0 available. However, plugging this into the above commands and running screen /dev/ttyUSB0 only returns lots of ``` characters. Note that this stops when the device is unplugged.


Solution

  • I managed to get this working. The commands were:

    sudo -i
    rmmod ftdi_sio
    rmmod usbserial
    modprobe ftdi-sio
    echo -n VENDOR_ID PRODUCT_ID | sudo tee /sys/bus/usb-serial/drivers/ftdi_sio/new_id
    stty -F /dev/ttyUSB0 9600 cs8 -cstopb -parenb
    echo -e "uud1\r" > /dev/ttyUSB0
    screen /dev/ttyUSB0 9600