Is it possible to create a "virtual" serial device that sends data through a "virtual" serial port? I need to develop some code to interact with an Arduino but don't have it with me. Can it be done with socat, or some code that writes to a dev/ttyXXX
file?
EDIT: I'm running Arch Linux
Download Virtual Serial Port Driver on your Windows machine. Install the application on your system and launch it. Choose “Pair” in the application's main window. Click the “Add a new pair” button to create a pair of virtual serial ports.
Virtual Serial Port Emulator allows you to create an unlimited number of virtual COM ports. The software emulates serial port functionality connected by virtual null modem cable in such a way that the system does not see the difference between virtual and real hardware ports.
A software-based virtual serial port presents one or more virtual serial port identifiers on a PC which other applications can see and interact with as if they were real hardware ports, but the data sent and received to these virtual devices is handled by software that manipulates the transmitted and received data to ...
Yes, you can use socat to simulate a serial port.
You need to use socat's PTY address type:
PTY: Generates a pseudo terminal (pty) and uses its master side. Another
process may open the pty's slave side using it like a serial line or
terminal.
The simplest option is:
socat PTY,link=./virtual-tty,raw,echo=0 -
Have the application you are testing opens virtual-tty
. Output from your
application will print to the console. Text you type will be sent to your
application.
As noted above, the PTY address type creates a
peudo-terminal. The link
option creates a soft-link between the pseudo-terminal and the given file.
You can choose any filename you wish. Without the soft-link you would need to
open the device and it is difficult to determine the correct one. raw
puts the pseudo-terminal in raw mode. You usually want this as you don't want
any of the special terminal handling options. echo=0
disables echo mode.
If you have (or create) an application that simulates the code executing on the Arduino, you can connect it via socat as well. If your simulator comunicates via stdin/stdout, then use the following command:
socat PTY,link=./virtual-tty,raw,echo=0 EXEC:simulator-command
The above connects the stdin/stdout of simulator-command
to the
pseudo-terminal.
If your simulator communicates via a serial port as well, then use the PTY command twice:
socat PTY,link=./arduino-sim,raw,echo=0 PTY,link=./virtual-tty,raw,echo=0
Have your simulator open arduino-sim
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With