Go Down

Topic: SoftwareSerial Signal FIFO (Read 929 times) previous topic - next topic

kj9k

Hello,

I am reading information from an Maxbotix LV-WR1 through a SoftwareSerial connection.

Unfortunately, the result is delayed. I guess that I only read the next Data transmitted but not the last.

Here is the part of my software where I am reading the Data.
Code: [Select]
// UltrasonicSerial
float readUltraSerial() {
  char new;
  int inchInt = 0, counter=0;
  char * inch;
 
  if (UltraSerial.available()) {
    for(;;) {

      neu = UltraSerial.read();
     
      if (neu == 'R' || isNumber(neu)) {
        if (neu == 'R') {
        //  Serial.println();
          inch = "";
          counter = 0;
        } else {
          inch[counter] = new;
          counter++;
        }
        Serial.print(counter);
        Serial.print(" - ");
        Serial.println(new);
       
       
        if (counter == 3) {
          inchInt = atoi(inch);
          Serial.print(inchInt);
          Serial.print(" - ");
          Serial.println(inchInt*2.54);
          return (inchInt*2.54);
        }
      }
    }
  } else {
    return 0;
  }
}


I am using an Arduino Mega 2560 and I have free HardwareSerial ports but I can't read the RS232 Data from the Sensor. If you could help me with that, it would be even better.


Thank you

robtillaart


the problem is in these two lines

Code: [Select]
if (UltraSerial.available()) {
    for(;;) {


suppose you have one byte available in UltraSerial, it enters an endless loop that (tries to) read a char per iteration (assuming neu and new are the same;)

add a few lines to check it.
Code: [Select]

  if (UltraSerial.available()) {
    for(;;) {

      neu = UltraSerial.read();
      Serial.print("<");
      Serial.print(neu, DEC);
      Serial.println(">");
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

kj9k

Thank you that helped me :-)

Go Up