Battont
Posts: 1
Joined: Mon Jan 20, 2020 6:22 pm

Multiple Serial ports on the RPi

Mon Jan 20, 2020 8:04 pm

I am new to the Raspberry Pi, and haven't written much code for any computer in a long time. I have, in the past, written programs for my employer for serial interfacing, but that was long ago, and written in QBasic. I currently need to create a replacement for an old system that has multiple serial ports (10 - 22 ports) and multiple digital and analog I/O inputs. I am planning to use a Raspberry Pi to do this, but need to find out what it will take to do multiple serial ports on the RPi. A multi-serial to USB converter would seem to be best, but I'm not sure which one(s) might work with the RPi and how to get an interface to it going (since, unlike windows/DOS, I don't imagine the RPi is going to just assign a sequential serial number to a new port) For the digital I/O I'm using the Opto-22 modules, which are the descendants of the ones in the current ancient system we're using. (That system runs DOS 3.3 on an ancient Prolog computer with the STD bus. The program it runs was created in Basic by one of our employees around 20-25 years ago. We have 100 or so of these systems in service.)

Can someone give me some insight into what it will take to implement 8 or more serial ports (via multi-serial to USB converter) on the RPi? I have Raspian on the RPi and plan on using Python but I'm open to suggestions. I'd use Basic just because of my familiarity with it, but that seems rather outdated and I don't imagine Tiny Basic on RPi would be up to the task anyway.
Thanks for any help here.

User avatar
topguy
Posts: 6183
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Multiple Serial ports on the RPi

Wed Jan 22, 2020 4:04 pm

How much is price an issue ? I would suggest maybe using some network2serial boxes from Moxa maybe to handle all the serialports in a good way.

Reasons:
- There was a limit on how many usb-tty endpoints that could be created on the Pi once. I dont know if that limit has been raised.
- Linux still enumerates USB devices (almost) totally random at boot. if you for example connected 5 identical FTDI devices you would probably have to program them with specific ID/labels and then write some udev rules to link them to fixed device names. And if you had to replace one you would have to make sure the correct ID/label was used on the replacement.

I didnt quite understand the role of the Opto-22, would you connect the Pis GPIO ports to it ? Or is it connected to the rest of the system and Pi would talk to it via serial ?

Replacing really old neglected sub-systems is no fun..

hippy
Posts: 6768
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Multiple Serial ports on the RPi

Wed Jan 22, 2020 6:27 pm

One option for multiple serial ports is to use some sort of ethernet terminal server. That should get around all the problems you can have with separate serial ports, identifying which is which, any 'maximum number' limitations there may be. They aren't necessarily cheap though.

I would think it should be possible to rebuild the kernel so it can have more USB endpoints and even alter the way USB and serial devices are enumerated so you can create serial devices which are numbered according to which hub and port is plugged into. I have no idea how or how much effort that would be.

Alternatively you might be able to find some way of determining which USB hub and port correlates with a particular /dev/ttyUSBn device.

dustnbone
Posts: 166
Joined: Tue Nov 05, 2019 2:49 am

Re: Multiple Serial ports on the RPi

Wed Jan 22, 2020 6:46 pm

A terminal server can be had fairly cheap used if you look around, there should be plenty of them in surplus,

We used them in the mid to late 90s when I worked at a dialup ISP to connect our many USR external modems to the network. Assuming they haven't all been "recycled" finding one under $10 a port shouldn't be hard.

Example:

https://www.ebay.ca/itm/Avocent-MergePo ... Swc9VcP387

hippy
Posts: 6768
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Multiple Serial ports on the RPi

Thu Jan 23, 2020 1:09 am

From a quick test it appears to be possible to programmatically create /dev serial devices which permanently reference fixed hub sockets regardless of whatever cables are plugged into those, no matter what /dev/ttyUSBn numbers they get allocated by Linux, regardless of make, type, serial numbers, lack of or duplicates, etc.

Not sure how that would work with multi-port on a single USB cable, but should work with cheap single port per cable adapters.

So that only leaves maximum number of USB devices, hubs and serial adapters supported. It seems Linux can support up to ~256 so a kernel compile should I guess get you what you want. But it might be worth having a read of the link below. That's old now, things may have changed. Unfortunately its discussing things I'm not familiar with so can't comment on it...

https://www.raspberrypi.org/forums/view ... hp?t=42586

Return to “Beginners”