AnsweredAssumed Answered

serial port timeout before expected # of bytes arrives

Question asked by Nass Sil on Jul 4, 2013
Latest reply on Jul 17, 2013 by Nass Sil

Hello everyone,
  I am trying to port an application that is receiving/sending data through the serial port.
  On the sabrelite board that is the /dev/ttymxc0 port, ie the 2ndary serial port (the primary being /dev/ttymxc1).
 
  I am using the functions select() and read() to read from the serial port , in order to implement a timeout mechanism that is waiting for a few seconds for bytes to arrive and if should they not arrive, then the timeout is reached.
 
  The receiving loop works like this:
 

  1. I wait for 2 bytes - the opcode of the command.
  2. Once I resolve a code, I wait for 4 bytes designating the length of data that will follow (depending on the command)
  3. I create a buffer in my application of size equal to the length I received above.
  4. I start receiving the data.


 
  Note that I have implemented reception of the data in 2 ways (since the 1st way used to work, it was tried as is. Then, I tried the next as well):
    a)receive my data using a for loop, reading() one byte at time. until all the expected bytes arrive , or a timeout is reached.
    b)receive my data using a while loop where I ask for all the remaining bytes to be read(). Read() returns how many bytes have actually arrived, so I update the remaining Bytes and re-read(). Again if a select() times-out without any data arriving, the loop will exit.

  Now, my problem is that while applications seem to be using this port without any problem (f.e. minicom, rx, cat /dev/ttymxc0, echo "something" > /dev/ttymxc0 ) , through the application I get timeouts for any file that is bigger than 3-4kBytes.

  Say I am trying to send a file 138kB. I may fail at byte ~40k, ~56k, or even ~12k. This is very weird. And I don't know what to assume is going wrong. Slow processing on the local end seems to not be a problem, as I can read (in (b) above) approx 58 bytes in the beginning and then 1 byte at a time. Could it be the memory buffer? If yes, how can I increase its size? Could another application be interfering with /dev/ttymxc0?


  I am running yocto dylan  fsl-image-test with all -dev, -sdk & -dbg options enabled.


  Thank you for your help.

Outcomes