Missing flow control data (0x13) from reading device data stream

有些话、适合烂在心里 提交于 2019-12-06 21:33:32

Thanks for any responses, like the website. Turns out stty showed:

# stty -F /dev/ttyUSB0

speed 115200 baud;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;
eol2 = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W;
lnext = ^V; flush = ^O; min = 0; time = 10;
-brkint -imaxbel
-opost
-isig -icanon -echo -echoe

Even though it looked like flow control was off, The solution was to use cfmakeraw settings to see ALL characters and ignore nothing.

cfmakeraw() sets the terminal to something like the "raw" mode of the old Version 7 terminal driver: input is available character by character, echoing is disabled, and all special processing of terminal input and output characters is disabled. The terminal attributes are set as follows:

termios_p->c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP
            | INLCR | IGNCR | ICRNL | IXON);
termios_p->c_oflag &= ~OPOST;
termios_p->c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
termios_p->c_cflag &= ~(CSIZE | PARENB);
termios_p->c_cflag |= CS8;

Can see all my data now :)

Maybe it's better to avoid control characters being sent through serial port at all, and instead slightly modify app on Linux and remote device to encode/decode them into/from two bytes. For example:

0x00 0x00 -> 0x00
0x00 0x01 -> 0x13 (escape XOFF)
0x00 0x02 -> 0x11 (escape XON) 

Considering the probability of appearing of these 3 bytes in a binary stream this shouldn't decrease the overall throughput I think.

And by the way, XON/XOFF is a software flow control and basic function of serial/terminal drivers. Actually this function can be useful in your case too - to avoid buffers overflow and missing some valuable bytes you can pause (XOFF) or resume (XON) transmission.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!