PedroD PedroD - 1 year ago 313
Linux Question

Null modem emulator (com0com) for linux

I have a project that contains some unitary tests used to test the serial communications using COM ports (in windows). I use com0com to create a virtual pair of bounded ports and execute the tests.

However I don't know how to do that in Linux neither in MACOS. I've read this topic: Are there some program like COM0COM in linux? Where the answer suggests using socat. I've tried that approach but it doesn't work, my application doesn't detect the ports I've just defined in socat.

socat PTY,link=/dev/COM98 PTY,link=/dev/COM99

My theory is that socat cannot create virtual ports, it can only bind together existing ports.

How can I solve this issue?



This is what I get after running the previous socat command. If you look closely, you'll see that COM98 and COM99 ports are in /dev/. However if I write to /dev/COM98 and use tail -f to follow COM99 I don't get any output from it.

enter image description here


Well, if I use cat instead of tail I can see the output (why?!)

enter image description here





SOLUTION: Don't name the ports COMxx but ttySxx instead!


socat PTY,link=/dev/ttyS98 PTY,link=/dev/ttyS99

Reason why: Some serial-comm libraries may not support other nomenclature, such as RXTX 2.X.X and previous versions.

Answer Source
socat -d -d pty,raw,echo=0 pty,raw,echo=0

works just fine and prints:

2014/05/26 13:29:15 socat[27177] N PTY is /dev/pts/32
2014/05/26 13:29:15 socat[27177] N PTY is /dev/pts/33
2014/05/26 13:29:15 socat[27177] N starting data transfer loop with FDs [3,3] and [5,5]

I assume that you should be able to write to /dev/pts/32 and read from /dev/pts/33.

Also is /dev/COM9{8,9} a character device you can use?

ls -l /dev/COM989 

should print a mode which starts with c if that is the case.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download