Lomax
Posts: 217
Joined: Wed May 20, 2015 9:43 pm

Mysterious issue with serial adapter on /dev/ttyUSB2

Sun May 16, 2021 1:03 pm

Hello,

I've got a device which I talk to over RS232 from Node-RED, using an FTDI USB <> serial adapter. When connected to my laptop (running Devuan Beowulf) I can talk to the device without issues, and I have developed a bunch of Node-RED flows making use of this data. Once I deploy these flows to the Raspberry Pi, and move the FTDI adapter over, the communication stops working and every transmission times out. I have checked that the device is recognised in DMESG:

Code: Select all

[943377.016356] usb 1-1.2: new full-speed USB device number 6 using dwc_otg
[943377.173957] usb 1-1.2: New USB device found, idVendor=0403, idProduct=6001, bcdDevice= 6.00
[943377.173979] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[943377.173991] usb 1-1.2: Product: FT232R USB UART
[943377.174003] usb 1-1.2: Manufacturer: FTDI
[943377.174014] usb 1-1.2: SerialNumber: A50285BI
[943377.183392] ftdi_sio 1-1.2:1.0: FTDI USB Serial Device converter detected
[943377.183593] usb 1-1.2: Detected FT232RL
[943377.186257] usb 1-1.2: FTDI USB Serial Device converter now attached to ttyUSB2
And I have verified that the port configuration is identical in Node-RED to how I have it set on my laptop (19200-8N1), with the only difference being the device name which changes from /dev/ttyUSB0 to /dev/ttyUSB2 (the Raspberry has another FTDI USB <> serial adapter connected which provides two independent ports on /dev/ttyUSB0 and /dev/ttyUSB1, one of which I use for RS485 comms). I can see Node-RED opening the port at start-up:

Code: Select all

16 May 14:06:02 - [info] serial port /dev/ttyUSB2 opened at 19200 baud 8N1
Permissions look identical for all /dev/ttyUSB* devices:

Code: Select all

crw-rw---- 1 root dialout 188,  0 May 16 13:46 /dev/ttyUSB0
crw-rw---- 1 root dialout 188,  1 May 16 13:57 /dev/ttyUSB1
crw-rw---- 1 root dialout 188,  2 May 16 13:57 /dev/ttyUSB2
I am at a loss to explain this. What could be causing this issue?

Lomax
Posts: 217
Joined: Wed May 20, 2015 9:43 pm

Re: Mysterious issue with serial adapter on /dev/ttyUSB2

Sun May 16, 2021 2:43 pm

A reboot did not help, though it did change the naming order of the ports, with the new adapter now showing up as /dev/ttyUSB0. After updating Node-RED accordingly the requests still time out as before. Modbus communication on /dev/ttyUSB2 continues to function.

Code: Select all

$ dmesg | grep usb
[    3.824409] usb 1-1.2: new full-speed USB device number 4 using dwc_otg
[    3.981949] usb 1-1.2: New USB device found, idVendor=0403, idProduct=6001, bcdDevice= 6.00
[    3.989044] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[    3.989063] usb 1-1.2: Product: FT232R USB UART
[    3.989080] usb 1-1.2: Manufacturer: FTDI
[    3.989095] usb 1-1.2: SerialNumber: A50285BI
[    4.104490] usb 1-1.3: new high-speed USB device number 5 using dwc_otg
[    4.239532] usb 1-1.3: New USB device found, idVendor=0403, idProduct=6010, bcdDevice= 7.00
[    4.246183] usb 1-1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[    4.249490] usb 1-1.3: Product: USB <-> Serial Cable
[    4.252764] usb 1-1.3: Manufacturer: FTDI
[    4.256086] usb 1-1.3: SerialNumber: FT1DQDHU
[    4.364467] usb 1-1.5: new full-speed USB device number 6 using dwc_otg
[    4.504896] usb 1-1.5: New USB device found, idVendor=04d8, idProduct=d004, bcdDevice= 0.03
[    4.510949] usb 1-1.5: New USB device strings: Mfr=1, Product=2, SerialNumber=4
[    4.514000] usb 1-1.5: Product: OPEN-UPS
[    4.516960] usb 1-1.5: Manufacturer: Mini-Box.Com
[    4.519771] usb 1-1.5: SerialNumber: PBSO4-LiFePO
[    4.574735] hid-generic 0003:04D8:D004.0001: hiddev96,hidraw0: USB HID v1.11 Device [Mini-Box.Com OPEN-UPS] on usb-3f980000.usb-1.5/input0
[    7.718555] usbcore: registered new interface driver usbserial_generic
[    7.718719] usbserial: USB Serial support registered for generic
[    7.753861] usbcore: registered new interface driver ftdi_sio
[    7.754412] usbserial: USB Serial support registered for FTDI USB Serial Device
[    7.755147] usb 1-1.2: Detected FT232RL
[    7.764839] usb 1-1.2: FTDI USB Serial Device converter now attached to ttyUSB0
[    7.766729] usb 1-1.3: Detected FT2232H
[    7.771151] usb 1-1.3: FTDI USB Serial Device converter now attached to ttyUSB1
[    7.771933] usb 1-1.3: Detected FT2232H
[    7.772872] usb 1-1.3: FTDI USB Serial Device converter now attached to ttyUSB2


Lomax
Posts: 217
Joined: Wed May 20, 2015 9:43 pm

Re: Mysterious issue with serial adapter on /dev/ttyUSB2

Sun May 16, 2021 3:02 pm

Interestingly, when I connect the FTDI adapter to my laptop, dmesg shows this:

Code: Select all

[451538.930020] usb 1-1.2: new full-speed USB device number 16 using ehci-pci
[451539.046027] usb 1-1.2: New USB device found, idVendor=0403, idProduct=6001, bcdDevice= 6.00
[451539.046033] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[451539.046036] usb 1-1.2: Product: FT232R USB UART
[451539.046038] usb 1-1.2: Manufacturer: FTDI
[451539.046040] usb 1-1.2: SerialNumber: A50285BI
[451539.048742] ftdi_sio 1-1.2:1.0: FTDI USB Serial Device converter detected
[451539.048763] usb 1-1.2: Detected FT232RL
[451539.049290] usb 1-1.2: FTDI USB Serial Device converter now attached to ttyUSB0
So on my laptop the adapter uses the `ehci-pci driver`, while on the Pi it uses `usbserial_generic`. I've got a feeling this is where the issue lies.

User avatar
scruss
Posts: 4097
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Mysterious issue with serial adapter on /dev/ttyUSB2

Sun May 16, 2021 5:28 pm

The Raspberry Pi doesn't have a PCI bus, which your laptop does. On my Raspberry Pi 4B, the USB controller appears as "usb 1-1: new high-speed USB device number 2 using xhci_hcd".

Rather than accessing the serial device via /dev/ttyUSB2, maybe try using one of the aliases in /dev/serial/by-id. I suspect you likely have a device called dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A50285BI-if00-port0 which points to your (non-RS485) serial port. If NodeRed allows access to the longer devices names, that alias will always point to your FT232R, even if it enumerates to ttyUSB0, ttyUSB1 or ttyUSB2.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

Lomax
Posts: 217
Joined: Wed May 20, 2015 9:43 pm

Re: Mysterious issue with serial adapter on /dev/ttyUSB2

Sun May 16, 2021 9:23 pm

Thanks, that makes sense. But now I'm back to square one, with no idea what causes this communication problem.

User avatar
FTrevorGowen
Forum Moderator
Forum Moderator
Posts: 6276
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: Mysterious issue with serial adapter on /dev/ttyUSB2

Sun May 16, 2021 9:43 pm

Lomax wrote:
Sun May 16, 2021 9:23 pm
Thanks, that makes sense. But now I'm back to square one, with no idea what causes this communication problem.
FWIW, and depending upon how your external device works, it may be useful for you to install (if you haven't done that already) GtkTerm (or similar) to capture raw data from said device. I had to do that (and write a post-processor for the captured data) to handle an unusual data stream from a DMM which had a free-running (one way) serial interface: http://www.cpmspectrepi.uk/raspberry_pi ... 000zc.html
Trev.
Still running Raspbian Jessie or Stretch on some older Pi's (an A, B1, 2xB2, B+, P2B, 3xP0, P0W, 2xP3A+, P3B+, P3B, B+, and a A+) but Buster on the P4B's & P400. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

User avatar
scruss
Posts: 4097
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Mysterious issue with serial adapter on /dev/ttyUSB2

Sun May 16, 2021 9:47 pm

Can you make the serial device do expected things outside NodeRed on the Raspberry Pi? Maybe it's an initialization/power problem?

Are your tasks timing out on the Raspberry Pi because the laptop you developed them on was much faster?

Kinda clutching at straws here: don't know what your device is, don't know what error messages you're seeing, …
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

Lomax
Posts: 217
Joined: Wed May 20, 2015 9:43 pm

Re: Mysterious issue with serial adapter on /dev/ttyUSB2

Sun May 16, 2021 11:07 pm

Thanks guys. Without hooking up a scope it seems hard to diagnose this further; when I send known valid requests to the device the response just times out. The exact same code works fine when I move the USB cable to my laptop, without changing anything. I know I have the right device name, but nevertheless tried switching between all three USB<>serial ports available on the Pi, with the same result. Unfortunately the time out only means the device didn't respond, which of course can have a multitude of reasons. But I'm not a complete novice wrt serial interfacing, and have tried all the basic troubleshooting steps I can think of. Really quite odd.

Edit: I should add that this is a 5V TTL serial connection, not standard RS232. Power usage should be negligible.

Return to “Interfacing (DSI, CSI, I2C, etc.)”