There is ubuntu 16.04 which is installed on VirtualBox. In the machine itself, there is one physical com port, it is prokinut in VirtualBox in the "host device" mode like this:

enter image description here

I also turned on 2 ports in "off" mode:

enter image description here

As a result, these ports are defined on ubuntu. (But I can only work with one)

$ dmesg | grep tty [ 0.004000] console [tty0] enabled [ 0.772403] 00:02: ttyS0 at I/O 0x3f8 (irq = 4, base_baud = 115200) is a 16550A [ 0.794717] 00:03: ttyS1 at I/O 0x2f8 (irq = 3, base_baud = 115200) is a 16550A [ 0.816355] 00:04: ttyS2 at I/O 0x3e8 (irq = 4, base_baud = 115200) is a 16550A 

The question is: can I make it so that I can write to the com-port and read from it (like here ) without connecting any device (I just need an echo) and without resorting to any crutches like inserting a clip into the port to close Tx-rx.

Can socat help me with this? As I understand it, with the help of it you can make a bridge from one port to another, but I got confused in the wilds of its settings, I would be grateful if someone could tell me the correct line.

Or is socat not suitable for this purpose, and do I need something else?

  • In the same place, in the commentary to the answer, I wrote to you where to look for the inclusion of an internal feedback loop. - 0andriy

1 answer 1

The serial port in terms of * nix-systems is the usual terminal device. So the simplest thing is to create a pseudo-terminal and connect to it:

 socat PIPE PTY,link=/tmp/my_pty,raw,echo=0 
  • PIPE - creates an unnamed pipe between the input and the output, essentially works as a simple echo responder
  • PTY - creates a pseudo-terminal device to which you can connect
  • link=/tmp/my_pty - creates a link to the device to which you can connect, as to the device, it can be specified in open() when opening the port.
  • raw,echo=0 - sets the operation mode of the pseudo-terminal in order to exclude a change in the response data.

Of the differences from the present port, the most obvious is the absence of delay in sending / receiving data, regardless of the baudrate installed, and the data will be transmitted almost instantly and in a whole packet.


Of the alternatives:

  • tty0tty - emulates a full pair of ports connected to each other, as an echo, you can use the same socat on one of them.
  • Redirect the COM port in a box to a unix or tcp socket. Then you can use any echo client / server on a host or even a remote system on this socket. The same socat can act as a client / server.