Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.sys.raspberry-pi > #25325 > unrolled thread

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

Started byRobertoA <amorosik@tiscalinet.it>
First post2020-12-30 16:19 +0100
Last post2021-01-03 22:27 -0500
Articles 20 on this page of 53 — 12 participants

Back to article view | Back to comp.sys.raspberry-pi


Contents

  How to realize a 'serial server' (with com port emulation on pc Windows) ? RobertoA <amorosik@tiscalinet.it> - 2020-12-30 16:19 +0100
    Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? Andy Burns <usenet@andyburns.uk> - 2020-12-30 16:22 +0000
      Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? Andy Burns <usenet@andyburns.uk> - 2020-12-30 16:41 +0000
      Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? A. Dumas <alexandre@dumas.fr.invalid> - 2020-12-31 02:02 +0000
        Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? RobertoA <amorosik@tiscalinet.it> - 2020-12-31 21:36 +0100
          Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? Martin Gregorie <martin@mydomain.invalid> - 2020-12-31 21:03 +0000
          Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? Andy Burns <usenet@andyburns.uk> - 2020-12-31 21:22 +0000
            Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? RobertoA <amorosik@tiscalinet.it> - 2021-01-02 11:10 +0100
    Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? Björn Lundin <b.f.lundin@gmail.com> - 2020-12-30 18:55 +0100
      Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? RobertoA <amorosik@tiscalinet.it> - 2020-12-31 21:38 +0100
        Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? Björn Lundin <b.f.lundin@gmail.com> - 2021-01-01 15:30 +0100
          Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? RobertoA <amorosik@tiscalinet.it> - 2021-01-02 11:14 +0100
            Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? Björn Lundin <b.f.lundin@gmail.com> - 2021-01-02 13:24 +0100
    Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? Deloptes <deloptes@gmail.com> - 2020-12-30 19:02 +0100
      Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? RobertoA <amorosik@tiscalinet.it> - 2020-12-31 21:40 +0100
        Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? Deloptes <deloptes@gmail.com> - 2021-01-01 21:54 +0100
          Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? RobertoA <amorosik@tiscalinet.it> - 2021-01-02 11:01 +0100
    Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? Martin Gregorie <martin@mydomain.invalid> - 2020-12-30 18:31 +0000
      Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? Deloptes <deloptes@gmail.com> - 2020-12-30 22:21 +0100
      Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2020-12-30 18:52 -0500
        Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? Martin Gregorie <martin@mydomain.invalid> - 2020-12-31 00:58 +0000
          Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2020-12-30 20:33 -0500
            Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? Deloptes <deloptes@gmail.com> - 2020-12-31 09:37 +0100
          Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? A. Dumas <alexandre@dumas.fr.invalid> - 2020-12-31 02:14 +0000
            Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2020-12-31 17:37 -0500
        Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? A. Dumas <alexandre@dumas.fr.invalid> - 2020-12-31 02:14 +0000
          Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? Andy Burns <usenet@andyburns.uk> - 2020-12-31 10:29 +0000
            Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? RobertoA <amorosik@tiscalinet.it> - 2020-12-31 21:44 +0100
              Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? Andy Burns <usenet@andyburns.uk> - 2020-12-31 21:18 +0000
            Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2020-12-31 17:50 -0500
        Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? RobertoA <amorosik@tiscalinet.it> - 2020-12-31 21:44 +0100
      Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? A. Dumas <alexandre@dumas.fr.invalid> - 2020-12-31 02:04 +0000
      Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? RobertoA <amorosik@tiscalinet.it> - 2020-12-31 21:41 +0100
        Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? Martin Gregorie <martin@mydomain.invalid> - 2020-12-31 21:31 +0000
          Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? RobertoA <amorosik@tiscalinet.it> - 2021-01-02 11:20 +0100
    Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? Anssi Saari <as@sci.fi> - 2020-12-31 00:15 +0200
      Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? Jim Jackson <jj@franjam.org.uk> - 2020-12-30 22:19 +0000
        Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? RobertoA <amorosik@tiscalinet.it> - 2020-12-31 21:46 +0100
          Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? Jim Jackson <jj@franjam.org.uk> - 2021-01-01 20:29 +0000
            Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? Andy Burns <usenet@andyburns.uk> - 2021-01-01 21:28 +0000
              Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? RobertoA <amorosik@tiscalinet.it> - 2021-01-02 11:23 +0100
                Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? Ahem A Rivet's Shot <steveo@eircom.net> - 2021-01-02 10:41 +0000
      Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? A. Dumas <alexandre@dumas.fr.invalid> - 2020-12-31 02:09 +0000
    Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? Theo <theom+news@chiark.greenend.org.uk> - 2020-12-30 22:17 +0000
      Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? A. Dumas <alexandre@dumas.fr.invalid> - 2020-12-31 02:14 +0000
    Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? Grant Taylor <gtaylor@tnetconsulting.net> - 2020-12-31 17:39 -0700
      Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? RobertoA <amorosik@tiscalinet.it> - 2021-01-02 11:08 +0100
        Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? Grant Taylor <gtaylor@tnetconsulting.net> - 2021-01-02 12:29 -0700
        Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2021-01-02 14:48 -0500
          Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? Grant Taylor <gtaylor@tnetconsulting.net> - 2021-01-02 13:31 -0700
            Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2021-01-03 12:27 -0500
              Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? Grant Taylor <gtaylor@tnetconsulting.net> - 2021-01-03 14:22 -0700
              Re: How to realize a 'serial server' (with com port emulation on pc Windows) ? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2021-01-03 22:27 -0500

Page 1 of 3  [1] 2 3  Next page →


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

FromRobertoA <amorosik@tiscalinet.it>
Date2020-12-30 16:19 +0100
SubjectHow to realize a 'serial server' (with com port emulation on pc Windows) ?
Message-ID<rsi5qr$1ele$1@gioia.aioe.org>
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?

[toc] | [next] | [standalone]


#25329

FromAndy Burns <usenet@andyburns.uk>
Date2020-12-30 16:22 +0000
Message-ID<i53nqfFkc2aU1@mid.individual.net>
In reply to#25325
RobertoA wrote:

> How to proceed?

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

[toc] | [prev] | [next] | [standalone]


#25330

FromAndy Burns <usenet@andyburns.uk>
Date2020-12-30 16:41 +0000
Message-ID<i53otfFkilrU1@mid.individual.net>
In reply to#25329
Andy Burns wrote:

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

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

[toc] | [prev] | [next] | [standalone]


#25344

FromA. Dumas <alexandre@dumas.fr.invalid>
Date2020-12-31 02:02 +0000
Message-ID<5fed3122$0$288$e4fe514c@news.xs4all.nl>
In reply to#25329
Andy Burns <usenet@andyburns.uk> wrote:
> 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.

No. He said uart, never mentioned rs232.

[toc] | [prev] | [next] | [standalone]


#25356

FromRobertoA <amorosik@tiscalinet.it>
Date2020-12-31 21:36 +0100
Message-ID<rslcog$cqt$1@gioia.aioe.org>
In reply to#25344
Il 31/12/2020 03:02, A. Dumas ha scritto:
> Andy Burns <usenet@andyburns.uk> wrote:
>> 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.
> 
> No. He said uart, never mentioned rs232.
> 

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/

[toc] | [prev] | [next] | [standalone]


#25363

FromMartin Gregorie <martin@mydomain.invalid>
Date2020-12-31 21:03 +0000
Message-ID<rslebj$ehn$1@dont-email.me>
In reply to#25356
On Thu, 31 Dec 2020 21:36:34 +0100, RobertoA wrote:

> Il 31/12/2020 03:02, A. Dumas ha scritto:
>> Andy Burns <usenet@andyburns.uk> wrote:
>>> 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.
>> 
>> No. He said uart, never mentioned rs232.
>> 
>> 
> 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/

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
Gregorie  | gregorie dot org

[toc] | [prev] | [next] | [standalone]


#25365

FromAndy Burns <usenet@andyburns.uk>
Date2020-12-31 21:22 +0000
Message-ID<i56tohF8vr1U1@mid.individual.net>
In reply to#25356
RobertoA wrote:

> Rs232 electric level in not necessary
> Conversion ttl-rs232 is not necessary
> Gpio port of Rasperry is connected directly with other 3v3 electronic 
> boards

ok

> The part for me obscure, is how to use Raspberry uart port for 
> communication via tcp ethernet line

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

> The second big question is how to use for a 'virtual com port' on 
> Windows side

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>

[toc] | [prev] | [next] | [standalone]


#25382

FromRobertoA <amorosik@tiscalinet.it>
Date2021-01-02 11:10 +0100
Message-ID<rspgrh$1dbq$2@gioia.aioe.org>
In reply to#25365
Il 31/12/2020 22:22, Andy Burns ha scritto:
> RobertoA wrote:
> 
>> Rs232 electric level in not necessary
>> Conversion ttl-rs232 is not necessary
>> Gpio port of Rasperry is connected directly with other 3v3 electronic 
>> boards
> 
> ok
> 
>> The part for me obscure, is how to use Raspberry uart port for 
>> communication via tcp ethernet line
> 
> That's the fairly easy part, as several people have linked different ways
> 
>> The second big question is how to use for a 'virtual com port' on 
>> Windows side
> 
> 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>


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?

[toc] | [prev] | [next] | [standalone]


#25331

FromBjörn Lundin <b.f.lundin@gmail.com>
Date2020-12-30 18:55 +0100
Message-ID<rsiev2$rdq$1@dont-email.me>
In reply to#25325
Den 2020-12-30 kl. 16:19, skrev RobertoA:
> The Raspberry4 board has 6 native uart
> How to proceed?

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.

-- 
Björn

[toc] | [prev] | [next] | [standalone]


#25357

FromRobertoA <amorosik@tiscalinet.it>
Date2020-12-31 21:38 +0100
Message-ID<rslct0$cqt$2@gioia.aioe.org>
In reply to#25331
Il 30/12/2020 18:55, Björn Lundin ha scritto:
> Den 2020-12-30 kl. 16:19, skrev RobertoA:
>> The Raspberry4 board has 6 native uart
>> How to proceed?
> 
> 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.
> 

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?

[toc] | [prev] | [next] | [standalone]


#25370

FromBjörn Lundin <b.f.lundin@gmail.com>
Date2021-01-01 15:30 +0100
Message-ID<rsnbla$af8$1@dont-email.me>
In reply to#25357
Den 2020-12-31 kl. 21:38, skrev RobertoA:
> 
> 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?


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

-- 
Björn

[toc] | [prev] | [next] | [standalone]


#25383

FromRobertoA <amorosik@tiscalinet.it>
Date2021-01-02 11:14 +0100
Message-ID<rsph1t$1i6r$1@gioia.aioe.org>
In reply to#25370
Il 01/01/2021 15:30, Björn Lundin ha scritto:
> Den 2020-12-31 kl. 21:38, skrev RobertoA:
>>
>> 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?
> 
> 
> 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
> 

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?

[toc] | [prev] | [next] | [standalone]


#25387

FromBjörn Lundin <b.f.lundin@gmail.com>
Date2021-01-02 13:24 +0100
Message-ID<rspolj$858$1@dont-email.me>
In reply to#25383
Den 2021-01-02 kl. 11:14, skrev RobertoA:
> Il 01/01/2021 15:30, Björn Lundin ha scritto:
>> Den 2020-12-31 kl. 21:38, skrev RobertoA:
> 
> I understand the substance of the written code, what I can't do at the 
> moment is how to use it on Raspberry

save it to a file and run it with
tclsh filename


> What documents / tutorials to follow to understand how to use the sent 
> code?

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 {what} {
   if {$::debug} {
      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 {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}
}





-- 
Björn

[toc] | [prev] | [next] | [standalone]


#25332

FromDeloptes <deloptes@gmail.com>
Date2020-12-30 19:02 +0100
Message-ID<rsifbl$v71$1@dont-email.me>
In reply to#25325
RobertoA wrote:

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

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)

[toc] | [prev] | [next] | [standalone]


#25358

FromRobertoA <amorosik@tiscalinet.it>
Date2020-12-31 21:40 +0100
Message-ID<rsld0p$cqt$3@gioia.aioe.org>
In reply to#25332
Il 30/12/2020 19:02, Deloptes ha scritto:
> RobertoA wrote:
> 
>> 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?
> 
> 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)
> 

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

[toc] | [prev] | [next] | [standalone]


#25373

FromDeloptes <deloptes@gmail.com>
Date2021-01-01 21:54 +0100
Message-ID<rso267$frh$1@dont-email.me>
In reply to#25358
RobertoA wrote:

> The description seems to be what I need
> How do you get 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/



[toc] | [prev] | [next] | [standalone]


#25380

FromRobertoA <amorosik@tiscalinet.it>
Date2021-01-02 11:01 +0100
Message-ID<rspgab$17v7$1@gioia.aioe.org>
In reply to#25373
Il 01/01/2021 21:54, Deloptes ha scritto:
> RobertoA wrote:
> 
>> The description seems to be what I need
>> How do you get 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/
> 
> 
> 
> 
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

[toc] | [prev] | [next] | [standalone]


#25334

FromMartin Gregorie <martin@mydomain.invalid>
Date2020-12-30 18:31 +0000
Message-ID<rsih1b$reu$1@dont-email.me>
In reply to#25325
On Wed, 30 Dec 2020 16:19:56 +0100, RobertoA wrote:

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

PICAXE http://www.picaxe.com/ sell adaptors for £12.49 (VAT incl) + 
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

[toc] | [prev] | [next] | [standalone]


#25336

FromDeloptes <deloptes@gmail.com>
Date2020-12-30 22:21 +0100
Message-ID<rsir09$otf$1@dont-email.me>
In reply to#25334
Martin Gregorie wrote:

> 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.
> 
> PICAXE http://www.picaxe.com/ sell adaptors for £12.49 (VAT incl) +
> 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.

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.

[toc] | [prev] | [next] | [standalone]


#25341

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2020-12-30 18:52 -0500
Message-ID<634quf9elcios21c6ce7tnl5bigmp2orfh@4ax.com>
In reply to#25334
On Wed, 30 Dec 2020 18:31:07 -0000 (UTC), Martin Gregorie
<martin@mydomain.invalid> declaimed the following:

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

	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
	wlfraed@ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/

[toc] | [prev] | [next] | [standalone]


Page 1 of 3  [1] 2 3  Next page →

Back to top | Article view | comp.sys.raspberry-pi


csiph-web