I have a tool that communicates with a robot via serial. My eventual goal is to build a man-in-the-middle box for the serial communication line, so that I can listen to the transmitted serial messages and modify them if desired, and then transmit them on. A small amount of latency introduced is not a problem. Can I do this with, say, a PC running Linux, and Perl? Is there a better way?
As a proof of concept, I figured I could use my laptop and two USB-to-Serial adapters.
As a first step, I plugged both serial adapters in, and connected them to each other through a null modem.
Now what? I figured I could just
, and then in a different terminal,
Code:
echo "blarg" >> /dev/ttyY
, and I would see "blarg" show up in the terminal that had cat running. The problem is figuring out what /dev/ttyX and /dev/ttyY are. My system has a bunch of tty device files, but how can I know which of them correspond to my two serial adapters?
Once upon a time, I had a perl script to communicated with a piece of lab equipment, and all I did was
Code:
open(MEOUT, ">>/dev/ttyUSB0");
open(MEIN, "</dev/ttyUSB0");
print MEOUT "*rst\n"; #reset the tool
The trouble I'm having is I have two USB-Serial adapters plugged in and I only have one /dev/ttyUSB0.
Even though I plugged two serial adapters in, there is only the one /dev/ttyUSB0 when they are both plugged in.
Code:
chaz@singularity:~$ ls /dev/tty*
/dev/tty /dev/tty16 /dev/tty24 /dev/tty32 /dev/tty40 /dev/tty49 /dev/tty57 /dev/tty8
/dev/tty0 /dev/tty17 /dev/tty25 /dev/tty33 /dev/tty41 /dev/tty5 /dev/tty58 /dev/tty9
/dev/tty1 /dev/tty18 /dev/tty26 /dev/tty34 /dev/tty42 /dev/tty50 /dev/tty59 /dev/ttyS0
/dev/tty10 /dev/tty19 /dev/tty27 /dev/tty35 /dev/tty43 /dev/tty51 /dev/tty6 /dev/ttyS1
/dev/tty11 /dev/tty2 /dev/tty28 /dev/tty36 /dev/tty44 /dev/tty52 /dev/tty60 /dev/ttyS2
/dev/tty12 /dev/tty20 /dev/tty29 /dev/tty37 /dev/tty45 /dev/tty53 /dev/tty61 /dev/ttyS3
/dev/tty13 /dev/tty21 /dev/tty3 /dev/tty38 /dev/tty46 /dev/tty54 /dev/tty62 /dev/ttyUSB0
/dev/tty14 /dev/tty22 /dev/tty30 /dev/tty39 /dev/tty47 /dev/tty55 /dev/tty63
/dev/tty15 /dev/tty23 /dev/tty31 /dev/tty4 /dev/tty48 /dev/tty56 /dev/tty7
chaz@singularity:~$