Tools quickstart
In five minutes you connect two virtual serial ports with a null-modem cable, send bytes across, and inject a fault that the receiving side sees. For the concepts, see How virtual serial ports work.
Before you begin
Section titled “Before you begin”-
You need macOS or Linux and three terminals. This quickstart uses pseudo terminals (pty), so you don’t install a driver.
-
The
pdcomm-vserialprogram must be on yourPATH. The Linux package installs it as/usr/bin/pdcomm-vserial. Check the version:터미널 창 pdcomm-vserial --versionThe program prints its version, for example
pdcomm-vserial 0.1.0.
Create a virtual pair
Section titled “Create a virtual pair”-
In terminal 1, start the pair.
--link-aand--link-badd a symbolic link at a fixed path for each port.터미널 창 pdcomm-vserial pair --link-a /tmp/pdcomm-a --link-b /tmp/pdcomm-bWhen the lab is ready, it prints its ports as one JSON line. The
pathvalues change from run to run.{"ports":[{"backend":"pty","link":"/tmp/pdcomm-a","node":"a","path":"/dev/ttys011"},{"backend":"pty","link":"/tmp/pdcomm-b","node":"b","path":"/dev/ttys016"}],"ready":true}The terminal now waits for commands that control the lab. Keep it open.
-
In terminal 2, print what port
breceives:터미널 창 cat /tmp/pdcomm-b -
In terminal 3, send a string to port
a:터미널 창 printf 'hello\n' > /tmp/pdcomm-ahelloappears in terminal 2. The pair runs at 9600 bit/s 8N1 and, like a real line, delivers one character per character time. -
In terminal 1, type the following command and press Enter. It flips bit 0x20 in the next character that port
breceives.{"command":"inject","node":"b","fault":{"xor":32}}The lab replies
{"ok":true}. -
In terminal 3, send again:
터미널 창 printf 'ABC\n' > /tmp/pdcomm-aTerminal 2 shows
aBC: only the first character changed, fromA(0x41) toa(0x61). -
In terminal 1, stop the lab:
{"command":"stop"}Closing the input with Ctrl+D stops the lab too. The lab removes the
/tmp/pdcomm-aand/tmp/pdcomm-blinks and exits with code 0. Press Ctrl+C to endcatin terminal 2.
Common errors
Section titled “Common errors”| Symptom | Fix |
|---|---|
pdcomm-vserial: /tmp/pdcomm-a exists and is not a symlink |
A regular file is in the way. Delete it or choose another path. The lab replaces symbolic links that an earlier lab left behind. |
| Nothing appears in terminal 2 | Check the link names. The sending port (a) and the receiving port (b) must differ. |
A command returns {"ok":false,"error":"unknown node …"} |
Use a node name of the lab (a or b) in node. |
Next steps
Section titled “Next steps”- Put a real protocol on a virtual bus: Test Modbus RTU on a virtual RS-485 bus.
- Look up every command and setting in pdcomm-vserial commands and lab files.
- Do the same from a GUI with the virtual serial manager.