libserial
当使用's 对象与串行 USB 设备(用于获取道路交通警报的 GNS FM9 接收器)通信SerialStream
时,我发现并非来自设备的所有字符实际上都被读取。这是我一直得到的服务:
3F 00 56 08 37 3F
将同一设备与RDS Surveyor 应用程序(用 Java 编写并使用com.fazecast.jSerialComm.SerialPort
)一起使用时,相同的响应如下所示:
3F 00 00 56 08 0A 37 0C 0D 3F
经过一番研究,我偶然发现了这个帖子:Wrong newline character over the serial port (CR instead of LF)。发帖人没有使用libserial
(而是一些现成的串口通讯应用),但他的问题和我的一模一样。
这是相关端口的系统端配置:
pi@autoradio:~ $ stty -a
speed 38400 baud; rows 40; columns 80; line = 0; intr = ^C; quit = ^\; erase = ^?; kill = ^U;
eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z;
rprnt = ^R; werase = ^W; lnext = ^V; discard = ^O; min = 1; time = 0; -parenb -parodd -cmspar
cs8 -hupcl -cstopb cread -clocal -crtscts -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr
-igncr icrnl ixon ixoff -iuclc -ixany -imaxbel iutf8 opost -olcuc -ocrnl onlcr -onocr -onlret
-ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0 isig icanon iexten echo echoe echok -echonl -noflsh
-xcase -tostop -echoprt echoctl echoke -flusho -extproc
该系统是运行最新生产版本的 Raspbian 的 Raspbery Pi 3B。在系统端,设备如下所示:
pi@autoradio:~ $ ls -al /dev/ttyUSB0
crw-rw---- 1 root dialout 188, 0 Jun 7 17:11 /dev/ttyUSB0
现在,我的问题是:如何让我的 SerialStream 读取所有字符而不进行任何转换,就像它们来自端口一样?我真的不想stty
在这种情况下使用,因为它的设置可能会在移除和重新连接设备时被覆盖。谢谢你。