问题
I want to determine exactly what data is sent by a controller to a off-board motor controller that has its own processor. I have not had success with plain text commands or json commands either. There is a program that the motor controller works with, however I need my own program to send the same information in the right format. Software being used is Coolterm and a tinyg board.
With interceptty I have been able to get one way communication back from the motor controller but not the data being sent to the controller. "interceptty -s 'ispeed 115200 ospeed 115200' /dev/ttyUSB0 /dev/tty<>" In the "<>"
I have tried my own words, letters, or other directories like S1. I have also tried /dev/<>
but coolterm won't recognize it in the dropdown menu.
No real error message just can't get data being sent by the computer. Can get data received.
回答1:
In my setup, I have two real (well, they are actually USB-to-serial adaptors) serial ports on /dev/ttyUSB0
and /dev/ttyUSB1
. I have linked them together with wires: RX on port 0 goes to TX on port 1, port 0 TX goes to port 1 RX.
I can open two terminals and send text from port 0 to port 1 or viceversa with minicom or any other terminal utility.
Now, if I want to snif on this link I can do the following: first I create a couple of virtual serial ports and link them to my real ports:
$ sudo socat -d -d pty,link=/dev/ttyUSB0,raw,echo=0 pty,link=/dev/ttyUSB1,raw,echo=0
This is the output I get (note the names of the virtual devices created):
2019/07/23 08:23:32 socat[10743] N PTY is /dev/pts/1
2019/07/23 08:23:32 socat[10743] N PTY is /dev/pts/2
2019/07/23 08:23:32 socat[10743] N starting data transfer loop with FDs [5,5] and [7,7]
And then I can run interceptty on a third terminal:
$sudo interceptty -s 'ispeed 9600 ospeed 9600' /dev/pts/2 /dev/ttyUSB1
I will now see all data traveling on the bus. This is an example of what I capture writing on port 0 and port 1 with minicom:
> 0x48 (H)
> 0x65 (e)
> 0x6c (l)
> 0x6c (l)
> 0x6f (o)
> 0x2c (,)
> 0x20
> 0x74 (t)
> 0x68 (h)
> 0x69 (i)
> 0x73 (s)
> 0x20
> 0x69 (i)
> 0x73 (s)
> 0x20
> 0x61 (a)
> 0x20
> 0x74 (t)
> 0x65 (e)
> 0x73 (s)
> 0x74 (t)
> 0x20
> 0x66 (f)
> 0x72 (r)
> 0x6f (o)
> 0x6d (m)
> 0x20
> 0x55 (U)
> 0x53 (S)
> 0x42 (B)
> 0x30 (0)
< 0x41 (A)
< 0x6e (n)
< 0x64 (d)
< 0x20
< 0x6e (n)
< 0x6f (o)
< 0x77 (w)
< 0x20
< 0x66 (f)
< 0x72 (r)
< 0x6f (o)
< 0x6d (m)
< 0x20
< 0x55 (U)
< 0x53 (S)
< 0x42 (B)
< 0x31 (1)
For your particular case, you only have one port on your computer, so you can create the virtual port pair with just one link:
$ sudo socat -d -d pty,link=/dev/ttyUSB0,raw,echo=0 pty,raw,echo=0
And run two sessions of interceptty:
$ sudo interceptty -s 'ispeed 9600 ospeed 9600' /dev/pts/1 /dev/ttyUSB0
$ sudo interceptty -s 'ispeed 9600 ospeed 9600' /dev/pts/2 /dev/ttyUSB0
For this to work reliably, I have to run first the two instances of interceptty and then open the USB ports (in my case with minicom).
Windows users can refer here for a similar solution using Termite and com0com.
Note that these procedures only work if you don't have hardware flow control active.
来源:https://stackoverflow.com/questions/57153141/cant-use-interceptty-or-slsnif-to-sniff-data-sent-via-serial-port