Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

Thanks!

EDIT:

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

EDIT2:

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

enter image description here

'

'

'

EDIT3:

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

Example:

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.

like image 811
PedroD Avatar asked May 26 '14 09:05

PedroD


People also ask

What is Null-modem emulator?

The Null-modem emulator is an open source kernel-mode virtual serial port driver for Windows, available freely under GPL license. The Null-modem emulator allows you to create an unlimited number of virtual COM port pairs and use any pair to connect one COM port based application to another.

Is com0com free?

com0com is a free utility to create virtual serial port pairs that can be used to capture the debug output of ReactOS and direct it to a terminal program. Useful terminal programs that are able to get this output include: Hyper Terminal. Teraterm.

What is tty0tty?

The Linux null-modem emulator (tty0tty) is a kernel-module virtual serial port driver for Linux. This create virtual tty ports pairs and use any pair to connect one tty serial port based application to another. There are a version using pseudo-terminal (UNIX 98 style).


1 Answers

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.

like image 166
wojciii Avatar answered Oct 04 '22 08:10

wojciii