Skip to content

Instantly share code, notes, and snippets.

@f-steff
Created May 24, 2024 10:01
Show Gist options
  • Save f-steff/2d1f3d2cfa920f70bcafce03ac87c579 to your computer and use it in GitHub Desktop.
Save f-steff/2d1f3d2cfa920f70bcafce03ac87c579 to your computer and use it in GitHub Desktop.
Forward a serial port from Linux to Windows

Forward a serial port from Linux to Windows.

Prerequisites:

  • com0com and com2tcp must be installed on the Windows machine (https://sourceforge.net/projects/com0com/)
  • socat must be installed on the linux box.
  • Optional, to log the communication (on windows) install hub4com (part of the com0com project).

Steps (tested on RPi):

  1. On Windown use com0com to create a pair of virtual serial ports. One port will be used to connect to the com2tcp, the other will be the forwarded serial port from linux.

  2. Add a virtual COM-pair (eg. COM10 <-> COM50) on the Windows machine with the help of com0com.

  3. Execute following command on the linux box, to create a background process that forwards /dev/ttyAMA0 over tcp (modify the device, baudrate, and port as needed):

	socat file:/dev/ttyAMA0,raw,echo=0,b115200 tcp-l:3000,fork& 
  1. Start com2tcp on the Windows PC with following command:
	com2tcp --baud 115200 --ignore-dsr \\.\COM50 10.0.0.53 3000
  1. Now you can communicate via COM0 with the device attached to /dev/ttyAMA0

Untested

  1. To use hub4com instead of com2tcp, use something like this:
	com4hub --baudrate=115200 --ignore-dsr=true --log=both --logfile=com4hub_log.txt --serial=\\.\COM50 --tcp=10.0.0.53:3000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment