Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a virtual serial port connection over TCP

I am developing an application that should be able to write to a virtual serial port and receive data through the same port from remote clients over network.

The application runs on a linux server. I am new in using serial ports and I have some questions on this topic.

Clients

The client can establish a TCP connection to a server. When we setup a client, we have to provide the IP address of the server, a tcp port (usually 8080) and a virtual com port.

The client then will automatically try to connect to the server.

Server

The server has a virtual com port, the same we set in the client config (e.g. COM1). When an application on the server writes data to this port, the data should be send to all clients connected via tcp. The response from the clients is send over TCP back to the server which can read it over the virtual serial port.

Question

On windows I used a virtual serial port connector http://www.eterlogic.com/Products.VSPE.html which did most of the work. However I want to solve this problem on linux machines.

My question is, how can I create a TCP server that has a virtual serial port attached and can send/receive data through this port over TCP to listening clients?

like image 604
UpCat Avatar asked Mar 25 '14 03:03

UpCat


People also ask

What is a virtual serial port in TCP?

The server has a virtual com port, the same we set in the client config (e.g. COM1). When an application on the server writes data to this port, the data should be send to all clients connected via tcp. The response from the clients is send over TCP back to the server which can read it over the virtual serial port.

How do I configure TCP sockets in a virtual machine?

The TCP socket will act in client mode if you select the Connect to Existing Pipe/Socket check box. Up to four serial ports can be configured per virtual machine, but you can pick any port numbers out of the above. However, serial ports cannot reliably share interrupts.

How to establish a TCP connection to a server?

The client can establish a TCP connection to a server. When we setup a client, we have to provide the IP address of the server, a tcp port (usually 8080) and a virtual com port.

How many serial ports can be configured on a TCP socket?

When the "Connect to Existing Pipe/Socket" box is ticked, the TCP socket will go into client mode. As you can see, 4 serial ports can be configured or each virtual machine.


1 Answers

Try socat. Possible scenario:

socat  pty,link=/dev/virtualcom0,raw  tcp:192.168.254.254:8080& 

socat creates TCP connection to 192.168.254.254:8080, so that everything, that will be written to /dev/virtualcom0 will be forwarded to 192.168.254.254:8080 and vice versa.

Another approach would be to use RFC2217 via ser2net on Linux sever side and RFC2217 driver on Windows side (for example http://www.hw-group.com/products/hw_vsp/index_en.html single port version). You can also try to get http://pyserial.sourceforge.net/ to work with ser2net.

like image 160
yegorich Avatar answered Sep 20 '22 08:09

yegorich