LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Serial ports, USB-Serial adapters, and Linux (https://www.linuxquestions.org/questions/linux-newbie-8/serial-ports-usb-serial-adapters-and-linux-831087/)

Daravon 09-08-2010 07:38 PM

Serial ports, USB-Serial adapters, and Linux
 
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
Code:

cat /dev/ttyX
, 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:~$


Daravon 09-08-2010 10:19 PM

I've discovered that while both USB-to-Serial adapters show up in lsusb, only one of them results in the creation of a /dev/ttyUSB* file. Any ideas on why the other one does not? Is it faulty?

Blue adapter:
Code:

chaz@singularity:~$ lsusb
Bus 002 Device 004: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 004: ID 0c45:62c0 Microdia Sonix USB 2.0 Camera
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
chaz@singularity:~$

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:~$


black adapter:
Code:

chaz@singularity:~$ lsusb
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 006: ID 9710:7715 MosChip Semiconductor Printer cable
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 004: ID 0c45:62c0 Microdia Sonix USB 2.0 Camera
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
chaz@singularity:~$

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/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:~$


jf.argentino 09-09-2010 06:31 AM

Quote:

Bus 003 Device 006: ID 9710:7715 MosChip Semiconductor Printer cable
It looks more like a parallel adapter than a serial one...

Daravon 09-09-2010 06:53 AM

It was one of those Open-box discounted items at Fry's. I bet someone switched devices in the package.


All times are GMT -5. The time now is 05:41 AM.