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

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
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?

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

Quoted text here. Click to load it

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.

<https://uk.farnell.com/ftdi/ttl-232r-3v3/cable-usb-to-ttl-level-serial/dp/1329311

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 ...

<http://www.trinityos.com/LINUX/TrinityOS/cHTML/TrinityOS-c-55.html

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 ...


Re: How to realize a 'serial server' (with com port emulation on pc Windows) ?
Andy Burns wrote:

Quoted text here. Click to load it

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" ...


Re: How to realize a 'serial server' (with com port emulation on pc Windows) ?
Quoted text here. Click to load it

No. He said uart, never mentioned rs232.


Re: How to realize a 'serial server' (with com port emulation on pc Windows) ?
Il 31/12/2020 03:02, A. Dumas ha scritto:
Quoted text here. Click to load it

Rs232 electric level in not necessary
Conversion ttl-rs232 is not necessary
Gpio port of Rasperry is connected directly with other 3v3 electronic boards
The part for me obscure, is how to use Raspberry uart port for  
communication via tcp ethernet line
The second big question is how to use for a 'virtual com port' on  
Windows side, that mus communicate with Raspberry board
Please see the following link

https://www.b4x.com/android/forum/threads/raspberry-how-to-realize-a-serial-server-uart-ethernet.125040/



Re: How to realize a 'serial server' (with com port emulation on pc Windows) ?
On Thu, 31 Dec 2020 21:36:34 +0100, RobertoA wrote:

Quoted text here. Click to load it
serial-server-uart-ethernet.125040/

netcat - aka. nc is one answer.  

Its a standard Linux utility program. Its usable in shell scripts which  
in turn can be run a cron jobs. See its manpage for details. Among other  
things it can copy a data stream from a serial port to a network socket  
or vice versa.  


--  
--  
Martin    | martin at
We've slightly trimmed the long signature. Click to see the full one.
Re: How to realize a 'serial server' (with com port emulation on pc Windows) ?
RobertoA wrote:

Quoted text here. Click to load it

ok


That's the fairly easy part, as several people have linked different ways

Quoted text here. Click to load it

There are several bit of software that do half of what you want, but not  
all of it e.g. look at com0com,  maybe com2tcp does actually do what you  
need?

<http://com0com.sourceforge.net/com2tcp/ReadMe.txt>

Re: How to realize a 'serial server' (with com port emulation on pc Windows) ?
Il 31/12/2020 22:22, Andy Burns ha scritto:
Quoted text here. Click to load it

Quoted text here. Click to load it


I know com0com but I thought it used its own protocol to communicate  
between the various components of the project
Do you think you can also use it to communicate with netcat or other  
program that will be installed on the Raspberry?

Re: How to realize a 'serial server' (with com port emulation on pc Windows) ?
Den 2020-12-30 kl. 16:19, skrev RobertoA:
Quoted text here. Click to load it

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 ]

   # 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 {
   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.

--  


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

Quoted text here. Click to load it

Quoted text here. Click to load it


Quoted text here. Click to load it





Quoted text here. Click to load it


Quoted text here. Click to load it



Quoted text here. Click to load it



Quoted text here. Click to load it



Quoted text here. Click to load it

Quoted text here. Click to load it







Quoted text here. Click to load it

I cannot fully understand how to use the example code described, but it  
seems to me very useful to realize what I would like to achieve
How to use this code on Raspberry board?

Re: How to realize a 'serial server' (with com port emulation on pc Windows) ?
Den 2020-12-31 kl. 21:38, skrev RobertoA:
Quoted text here. Click to load it


Hmm, if you don't see that, then it is not for you.
Basically you adapt the code for your purposes.
You assign values to variables
port
client_ip if you want a white list - otherwise remove that if-section
tty

then add a dbg proc like (or remove calls to dbg)
proc dbg {what } {
   puts $what
}

then you run it via tclsh (I think it is installed in raspbian else
sudo apt install tcl)

The filevent does the rest

But as others have pointed out - nc/netcat does the job as well
If you are not a programmer - then that is a better route.
If you needs are more special - then use something you can adapt  
yourself - like above

--  


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

Quoted text here. Click to load it

Quoted text here. Click to load it

I understand the substance of the written code, what I can't do at the  
moment is how to use it on Raspberry
What documents / tutorials to follow to understand how to use the sent code?

Re: How to realize a 'serial server' (with com port emulation on pc Windows) ?
Den 2021-01-02 kl. 11:14, skrev RobertoA:

Quoted text here. Click to load it

save it to a file and run it with
tclsh filename


Quoted text here. Click to load it

There is none - since I wrote it for me - unless you mean tcl as a  
language and in particular file events
<https://www.tcl.tk/man/tcl8.6/TclCmd/fileevent.htm
<https://www.tcl.tk/man/tcl8.6/TclCmd/fconfigure.htm



I just saw it wasn't complete - this should work (though not tested  
since I got no serial device)

save it to a file, install tcl if not alredy there
(sudo apt install tcl)

and set - below
set my_com "/dev/ttyWhatever"
set port 6789
to whatever values you need.

Then - when something connects to the tcp/ip port of your choise
it is forwared byte by byte to the serial device.
and vice versa. whenever the soceket ot serail port becomes readable, it  
invokes proc pass_through that reads a byte and forwards it unless its a  
carriage return. those are swallowed - change the if-statement 'if  
{[string equal "\r" $tmp]}' - in pass_through if it does not apply to you.


run it with tclsh whatever/name/you/gave/it

#####
#Associate a tcp/ip port 'port' with a tty 'my_com'
# run with tclsh scriptname
#####
set done 0
set my_sock 0
set my_com "/dev/ttyWhatever"
set port 6789
set ss 0
set debug 1
set config_line {}
###########################

proc gettime {} {
   return [clock format [clock seconds] -format "%Y-%b-%d %H:%M:%S"]
}

###########################

proc dbg {
   if {
      puts  $what
      # puts $::error_file_pointer $what
      # catch {flush $::error_file_pointer}
   }
}

###########################

proc pass_through {from to} {
   set tmp [read $from 1] ;# read 1 byte at a time
   if {[eof $from]} {     ;# client gone or finished
      set ::done 1        ;# signal to main loop to let go
   } else {
   #do things
     if {[string equal "\r" $tmp]} {
       catch {puts "\n[gettime] -> CR received, terminating chars above" 1}
     } else {
       catch {puts -nonewline $tmp}
       catch {puts -nonewline $to $tmp} ;# put it out
     }
   }
}
###########################

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

   set ::my_sock $sock
   set ::my_com [open $::tty ]

   # 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 {
   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}
}





--  


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

Quoted text here. Click to load it

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)

Re: How to realize a 'serial server' (with com port emulation on pc Windows) ?
Il 30/12/2020 19:02, Deloptes ha scritto:
Quoted text here. Click to load it

The description seems to be what I need
How do you get it?


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

Quoted text here. Click to load it

For example this here (UART TTL to Ethernet)
https://eckstein-shop.de/Waveshare-UART-TTL-to-Ethernet-Converter-ETH-RJ45-Module-USR-TCP232-T2?curr=EUR&gclid=CjwKCAiArbv_BRA8EiwAYGs23AXvVipkyFagOGWo7bhPhl32DwV9YYJKJ14TADzevjAnaJjX3jA3_RoCxmcQAvD_BwE

or read here
https://www.virtual-serial-port.org/article/best-serial-over-ethernet-tools/





Re: How to realize a 'serial server' (with com port emulation on pc Windows) ?
Il 01/01/2021 21:54, Deloptes ha scritto:
Quoted text here. Click to load it
I already use the module with two uart
https://www.pusr.com/products/dual-ttl-to-ethernet-modules-usr-tcp232-e2.html
But there is no equivalent module for 6 uart

Re: How to realize a 'serial server' (with com port emulation on pc Windows) ?
On Wed, 30 Dec 2020 16:19:56 +0100, RobertoA wrote:

Quoted text here. Click to load it
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:  

https://picaxe.com/hardware/cables/picaxe-usb-download-cable/


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


Re: How to realize a 'serial server' (with com port emulation on pc Windows) ?
Martin Gregorie wrote:

Quoted text here. Click to load it

Quoted text here. Click to load it

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.

Re: How to realize a 'serial server' (with com port emulation on pc Windows) ?
On Wed, 30 Dec 2020 18:31:07 -0000 (UTC), Martin Gregorie

Quoted text here. Click to load it

    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).
https://www.eltima.com/products/com-port-redirector/ {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... https://wiki.eltima.com/software-licenses/trial-version-eula.html



--  
    Wulfraed                 Dennis Lee Bieber         AF6VN
     snipped-for-privacy@ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/

Site Timeline