hunterli / remserial Goto Github PK
View Code? Open in Web Editor NEWbridge between socket and serial port
bridge between socket and serial port
Remserial --------- The remserial program acts as a communications bridge between a TCP/IP network port and a Linux device such as a serial port. Any character-oriented Linux /dev device will work. The program can also use pseudo-ttys as the device. A pseudo-tty is like a serial port in that it has a /dev entry that can be opened by a program that expects a serial port device, except that instead of belonging to a physical serial device, the data can be intercepted by another program. The remserial program uses this to connect a network port to the "master" (programming) side of the pseudo-tty allowing the device driver (slave) side to be used by some program expecting a serial port. See example 3 below for details. The program can operate as a server accepting network connections from other machines, or as a client, connecting to remote machine that is running the remserial program or some other program that accepts a raw network connection. The network connection passes data as-is, there is no control protocol over the network socket. Multiple copies of the program can run on the same computer at the same time assuming each is using a different network port and device. Some examples: 1) Give access to a RS232 device over a network. The computer with the serial port connected to the device (such as a data aquisition device) runs the remserial program: remserial -d -p 23000 -s "9600 raw" /dev/ttyS0 & This starts the program in daemon mode so that it runs in the background, it waits for connections on port 23000 and sets up the serial port /dev/ttyS0 at 9600 baud. Network connections to port 23000 from any machine can then read and write to the device attached to the serial port. This can be started from /etc/rc.local or as an entry in /etc/inittab or set up as a system service with a file in /etc/rc.init/. 2) Connect an RS232 device to a specified server. The computer with the serial port connected to the device (such as a data aquisition device) runs the remserial program: remserial -d -r server-name -p 23000 -s "9600 raw" /dev/ttyS0 & This would be used with case number 1 above creating an end-to-end serial port connection. What goes in the serial port on one machine would come out the serial port of the other machine. The ports could be running at different baud rates or other serial port settings. 3) Connect a Linux program that needs a serial port to a remote serial port. Some programs are written to communicate directly with a serial port such as some data aquisition programs. The remserial program can use pseudo-ttys to fool the program into thinking that it is talking to a real serial port on the local machine: remserial -d -r server-name -p 23000 -l /dev/remserial1 /dev/ptmx & This creates a file called /dev/remserial1 which can be used by the data aquisition application as its serial port. Any data sent or received is passed to the remote server-name on port 23000 where a computer configured in case number 1 above passes it to a real serial port. The remserial program uses the special pseudo-tty master device /dev/ptmx (see man ptmx) which creates a slave device that looks like a normal serial port named /dev/pts/something. Unfortunately, the actual device name created isn't consistent, so the remserial program creates a symbol link from the device name specified with the -l option to the /dev/pts/ name that was created allowing the other application to be configured with a consistent device name. 4) Server farm console control. Assuming multiple Linux servers (such as web servers) are set up to have a serial port as their console instead of a monitor/keyboard, their serial ports could be connected to a control server using a multi-port serial board. On the control server, a copy of remserial is run for each server: remserial -d -p 23000 -s "115200 raw" /dev/ttyS0 & remserial -d -p 23001 -s "115200 raw" /dev/ttyS1 & remserial -d -p 23002 -s "115200 raw" /dev/ttyS2 & remserial -d -p 23003 -s "115200 raw" /dev/ttyS3 & etc. From any computer on the local network, use a telnet program to connect to the control server on the appropriate port: telnet control-server-name 23002 This would connect through the associated serial port to the desired server's console. This example would then give the user console access to the 3rd server. Careful scripting such as using the Linux "expect" program could allow batches of commands to be run on each server. Other Linux program useful with remserial ----------------------------------------- - nc - The netcat program is similar to remserial except that it creates connections between network ports and command line standard input and output. For example, with case number 1 above, the following command run on another computer will send the contents of the named file out the serial port used by the remserial program: nc server-name 23000 <file-name Similarily, the following command will store incoming serial data in a file until the program is manually interrupted: nc server-name 23000 >file-name - telnet - The telnet program is normally used to log into a remote computer, but when used with network ports other than number 23, it operates in a raw data mode. For example, with case number 1 above, the following command will allow the user of the telnet program to see incoming serial port data and type data on the keyboard to send to the serial port: telnet server-name 23000 This is ideal for controlling the device connected to the serial port if it has some sort of command line interface usable over the serial port. remserial Usage: --------------- remserial [-r machinename] [-p netport] [-s "stty params"] device -r machinename The remote machine name to connect to. If not specified, then this is the server side. -p netport Specifiy IP port# (default 23000) -s "stty params" If serial port, specify stty parameters, see man stty -d Run as daemon programs -x debuglevel Set debug level, 0 is default, 1,2 give more info -l linkname If the device is /dev/ptmx, creates a symbolic link to the corresponding slave pseudo-tty so that another application has a static device name to use. -m max-connections Maximum number of simultaneous client connections to allow device Character oriented device node such as /dev/ttyS0.
It is currently hard-coded to 0 (not even INADDR_ANY ><) so running remserial binds the port to all network interfaces. It would be useful if one could specify the IP address to bind to (as well as the port) to help restrict access to more local networks.
When remserial is used in conjunction with a USB to serial adapter and udev\rules.d to start remserial when the converter is plugged in, after a hard reset (eg. unplug/plug) or soft reset (usbreset) remserial fails to start because of TIME-WAIT state, with message "Couldn't bind port XXXX, aborting: Address already in use".
I would suggest to use SO_REUSEADDR option to overcome this issue.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.