Reputation: 1485
init question and older discussion here: http://pastebin.com/GzsHhBs3
EDIT/append3:
VTIME seems to work correctly:
while opening the serial port, i set
serial_opts.c_cc[VTIME]=60; //6 seconds
then the code is : http://pastebin.com/W0vPGDBm
I have implemented time measurement for the timeout, and an attempt to reread() from the serial port until MAX_RETRIES (=5) is met.
The timeout seems to work right, and the debug output is (showing the last 2 read() operations, and the bytes that were 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.
Note that the last byte receive is a valid ascii char (0x30, corresponding to a char '0'). it also looks like after 6sec/retry*6 retries = 36 secs , I still haven't received any data.
I would start looking into the sender side code, but the code I am porting here (from a kernel 2.4 embedded system, to kernel 3.0.35 emb. system) used to work..... so it must be something on the receiving side.
Upvotes: 1
Views: 5309
Reputation: 1485
in a desperate attempt at my office, we modified the host application (running on windows, build on MS Visual Studio, as a .net application). So we created a small C++ serial port control application to just bypass the .net and voila! Without altering the code on the embedded system side, I can now read the full data I expect (from the embedded device side)!
I am not going to blame .net since the problem started showing up after I ported the embedded sytem's code from an older device ARM9TDMI-ARMv4T (running linux with kernel 2.4), to the newer freescale cortex A9 imx6q sabrelite.
However, I will note here that moving away from .net code, the C++ serial port control that we wrote worked both with the old device and the new one.
So the code above should work for reading from the serial port in linux.
I wonder if there is something with the serial port driver of the boundary-devices linux kernel 3.0.35 that is used by the yocto project (and which I am running on the board right now). If somebody knows anything about serial port problems with the sabrelite, pleasee share them. Thanks!
Upvotes: 1