AnthonyVillacorta / arduino

Automatically exported from code.google.com/p/arduino
0 stars 0 forks source link

Erroneous code generation #86

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The following simple command line editor geneates erroneous code. The 
program runs on other systems (DOS, Windows and 8051 microcontrollers) as 
expeted.

void SerialGets(char *rxstring, int MaxNumberOfCharsToRead);

void setup()                    // run once, when the sketch starts
{
  Serial.begin(9600);
  Serial.println("Read string test...");

}

void loop()                     // run over and over again
{
  /* print prompt */
  Serial.print("\n\r> ");

  /* read command */
  char command[17];

  SerialGets(command, 10);
  Serial.print("    String entered -> ");
  Serial.println(command);
  /* execute command */
  if(strcmp(command, "init") == 0){
    Serial.println("\ninit command executed\n");
  }
}

void SerialGets(char *rxstring, int MaxNumberOfCharsToRead)
{
  char c;
  int pos;

  pos = 0;

  while(pos <= MaxNumberOfCharsToRead) {
  if(Serial.available()) {  
    c = Serial.read();
      if(c == 8 ) {  // Backspace?
        if(pos != 0 ) { 
          Serial.print(8, BYTE);
          Serial.print(" ");
          Serial.print(8, BYTE);
          pos--;
        }
      }
      if(c == '\n' || c == '\r') break;
      if(c >= 32 && pos < MaxNumberOfCharsToRead) {
        Serial.print(c);          // echo if character >= "SPACE"     
        rxstring[pos++] = c;
      }
    }
  }

  rxstring[pos] = 0;

  return;
}

1. Entering string are working as expected, but the processing 
of "BACKSPACE" characters is erroneous. 
2. Arduino is occassionally crashes when exetuting this program, after a 
crash occures, resetting the board does not help, uploadig a program 
revitalize the arduino board. 

I tested the program with a duemilanove board and Arduino 0016 and 0017

Regards,

BT

Original issue reported on code.google.com by b...@torok.info on 19 Aug 2009 at 5:29

Attachments:

GoogleCodeExporter commented 9 years ago
seems the bacspace handling is erroneous too. 
david any idea ?

Original comment by barzilo...@gmail.com on 10 Nov 2009 at 5:40

GoogleCodeExporter commented 9 years ago
I'm not sure what the bug is here.  If it's still present, can you open a new 
issue which highlights it more clearly?

Original comment by dmel...@gmail.com on 30 Dec 2011 at 11:26