I've written an app that communicates with some devices via RS-485 (MODBUS). I wrote it on macOS and it works great from my Mac via an FTDI USB-485 adapter. But when I run the code on Raspbian, using another of the same adapter, it's not able to communicate with any of the devices. Note that everything (Mac, RPi, devices) is on the same bus.

If I use screen on Raspbian and on macOS, the two appear able to talk to each other (just me typing in each window).

Note that the MODBUS speed is only 19200, so there shouldn't be any signal integrity issues.

Clearly something is wrong with the way Raspbian is handling my serial port, but it was working a few days ago. I'm not sure what has changed, although I did update a few packages.

I've tried setting serial port to raw, but that seemed to have no effect. I’m at a loss for what to try next, and I have to fly home tomorrow (I'm on-site trying to install this thing and this has just come up).

  • If the two are able to talk over screen through the RS485 and there's no sign of corruption that way then the problem most likely is nothing to do with Linux so much as the software you are running. Linux represents serial connections as a TTY so screen us showing you raw bytes in / out. Screen will be getting exactly what your software is getting. Aug 20, 2022 at 11:03
  • It’s the identical software on both platforms, and it worked before. After I enabled debug mode in libmodbus (it dumps the raw bytes in and out), it really seemed like there was local echo. I didn’t see that on macOS. I brought it back home and now it’s working fine, no local echo, so I’m thinking Linux got corrupted somehow, and a reboot fixed the port. I can’t think of anything else.
    – Rick
    Aug 21, 2022 at 15:11
  • Like I say it's unlikely to be a Linux issue the way you are describing it. Serial devices are common enough and tested enough. Echos on the line make it sound more like another device on the line talking when it shouldn't. We had one were one device was interpreting response messages as badly formatted requests addressed to itself. Really screwed up communication. Just changed the unit ID and it was fixed. Aug 21, 2022 at 15:41
  • I'm just describing what I saw. It seemed the serial port insisted on local echo and couldn't be persuaded not to (not in screen, not in the app that sets raw, not with stty). I can't think of a wiring issue that would cause it to appear to echo to the Pi but not the Mac connected to the same bus.
    – Rick
    Aug 22, 2022 at 8:11


You must log in to answer this question.

Browse other questions tagged .