初始化问题和较早的讨论在这里: http: //pastebin.com/GzsHhBs3
编辑/附加3:
VTIME 似乎工作正常:
在打开串口时,我设置
serial_opts.c_cc[VTIME]=60; //6 seconds
那么代码是: http: //pastebin.com/W0vPGDBm
我已经实现了超时时间测量,并尝试从串行端口重新读取(),直到满足 MAX_RETRIES(=5)。
超时似乎工作正常,调试输出是(显示最后 2 个 read() 操作和读取的字节):
SERIAL: DATA read 11 bytes and a total of 12262 .
SERIAL: serDataBuf[12262]= 0x32
SERIAL: serDataBuf[12263]= 0x30
SERIAL: serDataBuf[12264]= 0x32
SERIAL: serDataBuf[12265]= 0x30
SERIAL: serDataBuf[12266]= 0x32
SERIAL: serDataBuf[12267]= 0x30
SERIAL: serDataBuf[12268]= 0x32
SERIAL: serDataBuf[12269]= 0x30
SERIAL: serDataBuf[12270]= 0x32
SERIAL: serDataBuf[12271]= 0x30
SERIAL: serDataBuf[12272]= 0x32
SERIAL: DATA read 5 bytes and a total of 12273 .
SERIAL: serDataBuf[12273]= 0x30
SERIAL: serDataBuf[12274]= 0x32
SERIAL: serDataBuf[12275]= 0x30
SERIAL: serDataBuf[12276]= 0x32
SERIAL: serDataBuf[12277]= 0x30
SERIAL: time diff is tv_sec=5 , tv_usec=996447
SERIAL: No DATA have been read. Timeout @ byte 12278, timeout counter 0.
SERIAL: time diff is tv_sec=5 , tv_usec=999983
SERIAL: No DATA have been read. Timeout @ byte 12278, timeout counter 1.
SERIAL: time diff is tv_sec=5 , tv_usec=999973
SERIAL: No DATA have been read. Timeout @ byte 12278, timeout counter 2.
SERIAL: time diff is tv_sec=5 , tv_usec=999961
SERIAL: No DATA have been read. Timeout @ byte 12278, timeout counter 3.
SERIAL: time diff is tv_sec=5 , tv_usec=999974
SERIAL: No DATA have been read. Timeout @ byte 12278, timeout counter 4.
SERIAL: time diff is tv_sec=5 , tv_usec=999960
SERIAL: No DATA have been read. Timeout @ byte 12278, timeout counter 5.
SERIAL: time diff is tv_sec=5 , tv_usec=999982
SERIAL: No DATA have been read. Timeout @ byte 12278, timeout counter 6.
请注意,接收到的最后一个字节是有效的 ascii char(0x30,对应于 char '0')。看起来在 6sec/retry*6 retries = 36 secs 之后,我仍然没有收到任何数据。
我会开始研究发送方代码,但我在这里移植的代码(从内核 2.4 嵌入式系统到内核 3.0.35 emb。系统)曾经工作......所以它必须是接收端的东西边。