How to realize a 'serial server' (with com port emulation on pc Windows) ?

The Raspberry4 board has 6 native uart I'm not talking about serial ports via usb but uart on the gpio connector of the Raspberry board Having to control devices via uart (for example gps receivers, electronic scales, etc.) it would be useful to create a device that, communicating with the control computer via ethernet, would allow the computer to 'see' the virtual com ports, corresponding to the uart of the card Raspberry So it will be necessary to program the Raspberry so that it has a tcp / ip server inside, which will pass the information to the uart ports On the computer side it will be necessary to install programs to 'virtualize' the com port and connect it to the tcp / ip server on the Raspberry How to proceed?

Reply to
RobertoA
Loading thread data ...

What you're trying to do would traditionally have been done by a "terminal server" e.g. from DEC or Moxa, but could be done by a Pi.

On a hardware level you'll need a level shifter to convert the PI's RX/TX pins from 3.3V TTL to +/- 12V e.g.

there are plenty of cheaper ones on ebay/amazon/aliexpress

Then you need to setup something listening on a known IP addr/TCP port, which invokes the "cu" utility to talk to the /dev/ttyXX port.

not Pi specific, and probably xinetd won't be running by default, but clues available here ...

Beware where it says there is zero security doing it this way, anyone who is allowed [by your firewall] to telnet to your Pi, will be directly connected to the serial port, you'd have to knock up any extra security yourself ...

Reply to
Andy Burns

Just re-read your message, are you saying you want something to create a virtual COMn: port on a windows PC, which when opened by a program running there automatically connects over TCP/IP to the PI, which in turn connects to the serial port as mentioned above?

The commercial drivers (e.g. Moxa) do come with such drivers, but are presumably licenced only for use with their hardware, implementing that from scratch would be "more involved" ...

Reply to
Andy Burns

Den 2020-12-30 kl. 16:19, skrev RobertoA:

with virtual ports you need commercial drivers. I once did a mapping tcp-port serail port in tcl ran in a _very_ busy warehouse translating stacker crane protcol (3964rk512) it ran 12 serial port on an XP at that time (now - new plcs with tcp/ip are installed)

it basically looked like

proc accept {sock addr port} { dbg "[gettime] -> start accept from $addr"

if { ! [string equal $addr $::client_ip]} { dbg "[gettime] -> wrong client, got '$addr' but accepts only from '$::client_ip'" catch {close $::ss} catch {close $sock} set ::done 1 ;# signal to main loop to let go return }

set ::my_sock $sock set ::my_com [open $::tty {RDWR}]

# Read channels w/o buffering and in binary mode fconfigure $::my_sock -buffering none -translation binary fconfigure $::my_com -mode $::mode -buffering none -translation binary

# Setup handler for communication on the channels fileevent $::my_sock readable [list pass_through $::my_sock $::my_com] fileevent $::my_com readable [list pass_through $::my_com $::my_sock]

# make sure noone else connects while a session in running catch {close $::ss} dbg "[gettime] -> stop accept" }

loop to reopen the listening socket when connection down while {1} { dbg "[gettime] -> Start listening" set ss [socket -server accept $port] vwait done ; # wait until the connection is closed # clean up after session dbg "[gettime] -> Close this session" catch {close $::my_com} catch {close $::my_sock} }

there where som config files and some whitelist involved as well, but above is the essence of it

its usefull, if you connect the pi with your serial device, and the conect the PC to the pi via a simple socket.

Reply to
Björn Lundin

I built one Rs323 to RS232 adapter during the first lock down this year. I had this project on my todo list since 3-4years already. I connect it to the GPIO pins and have a serial console, where I can see exactly everything. It works great. It helped me debug and setup the TFTP boot. But of course you can also buy a ready to use one. Pay attention on the chipset and manufacturer. There is tons of fake and buggy crap out there. There are also Serial to IPv4 converters, so that you can access your serial port via internet. AFAIR they are RS232 (12V) so perhaps a TTL level shifter (323-232) and a Serial to IPv4 is what you are looking for. I am not aware of any additional software (besides setting up the serial port on the RPI4)

Reply to
Deloptes

Ignore the gpio lines: Just get a standard a USB-serial adapter. Each supports a single serial line, so get one for each device with a serial port that you need to connect to the Pi and either plug them directly into the Pi or, if you run out of USB ports, via a USN connector block.

The ones I've used have all presented a common interface to Linux: plugging one in on a Pi automatically creates a new serial device, /dev/ ttyUSBnn IIRC, that behaves exactly like one of the predefined serial ports (/dev/ttynn) that are created at boot time on a PC with builot-in serial ports. This means that any program using the standard Linux serial port library routines can read and write to anything connected to your Pi via a USBserial adapter. It can also set the baud rate, character size, parity and stop bits.

The last Serial USB adapter I bought came from PicAxe, where they're used to upload PIC binaries to a PICAXE chip and/or to let the program you uploaded to the PICAXE chip talk to a program on your Linux box. They work just fine if that's a Pi too.

postage:

formatting link

I'm certain they're available elsewhere too, but that's where I bought the last one I needed.

--

-- Martin | martin at Gregorie | gregorie dot org

Reply to
Martin Gregorie

The best one is the prolific chip (pl2303) in the controller, but it is hard to have a genuine one. There are tons of Chinese fakes. I wounder how this sh*t is sold in the west, how it is possible to enter the markets and why?! I definitely was thinking of this when heard the news about Trump and the tarifs on Chinese imports. And it is not only the prolific chip of course.

Reply to
Deloptes

I didn't actually know that but so it is. One or two may be in use by default.

I can't help with the Windows part and it's really off topic here. On the RPi side you can use netcat to listen to a tcp port and forward data to serial and vice versa.

Reply to
Anssi Saari

Have a look at Conserver:

formatting link

Theo

Reply to
Theo

Serial to tcp servers for linux already exist. Try looking at the package ser2net - I'm sure there others.

Reply to
Jim Jackson

On Wed, 30 Dec 2020 18:31:07 -0000 (UTC), Martin Gregorie declaimed the following:

That doesn't answer the OP's actual request -- they want the ports physically on the R-Pi to be VISIBLE on the host (desktop/laptop) computer that is connecting to the R-Pi.

Unfortunately, that likely means a commercial $$$ ($260) package (which may not be available for ARM architecture).

formatting link
{STRIKE my parenthetical: "Linux version for ARM-based devices is available. Now you can share serial ports on ARM devices or connect to remote devices. Note: you need D-Bus to be installed on your device to use this version."} Hmmm...
formatting link

--
	Wulfraed                 Dennis Lee Bieber         AF6VN 
	wlfraed@ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/
Reply to
Dennis Lee Bieber

It answers the first part of his problem: getting signals to and from a user process to a D-9 or D-25 serial port without having to build something on a GPIO expansion card.

Once that's done the rest should be fairly simple programming. If the OP speaks C, then whipping up a program based round the poll() library function is pretty straight forward, not the least because it avoids having to write any multithreaded code.

Don't like C? Write it in Perl or, probably, Python instead.

Java isn't really a starter for this job since it can't handle serial ports without helper processes, which would have to be written in C, Perl or Python.

--
--   
Martin    | martin at 
 Click to see the full signature
Reply to
Martin Gregorie

On Thu, 31 Dec 2020 00:58:57 -0000 (UTC), Martin Gregorie declaimed the following:

A 5-pack of TTLRS232 level shifters is available for only $6 via Amazon (US).

SparkFun has one that includes the DB-9 connector for $16

formatting link
Other than running wires between the R-Pi and the unit there isn't much to "build" (and this one likely can be mounted in a suitable hole in a chassis).

--
	Wulfraed                 Dennis Lee Bieber         AF6VN 
	wlfraed@ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/
Reply to
Dennis Lee Bieber

No. He said uart, never mentioned rs232.

Reply to
A. Dumas

Why? His problem has nothing to do with the actual serial ports (whether uart or rs232) but with getting the data from them on the network.

Reply to
A. Dumas

Yeah, lots of caveats:

formatting link

That seems useful.

Reply to
A. Dumas

Wow, nice.

Reply to
A. Dumas

Nope. Look at replies by Theo and Jim.

Reply to
A. Dumas

He. Never. Mentioned. D9, D25 or RS232. Stop living in 1975.

Reply to
A. Dumas

As said there is tons of crap and who buys on Amazon?!

You can soldier your own RS323RS232 level shifter if skilled enough - it would guarantee quality compared to the 5pack for 6US$ Amazon sh*t.

The parts cost me about 3-4,- the plastic case however cost 6,- :/. I added some transistor, capacitor and diode for the feedback from the TTL signalling.

Reply to
Deloptes

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.