Null modem emulator (com0com) for linux
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.
Are there some program like COM0COM in linux?
I found a good method:
socat PTY,link=COM8 PTY,link=COM9
then 2 virtual serial port files are created: COM8, COM9
How to simulate failure / cable break with com0com null-modem emulator
I finally found out how I can do it using com0com along with the tool com2tcp (which is part of the com0com project). The approach is described in this document: http://com0com.sourceforge.net/doc/UsingCom0com.pdf The com0com project is a really useful and amazing thing!
Basically, the idea is to create two pairs of virtual COM ports on the machine. In my case they are: COM7 <-> COM8 and COM9 <-> COM10. Then, using com2tcp utility, I redirect the data transmission between COM8 and COM10 via TCP. In two console windows I start the com2tcp once as server, once as client (as described in the document above). In particular, I use com2tcp --telnet \\.\COM8 12345
(where 12345 is some TCP port number) and com2tcp.exe --telnet \\.\COM10 1.2.3.4 12345
(where 1.2.3.4 is my machine's IP address). COM7 and COM9 are used by both instances of my application, so that the communication goes like this: PROCESS1 <-> COM7 <-> COM8 <---- TCP ----> COM10 <-> COM9 <-> PROCESS2
. Then, when both application instances are running, I just stop the com2tcp process by pressing CTRL+C
in the console - and that breaks the port-to-port communication exactly as a cable break would do! In this way I could easily simulate and debug the behavior as I needed.
Are there some program like COM0COM in linux?
I found a good method:
socat PTY,link=COM8 PTY,link=COM9
then 2 virtual serial port files are created: COM8, COM9
Virtual Serial Port for Linux
You can use a pty ("pseudo-teletype", where a serial port is a "real teletype") for this. From one end, open /dev/ptyp5
, and then attach your program to /dev/ttyp5
; ttyp5
will act just like a serial port, but will send/receive everything it does via /dev/ptyp5.
If you really need it to talk to a file called /dev/ttys2
, then simply move your old /dev/ttys2
out of the way and make a symlink from ptyp5
to ttys2
.
Of course you can use some number other than ptyp5
. Perhaps pick one with a high number to avoid duplicates, since all your login terminals will also be using ptys.
Wikipedia has more about ptys: http://en.wikipedia.org/wiki/Pseudo_terminal
Related Topics
200,000 Images in Single Folder in Linux, Performance Issue or Not
Linux: Create Random Directory/File Hierarchy
Hook into Linux Key Event Handling
What's the Best Way to Find a String/Regex Match in Files Recursively? (Unix)
What Does "< /Dev/Null >& /Dev/Null" at the End of a Command Do
How to Check a File Exists and Execute a Command If Not
How to Overcome an Incompatibility Between the Ksh on Linux VS. That Installed on Aix/Solaris/Hpux
Prevent Process from Killing Itself Using Pkill
Linux Find Out Hyper-Threaded Core Id
Differencebetween Module_Init and Init_Module in a Linux Kernel Module
What Tools Do I Need to Develop in Actionscript (In Linux)
What Is Kernel Section Mismatch
When Should the Option Remainafterexit Needs to Be Set True When Creating New Systemd Services