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


Groups > comp.sys.raspberry-pi > #25387

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

From Björn Lundin <b.f.lundin@gmail.com>
Newsgroups comp.sys.raspberry-pi
Subject Re: How to realize a 'serial server' (with com port emulation on pc Windows) ?
Date 2021-01-02 13:24 +0100
Organization A noiseless patient Spider
Message-ID <rspolj$858$1@dont-email.me> (permalink)
References <rsi5qr$1ele$1@gioia.aioe.org> <rsiev2$rdq$1@dont-email.me> <rslct0$cqt$2@gioia.aioe.org> <rsnbla$af8$1@dont-email.me> <rsph1t$1i6r$1@gioia.aioe.org>

Show all headers | View raw


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

Back to comp.sys.raspberry-pi | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web