Pages: [1]   Go Down
Author Topic: Board stops listening after reading 73 bytes on /dev/ttyACM*  (Read 586 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Just another geek
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi there,

using the following piece of code written changing just few lines from what's been written by the user AlphaBeta (here)

Code:
int input;
int numberOfCharactersRead = 0;

void setup() {
  Serial.begin(9600);
}

void loop() {
  if (Serial.available()) {
    // Read next character ...
    input = Serial.read();
    
    Serial.print("DEBUG: numberOfCharactersRead ==");
    Serial.println(++numberOfCharactersRead);

    // Print just-read character ...
    Serial.print("DEBUG: Serial.println((char)input) ==");
    Serial.println((char)input);
  }
}

and typing from the command-line (using Bash)

Code:
$ cat theLog > /dev/ttyACM0    # theLog: ASCII text ; /dev/ttyACM0: serial port Arduino is listening to.

via the Serial Monitor (in the Arduino IDE) I see that only ~70 bytes are read -- doesn't matter how many bytes the file is filled with.

As for my understanding, the serial port gives up listening if it takes too long to read the file ... (?) Indeed, if one uses redirection to pass an infinite flow of bytes like

Code:
$ od /dev/urandom > /dev/ttyACM0

then problems disappear.

Any suggestion on how to fix that?

Thank you folks :-)
« Last Edit: November 12, 2013, 06:15:19 am by giuscri » Logged

Sweden
Offline Offline
Sr. Member
****
Karma: 11
Posts: 443
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Remove the printout and see what happens. My guess is that you fill the output buffer and the Arduino then waits for space which then misses the receive.

To test this idea simply remove the printout in the sketch for each recieved character and do for instance one every 100 or a time limit.

My guess is also that od and cat give very different bursts of data to the driver. This also gives an idea on how to fix this. You can write your own version of cat that does not write so fast ;-) You can also use expect and look for "sync" messages. A bit like xon/xoff.

Cheers!
Logged

Pages: [1]   Go Up
Jump to: