Linux tty-写入/读取uart脚本

Linux tty-写入/读取uart脚本,linux,bash,serial-port,uart,tty,Linux,Bash,Serial Port,Uart,Tty,我的tty有问题(我正在进行UART通信PCuC) 我将数据发送到uC,然后uC将其发送回(echo)。 我想读写到tty cat /dev/ttyUSB0 >output.txt & #redirect output to file and move to background echo abcd > /dev/ttyUSB0 #write to tty 在第一次运行时,脚本运行良好。但如果它再次运行,它会跳过字符、更改顺序等。我必须拔下并插入usb(pl23

我的tty有问题(我正在进行UART通信PCuC)

我将数据发送到uC,然后uC将其发送回(echo)。 我想读写到tty

cat /dev/ttyUSB0 >output.txt & #redirect output to file and move to background
echo abcd > /dev/ttyUSB0       #write to tty
在第一次运行时,脚本运行良好。但如果它再次运行,它会跳过字符、更改顺序等。我必须拔下并插入usb(pl2303串行端口),以使脚本一次性正常工作。 我认为这可能是同步或一些缓冲区的问题。也许有一个命令可以在不拔出的情况下重置ttyUSB0

我的uC以9600 8N1发送数据

$ stty -F /dev/ttyUSB0 -a
speed 9600 baud; rows 0; columns 0; 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; flush = ^O; min = 1; time = 0;
-parenb -parodd 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
$stty-F/dev/ttyUSB0-a
速度9600波特;第0行;第0列;直线=0;
intr=^C;退出=^\;擦除=^?;杀死你;eof=^D;eol=;eol2=;swtch=;开始=^Q;停止=^S;susp=^Z;rprnt=^R;werase=^W;
lnext=^V;冲洗=^O;最小值=1;时间=0;
-parenb-parodd 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-echok-echonl-noflsh-xcase-tostop-echoprt-echoctl-echoke

谢谢你的帮助;)

您可以尝试编写一个C程序,该程序在/dev/ttyUSB0上使用读写系统调用。“cat/dev/ttyUSB0>output.txt&#重定向输出到文件”--您似乎有向后的输入/输出。从设备读取的数据称为“输入”。尝试从测试设置中移除uC,只需在其位置使用环回(即,将RS-232 RxD引脚连接到TxD引脚)。