Sample Header Ad - 728x90

create pty and connect it to a serial port /dev/ttyUSB0

0 votes
1 answer
4121 views
**Problem:** I have two Linux machines connected with a serial interface. I use ppp to communicate between them (I have to since it is a project requirement). Communication speed is at 9600 bits/s. I need to measure bandwidth used, bits/s, live, i.e. while the system is running. Initially I thought I would use ifstat -btwTWS -i ppp0, since this is what the tools was designed for. However the value that was displayed was way more than 9600 bits/s. It hovered around 12.09 Kbits/s. I did ask why this happening , and the response was that it could be because of a compression. This does make sense. What I need, however, is actual bits/s after compression and before decompression happens. **My initial approach to solve this problem:** Initially I thought to use some sort of a serial traffic sniffer with a capability to display a data rate. I've tried several, but whenever I try to connect to /dev/ttyUSB0 I'm getting a resource busy error. This is happening because PPP is taking over the device. **My second approach to solve this problem:** I want to create a pseudo serial port, connect it to a real serial port. Then PPP will take over pseudo serial port and I will sniff the traffic on a real serial port. Here is the diagram:
--------------------         -------------------------  
|                  |         |                       |
|      PPP         |         |        sniffer        |
|  -------------   |         |   ------------------  |              
|  | /dev/pty0 |---|---------|---|  /dev/ttyUSB0  |  |
|  -------------   |         |   ------------------  |
|                  |         |                       |
--------------------         -------------------------
My understanding is that socat can do that. I've been reading up on this, but I coulnd't find any options that allow me to do that. **So here is my question:** How do I create a pseudoterminal with socat and connect to a real serial port? Is that even possible?
Asked by flashburn (691 rep)
Jan 9, 2019, 10:33 PM
Last activity: Nov 22, 2021, 02:05 AM