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
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
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.
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
Fake serial communication under Linux
It's probably best to use pyserial to communicate with the serial port, and you can just create a mock version of the serial.Serial
class which implements read
, readline
, write
and any other methods you need.
How to connect two virtual serial ports to read data from GPSFeed+?
Steps
- Download
gpsfeed+
from https://gpsfeed.sourceforge.io/ - Make executable the file downloaded:
$ chomod +x gpsfeed+_amd64
- Install
socat
package:
$ sudo pacman -S socat
- Create a pair of virtual serial ports (VSPs) with
socat
:
$ socat -d -d pty,raw,echo=0 pty,raw,echo=0
- It displays virtual ports created, in this case:
/dev/pts/4
and/dev/pts/5
. One port will be transmitter and the another one will be the receiver. - Open
gpsfeed+
application:
$ ./gpsfeed+_amd64\
- In Configuration for
gpsfeed+
to do:
- Connection >> check: Serial, and uncheck: TCP, UDP, Http
- Serial/IP >> Port: /dev/pts/4 (transmitter), and Speed: 9600
- Run simulator (button with a concentric circle as icon)
- Read data from /dev/pts/5 (receiver)
Python code (install pyserial
package):
import serial
ser = serial.Serial('/dev/pts/5', 9600)
iter = 5
while iter > 0:
print(ser.readline().decode("utf-8"))
iter -= 1
The very few existing packages for Dart (like dart_serial_port
) do not work with virtual ports.
Related Topics
Packaging Proprietary Software for Linux
"Cd" Does Not Work in Shell Script
Elf Program Header Virtual Address and File Offset
Rename Multiple Directories Matching Pattern
How to Keep Executable Code in Memory Even Under Memory Pressure? in Linux
Can an Interrupt Handler Be Preempted
What Do the Characters in the Bash Environment Variable $- Mean
What Does the Gcc Error Message, "Error: Unsupported for 'Mov'", Mean
How to Write-Protect Every Page in the Address Space of a Linux Process
How to List the Files in a Zip Archive Without Decompressing It
How to Run a Command as a Specific User in an Init Script
Difference Between .Dynamic .Dynsym and .Dynstr in an Elf Executable
Arm Linux Atags VS Device Tree
How Does Ancillary Data in Sendmsg() Work