Re: Make serial data available over TCP

From: Rob Mayoff (usenet_at_rob.dqd.com)
Date: 05/16/03


Date: 16 May 2003 12:41:19 -0700


"Robin Bowes" <robin-news@robinbowes.com> wrote in message news:<hz1xa.119$N02.30570@newsfep1-win.server.ntli.net>...
> One way to solve this would be to write a small process that creates a fifo,
> connects to the serial port, and writes all incoming data from the serial
> port to the fifo. Another process would run under tcpsever and, every time a
> connection is made would read from the fifo and write to the network
> connection.

Your approach won't work. Each byte written to a FIFO will be delivered
to at most a single reader.

I like tcpserver, but in this case, you're probably better off not using it.
Try this instead:

  Open a socket to listen for connections.
  Set stdin and the listening socket to non-blocking.
  Block SIGPIPE.
  Loop:
    Select/poll both stdin and listening socket for readability.
    If listening socket is readable, accept a new connection.
    If stdin is readable:
      Read from it
      Loop over each connection:
        Write data to connection.
        If write returns EPIPE, close the connection and forget it.
      End loop.
    End if.
  End loop.

Run this program with stdin redirected from the serial port. Or, if
necessary, write a separate program that reads from the serial port and
writes to stdout, and pipe the programs together.

You also need to decide what to do if a client is too slow to keep up.
There are two trivial choices. You could set each accepted connection to
non-blocking, and just let clients miss data when they're too slow. Or
you can use exactly the algorithm above, forcing all clients to receive
data as slowly as the slowest client. The non-trivial option is to put a
dynamically-growable buffer in front of each client.



Relevant Pages

  • Re: Make serial data available over TCP
    ... >> port to the fifo. ... >> connection is made would read from the fifo and write to the network ... > Run this program with stdin redirected from the serial port. ... and just let clients miss data when they're too slow. ...
    (comp.unix.programmer)
  • Re: Make serial data available over TCP
    ... >> port to the fifo. ... >> connection is made would read from the fifo and write to the network ... > Run this program with stdin redirected from the serial port. ... > You also need to decide what to do if a client is too slow to keep up. ...
    (comp.unix.programmer)
  • Re: activesync not connecting over serial
    ... I only saw the "CLIENT" signal when I attached to it via Hyperterminal without using the null cable. ... I've included the ActiveSync catalog item into the platform image, and when I run repllog.exe on the device via the "target->run programs" menu of PB, I see a "CLIENT" message sent out repeatedly via the COM1 serial port, but when I have my host computer connected to that serial port, and I run the "get connected" utility of ActiveSync, it doesn't make the connection. ...
    (microsoft.public.windowsce.platbuilder)
  • Re: Serial modem needs RI/CD lines?
    ... the CD signal from the UART is sampled by the PPP client and is ... required to be active before a connection can be made. ... it can be "faked out" inside the serial driver function: ... > And I can't find any logic for the RI signal in the serial port driver. ...
    (microsoft.public.windowsce.platbuilder)
  • Re: beginner Qs about COM/.NET (context = exposing a pre-existing app to scripting)
    ... You can even use a C++ singleton class. ... > objects into a script variable, and lets it sit on the shelf, my server ... it is the client that determines when to call Releaseon your object. ... > I think I have to use MTA; while program A is using the serial port, ...
    (microsoft.public.vc.atl)