For an application, which uses SerialPorts for communication (Modbus RTU, to be exactly) I need to bridge the SerialPort over the network for testing purposes.
So I would like to have the following Setup:
Device | Network | PC
SerialPort |------------------| SerialPort
Map Serialport| | Map network to Serialport
to Network | |
I already got the first part working with
I opened the TCP Port on PC with
nc -l 8080
On my Device I used
socat pty,link=/dev/virtualcom0 tcp:PC-IP:8080
To map everything written on
/dev/virtualcom0 to PC-IP on port 8080.
But now I have problems to map the socket back to a Serialport.
socat tcp:PC-IP:9123 pty,link=/dev/virtualport0
This got me a
Connection Refused, which is obvious because i used TCP and the Port is already used by the Device.
So I tried the same with
socat pty,link=/dev/virtualcom0,raw udp:PC-IP:8080
and changed everything else to UDP, too.
But then nothing arrives on my
/dev/virtlalcom0/ on my PC.
One side of the tcp connection needs to be listening on the port (the first one you launch), and the second side connects to it.
For the first side do:
socat tcp-listen:8080 pty,link=/dev/virtualport0
And for the second side do:
socat pty,link=/dev/virtualcom0 tcp:IP-of-other-machine:8080
Forget the netcat, you do not need it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!Donate Us With