How can I set up a "USB proxy" for /dev/ttyUSB0 over the network?

socat might work here.

On the 2nd PC you could let socat listen for data on /dev/ttyUSB0 and serve it to a tcp port, e.g:

socat /dev/ttyUSB0,raw,echo=0 tcp-listen:8888,reuseaddr

Then on 1st PC you can connect to 2nd PC with socat and provide the data on a pseudo terminal /dev/ttyVUSB0 for your application:

socat PTY,raw,echo=0,link=/dev/ttyVUSB0 tcp:<ip_of_pc2>:8888

This isn't tested and socat supports many options, so tweaking may be needed.


You can use a combination of ser2net and socat. For example, I have a robot connected to a raspberry pi through a serial port. The raspberry pi is connected to my local network (equivalent to your 2nd PC). And my laptop is connected to the same local network (equivalent to your 1st PC). Then I use ser2net to forward the serial port via TCP from the 2nd PC, and create a proxy serial device file using socat on the 1st PC.

This setup may work for you as well. Proposed solution:

Step 1: Install ser2net package on your 2nd PC (following your diagram)

sudo apt-get install ser2net

ser2net listens to a TCP port and is able to pipe data to and from a serial port via the TCP port. You can set up which serial ports you want to create "proxies" for via its configuration file /etc/ser2net.conf.

Step 2: configure ser2net in the 2nd PC

For example, if you have a device connected at /dev/ttyACM0 with baudrate 115200 and want to serve it from localhost port 3333, then you can add the following line to /etc/ser2net.conf

3333:raw:0:/dev/ttyACM0:115200,remctl

Having created the configuration file, then either start ser2net by running on the second PC:

ser2net

or (if it's already running, then just restart it as below)

/etc/init.d/ser2net restart

One important thing here is the remctl option. It allows the client side (1st PC in your diagram) to connect to the device and choose the serial connection options freely. I think this way the serial communication is completely transparent from the data collection workspace perspective. See more details here.

Step 3: Set up proxy serial device file on the data collection workstation (1st PC)

(if you don't have socat, then sudo apt-get install socat)

Finally, in a terminal on the 1st PC let socat create a proxy serial port that will listen from the tcp port:

socat pty,link=$HOME/MyProxySerialPort,waitslave tcp:$ip:$port,forever,reuseaddr,keepalive

Where, in this example ip=<2nd-PC-IP-address> and port=3333 (or whatever you chose when setting up /etc/ser2net.conf on the 2nd PC).

Step 4: Connect to MyProxySerialPort

Now you should be able to open a serial connection normally to the device located at $HOME/MyProxySerialPort on the 1st PC.

This blog post has some more information about this setup too: http://techtinkering.com/2013/04/02/connecting-to-a-remote-serial-port-over-tcpip/