Serial.readBytesUntil()

I'm not search four years worth the posts. It's not that important. It is what I was told. Both of you are showing with the program serialEvent() is not an ISR. At that time I was just starting and didn't know the Arduino lingo well. Likely I didn't ask the question using the correct lingo, which is very important on this site (if the words in the question are not just right, people fly off in every direction with their responses). Until recently the word 'interrupt' hasn't appeared in this thread nor in Serial Input Basics. Neither say serialEvent() is or is not an ISR.

I'm fine with changing that thought process, it is a matter of having the correct information.

You are correct there is no serialEvent() nor readBytesUntil(). It is the original code that needs to be modified to remove the five readStringUntil() instances. Unless I'm about to find out that readStringUntil() is non-blocking.

P.S. My bad. I asked about the wrong function. My mistake.

Here's the core of a non-blocking read-line thing. Just call it "reasonable often" in loop; it returns a non-zero value when its seen a line terminator... Don't forget that the Serial core is interrupt driven but has a relatively small buffer...

uint8_t parseGetline_nb(void)
{
    int c;

    c = Serial.read();
    switch (c) {
    case 127:
    case CTRL('H'):
    /*
     * Destructive backspace: remove last character
     */
    if (inptr > 0) {
        Serial.print("\010 \010");
        linebuffer[--inptr] = 0;
    }
    break;
    case CTRL('R'):
    /*
     * Ctrl-R retypes the line
     */
    Serial.print("\r\n");
    Serial.print(linebuffer);
    break;
    case CTRL('U'):
    /*
     * Ctrl-U deletes the entire line and starts over.
     */
    Serial.println("XXX");
    memset(linebuffer, 0, sizeof(linebuffer));
    inptr = 0;
    break;
    case CTRL('M'):
    Serial.println();            /* Echo newline too. */
    return inptr;
    default:
    /*
     * Otherwise, echo the character and put it into the buffer
     */
    linebuffer[inptr++] = c;
    Serial.write(c);
    case -1:
    /*
     * No character present; don’t do anything.
     */
    return 0;
    break;
    }
}
void setup() {
  while (!Serial)
    delay(500);
  Serial.begin(115200);
  Serial.print(F("Enter command: "));
  parseReset();
  pinMode(13, OUTPUT);
}

boolean delay_without_delaying(unsigned long &since, unsigned long time) {
  // return false if we're still "delaying", true if time ms has passed.
  // this should look a lot like "blink without delay"
  unsigned long currentmillis = millis();
  if (currentmillis - since >= time) {
    since = currentmillis;
    return true;
  }
  return false;
}

int red, blue, green;
unsigned long ledtime;

void loop() {
  char *p;
  int8_t cmd;
  int n;

  if (parseGetline_nb()) {
    do {
      enum {
        CMD_RED, CMD_GREEN, CMD_BLUE, CMD_RESET  // make sure this matches the string
      };
      cmd = parseKeyword(PSTR("red green blue reset")); // look for a command.

      if (cmd >= 0) {
        n = parseNumber();
      }
      switch (cmd) {
        case CMD_RED:
          red = n;
          break;
        case CMD_BLUE:
          blue = n;
          break;
        case CMD_GREEN:
          green = n;
          break;
        case CMD_RESET:
          red = green = blue = 0;
          break;
        case PARSER_EOL:
          Serial.print("RED = "); Serial.print(red);
          Serial.print(" GREEN = "); Serial.print(green);
          Serial.print(" BLUE= "); Serial.println(blue);
          break;
        default:
          Serial.println("Invalid command");
          break;
      }
    } while (cmd >= 0);
    parseReset();
    Serial.print(F("Enter command: "));
  } // if line
  
  static int ledstate = false;
  if (delay_without_delaying(ledtime, 500)) {
    ledstate = !ledstate;
    digitalWrite(13, ledstate);
  }
}

(The rest of the "parser library", such as it is, is at GitHub - WestfW/parser: Simple serial command line parser for Arduino/etc)

adwsystems:
Likely I didn't ask the question using the correct lingo, which is very important on this site (if the words in the question are not just right, people fly off in every direction with their responses).

I don't think we impose a standard of accuracy that is as high as that required by the compiler.

I still have no idea why you object to using the straightforward non-blocking code in Serial Input Basics. It works.

...R

I was heading down the serialEvent() road as I had previous been informed it was interrupt driven.

As for Serial Input Basics, I'm working to reverse engineer it now to understand how to incorporate in the PLX-DAQ program to then incorporate it into the main program.

This is my first pass. It is not optimized but functional and seems to be working with PLX-DAQ. There's too much code in loop(), but it is a start.

int i = 0;

String inputString = "";         // a String to hold incoming data
boolean stringComplete = false;  // whether the string is complete

void setup()
 {
  // open serial connection
   Serial.begin(9600);
   pinMode(3, INPUT_PULLUP);
   inputString.reserve(200);
 }

void StartTransfer()
 {
    //Serial.println("CLEARDATA"); // clears sheet starting at row 2
    Serial.println("CLEARSHEET"); // clears sheet starting at row 1
    
  // define 5 columns named "Date", "Time", "Timer", "Counter" and "millis"
    Serial.println("LABEL,Date,Time,Timer,Counter,millis");

  // set the names for the 3 checkboxes
    Serial.println("CUSTOMBOX1,LABEL,Stop logging at 250?");
    Serial.println("CUSTOMBOX2,LABEL,Resume log at 350?");
    Serial.println("CUSTOMBOX3,LABEL,Quit at 450?");

  // check 2 of the 3 checkboxes (first two to true, third to false)
    Serial.println("CUSTOMBOX1,SET,1");
    Serial.println("CUSTOMBOX2,SET,1");
    Serial.println("CUSTOMBOX3,SET,0");

    i=0;
 }
 
void SendData()
 {
  static boolean wait_for_response = false;
  
 // simple print out of number and millis. Output e.g.,: "DATA,DATE,TIME,TIMER,4711,13374,AUTOSCROLL_20"
  if (!wait_for_response)
   { Serial.println( (String) "DATA,DATE,TIME,TIMER," + i++ + "," + millis() + ",AUTOSCROLL_20" ); }

    // clear some cells in Excel (rectangle range from B10 to D20)
  if (i==100)
   { Serial.println("ClearRange,B,10,D,20"); }

    // do a simple beep in Excel on PC
  if (i==150)
   { Serial.println("BEEP"); }

    // read a value (in this case integer) from Excel (from a sheet by name)
  if (i==200)
   {
    if (!wait_for_response)
     {
      Serial.println("CELL,GET,FROMSHEET,Simple Data,E,4");  // ==> request value from sheet
      wait_for_response = true;
     }
     else
      {
       if (stringComplete == true)
        {
         Serial.println( (String) "Value of cell E4 is: " + inputString.toInt()); // result displayed in Excel DirectDebugWindow to double check
         stringComplete = false;
         inputString = "";
         wait_for_response = false;
        }
      }  
   }

    // check value of custombox1 on PLX DAQ in Excel and if
    // checkbox is checked then send the command to pause logging
  if (i==250)
   {
    if (!wait_for_response)
     {
      Serial.println("CUSTOMBOX1,GET");  // ==> request value from sheet
      wait_for_response = true;
     }
     else
      {
       if (stringComplete == true)
        {
         int stoplogging =  inputString.toInt();
         Serial.println( (String) "Value of stoplogging/checkbox is: " + stoplogging); // result displayed in Excel DirectDebugWindow to double check
         if(stoplogging) 
           Serial.println("PAUSELOGGING");
         stringComplete = false;
         inputString = "";
         wait_for_response = false; 
        }
      }  
   }

    // get a true random number from the computer
  if (i==300)
   {
    if (!wait_for_response)
     {
      Serial.println("GETRANDOM,-4321,12345"); // between -4321 to 12345
      wait_for_response = true;
     }
     else
      {
       if (stringComplete == true)
        {
         int rndseed = inputString.toInt();
         Serial.println( (String) "Got random value '" + rndseed + "' from Excel" );
         // Note: this information is not posted to the Excel sheet because "DATA" is missing
         // instead this information can be seen in the direct debug window
         stringComplete = false;
         inputString = "";
         wait_for_response = false;
        }
      }  
   }

    // and now resume logging
  if (i==350)
   {
    if (!wait_for_response)
     {
      Serial.println("CUSTOMBOX2,GET");
      wait_for_response = true;
     }
     else
      {
       if (stringComplete == true)
        {
         int resumelogging = inputString.toInt();
         if(resumelogging) 
           Serial.println("RESUMELOGGING");
         stringComplete = false;
         inputString = "";
         wait_for_response = false;
        }
      }  
   }

    // post to specific cells on default sheet as well as named sheet
  if (i==400)
   {
    Serial.println("CELL,SET,G10,400 test 1 string"); // default sheet active in PLX DAQ Excel
    Serial.println("CELL,SET,ONSHEET,Simple Data,G,11,400 test 2 string"); // named sheet available in PLX DAQ Excel
   }
       
  // and for forced quit of Excel with saving the file first
  if (i==123)
   {
    if (!wait_for_response)
     {
      Serial.println("CUSTOMBOX3,GET");
      wait_for_response = true;
     }
     else
      {
       if (stringComplete == true)
        {
         if (inputString.toInt())
          {
           Serial.println("SAVEWORKBOOKAS,450-Lines-File");
           Serial.println("FORCEEXCELQUIT");
          }
          else
           {
            Serial.println("No forced Excel quit requested!");
           }
         stringComplete = false;
         inputString = "";
         wait_for_response = false;
        }
      }  
   }
 
 }

void ReadSerial()
 {
  char inChar = (char)Serial.read();
    // add it to the inputString:
  inputString += inChar;
    // if the incoming character is a newline, set a flag so the main loop can
    // do something about it:
  if (inChar == 10)
   { stringComplete = true; }
 }
 
void loop()
 {
  static boolean transfer_data = false;
  int start_transfer;
  
  start_transfer = digitalRead(3);
  
  if ((start_transfer==1) && (transfer_data == false))
   {
    transfer_data = true;
    StartTransfer();
   }
   else if ((start_transfer==0) && (transfer_data == true))
    {
     transfer_data = false; 
    }

  if (transfer_data)
   {
    SendData();
   }
  if (Serial.available())
   { ReadSerial(); } 
 }

adwsystems:
This is my first pass.

You could replace these two lines in your loop() function

 if (Serial.available())
   { ReadSerial(); }

with

recvWithEndMarker();

if you include my function in your program.

It is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. Just use cstrings - char arrays terminated with 0.

...R

Robin2:
You could replace these two lines in your loop() function

 if (Serial.available())

{ ReadSerial(); }



with


recvWithEndMarker();



if you include my function in your program.

It is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. Just use [cstrings](http://www.cplusplus.com/reference/cstring/) - char arrays terminated with 0.

...R

First option didn't work so well as it wasn't compatible with anything except the example. On a leap of faith, I did take you second suggestion. I have never used the String class before, but it was in the example and worked the first try. I am more familiar with cstrings anyhow.

int i = 0;

char inputString[200];         // a String to hold incoming data
boolean stringComplete = false;  // whether the string is complete

void setup()
 {
  // open serial connection
   Serial.begin(9600);
   pinMode(3, INPUT_PULLUP);
 }

void StartTransfer()
 {
    //Serial.println("CLEARDATA"); // clears sheet starting at row 2
    Serial.println("CLEARSHEET"); // clears sheet starting at row 1
    
  // define 5 columns named "Date", "Time", "Timer", "Counter" and "millis"
    Serial.println("LABEL,Date,Time,Timer,Counter,millis");

  // set the names for the 3 checkboxes
    Serial.println("CUSTOMBOX1,LABEL,Stop logging at 250?");
    Serial.println("CUSTOMBOX2,LABEL,Resume log at 350?");
    Serial.println("CUSTOMBOX3,LABEL,Quit at 450?");

  // check 2 of the 3 checkboxes (first two to true, third to false)
    Serial.println("CUSTOMBOX1,SET,1");
    Serial.println("CUSTOMBOX2,SET,1");
    Serial.println("CUSTOMBOX3,SET,0");

    i=0;
 }
 
void SendData()
 {
  static boolean wait_for_response = false;
  
 // simple print out of number and millis. Output e.g.,: "DATA,DATE,TIME,TIMER,4711,13374,AUTOSCROLL_20"
  if (!wait_for_response)
   { Serial.println( (String) "DATA,DATE,TIME,TIMER," + i++ + "," + millis() + ",AUTOSCROLL_20" ); }

    // clear some cells in Excel (rectangle range from B10 to D20)
  if (i==100)
   { Serial.println("ClearRange,B,10,D,20"); }

    // do a simple beep in Excel on PC
  if (i==150)
   { Serial.println("BEEP"); }

    // read a value (in this case integer) from Excel (from a sheet by name)
  if (i==200)
   {
    if (!wait_for_response)
     {
      Serial.println("CELL,GET,FROMSHEET,Simple Data,E,4");  // ==> request value from sheet
      wait_for_response = true;
     }
     else
      {
       if (stringComplete == true)
        {
         Serial.println( (String) "Value of cell E4 is: " + atoi(inputString)); // result displayed in Excel DirectDebugWindow to double check
         stringComplete = false;
         ClearInputString();
         wait_for_response = false;
        }
      }  
   }

    // check value of custombox1 on PLX DAQ in Excel and if
    // checkbox is checked then send the command to pause logging
  if (i==250)
   {
    if (!wait_for_response)
     {
      Serial.println("CUSTOMBOX1,GET");  // ==> request value from sheet
      wait_for_response = true;
     }
     else
      {
       if (stringComplete == true)
        {
         int stoplogging =  atoi(inputString);
         Serial.println( (String) "Value of stoplogging/checkbox is: " + stoplogging); // result displayed in Excel DirectDebugWindow to double check
         if(stoplogging) 
           Serial.println("PAUSELOGGING");
         stringComplete = false;
         ClearInputString();
         wait_for_response = false; 
        }
      }  
   }

    // get a true random number from the computer
  if (i==300)
   {
    if (!wait_for_response)
     {
      Serial.println("GETRANDOM,-4321,12345"); // between -4321 to 12345
      wait_for_response = true;
     }
     else
      {
       if (stringComplete == true)
        {
         int rndseed = atoi(inputString);
         Serial.println( (String) "Got random value '" + rndseed + "' from Excel" );
         // Note: this information is not posted to the Excel sheet because "DATA" is missing
         // instead this information can be seen in the direct debug window
         stringComplete = false;
         ClearInputString();
         wait_for_response = false;
        }
      }  
   }

    // and now resume logging
  if (i==350)
   {
    if (!wait_for_response)
     {
      Serial.println("CUSTOMBOX2,GET");
      wait_for_response = true;
     }
     else
      {
       if (stringComplete == true)
        {
         int resumelogging = atoi(inputString);
         if(resumelogging) 
           Serial.println("RESUMELOGGING");
         stringComplete = false;
         ClearInputString();
         wait_for_response = false;
        }
      }  
   }

    // post to specific cells on default sheet as well as named sheet
  if (i==400)
   {
    Serial.println("CELL,SET,G10,400 test 1 string"); // default sheet active in PLX DAQ Excel
    Serial.println("CELL,SET,ONSHEET,Simple Data,G,11,400 test 2 string"); // named sheet available in PLX DAQ Excel
   }
       
  // and for forced quit of Excel with saving the file first
  if (i==123)
   {
    if (!wait_for_response)
     {
      Serial.println("CUSTOMBOX3,GET");
      wait_for_response = true;
     }
     else
      {
       if (stringComplete == true)
        {
         if (atoi(inputString))
          {
           Serial.println("SAVEWORKBOOKAS,450-Lines-File");
           Serial.println("FORCEEXCELQUIT");
          }
          else
           {
            Serial.println("No forced Excel quit requested!");
           }
         stringComplete = false;
         ClearInputString();
         wait_for_response = false;
        }
      }  
   }
 }

void ClearInputString()
 {
  int x;
  for (x=-0; x++; x<sizeof(inputString))
   { inputString[x]='\0'; }
 }
 
void ReadSerial()
 {
  static byte inputStringIDX = 0;
  
  char inChar = Serial.read();
  if (inputStringIDX < (sizeof(inputString) -1))
   {
    if (inChar == 10)
     {
      inputString[inputStringIDX] = '\0';
      inputStringIDX=0;
      stringComplete = true;
     }
     else
      {
       inputString[inputStringIDX] = inChar;
       inputStringIDX+=1;
      }
   }
 }
 
void loop()
 {
  static boolean transfer_data = false;
  int start_transfer;
  
  start_transfer = digitalRead(3);
  
  if ((start_transfer==1) && (transfer_data == false))
   {
    transfer_data = true;
    StartTransfer();
   }
   else if ((start_transfer==0) && (transfer_data == true))
    {
     transfer_data = false; 
    }

  if (transfer_data)
   {
    SendData();
   }
  if (Serial.available())
   { ReadSerial(); } 
 }

adwsystems:
First option didn't work so well as it wasn't compatible with anything except the example.

As you have not posted the program in which you tried it I have no idea why it did not work for you. It does work for me and for other Forum members.

...R

Robin2:
As you have not posted the program in which you tried it I have no idea why it did not work for you. It does work for me and for other Forum members.

...R

Why would I post broke code? Your suggestion was to copy and paste the Serial Basics into the previously posted code and replace the if statement with the function call. I did. I pasted in Example 3 (a more complete system) It didn't work. The example was written for a very specific format and structure which is wrong for my application. By the time I removed what didn't apply I wasn't left with much, including a compilable (is that word?) sketch.

As you suggest, it isn't that difficult, please feel free to move ahead. I already spent more than 4 hours reverse engineering the sketch to the basic the tactics and then to adapt it to create the working program posted.

Your example are nice but very specific. I don't see any time I could or would have been able to use them without extensive heavy modifications.

Do you see anything wrong with the posted sketch? Any gaps or improvements you suggest while you are critiquing it?

adwsystems:
Why would I post broke code?

WTF would be the point of posting working code?

If you post the broken code we may be able to tell you how to fix it.

...R

Robin2:
WTF would be the point of posting working code?

For the same reason you posted working code. As an example of how to do something, or as a solution to a problem, or to show you have solved someone else's problem.

Robin2:
As you have not posted the program in which you tried it I have no idea why it did not work for you. It does work for me and for other Forum members.

...R

OK. Here is exactly what you wanted. The original program with your function substituted for the if (Serial.available()) statement.

int i = 0;

String inputString = "";         // a String to hold incoming data
boolean stringComplete = false;  // whether the string is complete

void setup()
 {
  // open serial connection
   Serial.begin(9600);
   pinMode(3, INPUT_PULLUP);
   inputString.reserve(200);
 }

void StartTransfer()
 {
    //Serial.println("CLEARDATA"); // clears sheet starting at row 2
    Serial.println("CLEARSHEET"); // clears sheet starting at row 1
    
  // define 5 columns named "Date", "Time", "Timer", "Counter" and "millis"
    Serial.println("LABEL,Date,Time,Timer,Counter,millis");

  // set the names for the 3 checkboxes
    Serial.println("CUSTOMBOX1,LABEL,Stop logging at 250?");
    Serial.println("CUSTOMBOX2,LABEL,Resume log at 350?");
    Serial.println("CUSTOMBOX3,LABEL,Quit at 450?");

  // check 2 of the 3 checkboxes (first two to true, third to false)
    Serial.println("CUSTOMBOX1,SET,1");
    Serial.println("CUSTOMBOX2,SET,1");
    Serial.println("CUSTOMBOX3,SET,0");

    i=0;
 }
 
void SendData()
 {
  static boolean wait_for_response = false;
  
 // simple print out of number and millis. Output e.g.,: "DATA,DATE,TIME,TIMER,4711,13374,AUTOSCROLL_20"
  if (!wait_for_response)
   { Serial.println( (String) "DATA,DATE,TIME,TIMER," + i++ + "," + millis() + ",AUTOSCROLL_20" ); }

    // clear some cells in Excel (rectangle range from B10 to D20)
  if (i==100)
   { Serial.println("ClearRange,B,10,D,20"); }

    // do a simple beep in Excel on PC
  if (i==150)
   { Serial.println("BEEP"); }

    // read a value (in this case integer) from Excel (from a sheet by name)
  if (i==200)
   {
    if (!wait_for_response)
     {
      Serial.println("CELL,GET,FROMSHEET,Simple Data,E,4");  // ==> request value from sheet
      wait_for_response = true;
     }
     else
      {
       if (stringComplete == true)
        {
         Serial.println( (String) "Value of cell E4 is: " + inputString.toInt()); // result displayed in Excel DirectDebugWindow to double check
         stringComplete = false;
         inputString = "";
         wait_for_response = false;
        }
      }  
   }

    // check value of custombox1 on PLX DAQ in Excel and if
    // checkbox is checked then send the command to pause logging
  if (i==250)
   {
    if (!wait_for_response)
     {
      Serial.println("CUSTOMBOX1,GET");  // ==> request value from sheet
      wait_for_response = true;
     }
     else
      {
       if (stringComplete == true)
        {
         int stoplogging =  inputString.toInt();
         Serial.println( (String) "Value of stoplogging/checkbox is: " + stoplogging); // result displayed in Excel DirectDebugWindow to double check
         if(stoplogging) 
           Serial.println("PAUSELOGGING");
         stringComplete = false;
         inputString = "";
         wait_for_response = false; 
        }
      }  
   }

    // get a true random number from the computer
  if (i==300)
   {
    if (!wait_for_response)
     {
      Serial.println("GETRANDOM,-4321,12345"); // between -4321 to 12345
      wait_for_response = true;
     }
     else
      {
       if (stringComplete == true)
        {
         int rndseed = inputString.toInt();
         Serial.println( (String) "Got random value '" + rndseed + "' from Excel" );
         // Note: this information is not posted to the Excel sheet because "DATA" is missing
         // instead this information can be seen in the direct debug window
         stringComplete = false;
         inputString = "";
         wait_for_response = false;
        }
      }  
   }

    // and now resume logging
  if (i==350)
   {
    if (!wait_for_response)
     {
      Serial.println("CUSTOMBOX2,GET");
      wait_for_response = true;
     }
     else
      {
       if (stringComplete == true)
        {
         int resumelogging = inputString.toInt();
         if(resumelogging) 
           Serial.println("RESUMELOGGING");
         stringComplete = false;
         inputString = "";
         wait_for_response = false;
        }
      }  
   }

    // post to specific cells on default sheet as well as named sheet
  if (i==400)
   {
    Serial.println("CELL,SET,G10,400 test 1 string"); // default sheet active in PLX DAQ Excel
    Serial.println("CELL,SET,ONSHEET,Simple Data,G,11,400 test 2 string"); // named sheet available in PLX DAQ Excel
   }
       
  // and for forced quit of Excel with saving the file first
  if (i==123)
   {
    if (!wait_for_response)
     {
      Serial.println("CUSTOMBOX3,GET");
      wait_for_response = true;
     }
     else
      {
       if (stringComplete == true)
        {
         if (inputString.toInt())
          {
           Serial.println("SAVEWORKBOOKAS,450-Lines-File");
           Serial.println("FORCEEXCELQUIT");
          }
          else
           {
            Serial.println("No forced Excel quit requested!");
           }
         stringComplete = false;
         inputString = "";
         wait_for_response = false;
        }
      }  
   }
 
 }

const byte numChars = 32;
char receivedChars[numChars];   // an array to store the received data

boolean newData = false;

void recvWithEndMarker()
 {
    static byte ndx = 0;
    char endMarker = '\n';
    char rc;
    
    while (Serial.available() > 0 && newData == false) {
        rc = Serial.read();

        if (rc != endMarker) {
            receivedChars[ndx] = rc;
            ndx++;
            if (ndx >= numChars) {
                ndx = numChars - 1;
            }
        }
        else {
            receivedChars[ndx] = '\0'; // terminate the string
            ndx = 0;
            newData = true;
        }
    }
}

void loop()
 {
  static boolean transfer_data = false;
  int start_transfer;
  
  start_transfer = digitalRead(3);
  
  if ((start_transfer==1) && (transfer_data == false))
   {
    transfer_data = true;
    StartTransfer();
   }
   else if ((start_transfer==0) && (transfer_data == true))
    {
     transfer_data = false; 
    }

  if (transfer_data)
   {
    SendData();
   }
  recvWithEndMarker();
 }

adwsystems:
OK. Here is exactly what you wanted. The original program with your function substituted for the if (Serial.available()) statement.

Thank you. However you have not told me what happens when you tried to run it.

You don't seem to have included the necessary variable declarations. And I don't see any code in the rest of your program that responds to the variable newData.

...R

Your instructions were to include your function and replace the if statement with the function call. I did. It compiles but doesn't respond or send anything. SO there is more to it than just adding your function and calling it. After I go through and rework it to include one variable set or the other (mine or yours), then it works. You asked to use your function, I did. You asked for the broken code to be posted. I did. I have not followed you on most of your posts, so I figured you wanted the broken code to fix it yourself. After several hours work, I have the working program I posted. Why did you want to walk through this exercise?

There's another section called gigs and collaborations where you can pay someone to just fix your code without worrying about people trying to help you learn to do it on your own.

Even in Gigs and Collaboration, I tend to try to get people to learn to do it (whatever it is) themselves, so the worry that someone would want OP to learn something is not unfounded.

adwsystems:
Your instructions were to include your function and replace the if statement with the function call. I did. It compiles but doesn't respond or send anything. SO there is more to it than just adding your function and calling it.

As you had not told me that you did not understand my examples I assumed that you did and would know how to incorporate one of them.

Why did you want to walk through this exercise?

Because I wanted to ensure that you had not found a problem in my example code that I would need to fix.

...R

If you all recall, the original post was if Serial.readBytesUntil() and/or readStringUntil() was blocking or non-blocking. We have ventured three or more degrees away from the original post. Questions has been asked an some answers given. It has been quite a meandering conversation. I'm fine with it all and even revealed some additional items about the "Arduino IDE" that weren't readily available.

He obviously doesn't want to be taught anything here.

OP: why do you keep posting here if you don't want to learn anything? There's another section called gigs and collaborations where you can pay someone to just fix your code without worrying about people trying to help you learn to do it on your own.

Though I appreciate the conversation, there are 44 posts and only 4 of which are useful or provide any information or teaching. I am here to learn, but there are 40 posts that are a lot of "do this." No explanation as to how or why; ie., no teaching. (I have a pet peeve about taking classes at $$$$$$$$ per credit, only to sit for 3 hours per week and listen to the professor read from the textbook. I want to be taught, not read to.)

Robin2:

Why did you want to walk through this exercise?

Because I wanted to ensure that you had not found a problem in my example code that I would need to fix.
...R

I can't tell if it works or not as it was not a module I could use verbatim. So I guess its a no win-no lose.

I thank you all for the information on serialEvent(), Serial.readxxxxuntil(), and the "Arduino IDE". All the information that I did not see (might have been there and I didn't see it), but needed to know.

I would not mind a few folks that are using PLX-DAQ to trying the resultant and post your thoughts. NetDevil, have you seen the post? Do you have any feedback?[quote author=Delta_G

Delta_G:
If you would take a slightly different view of this, you'd see that this is what that looks like. You do your best to stick in the functions that @Robin is talking about and when it doesn't work you post it back up and someone helps you figure out what you did wrong. Then you get to learn from your mistakes, which is really the best way to learn. You get to see what parts you don't understand and you get to ask questions about things until you do understand it. And understanding IS the goal of learning right?

What you don't do is just say, "I tried that, didn't work, gimme something else". If we would just take your code, fix it, and hand it back to you all nice and neat and working, that would be like the professor just reading the answers to you. From this quote, you obviously understand how that works.

You hit the nail on the head. The person trying to "teach" needs to provide more than just the answers. To learn and understand the explanation needs to be provided. Only in four posts was anything explained, especially including the post on serialeventrun. The remainder of the posts were 'here is the answer, just do it'.

Once you (all) got me the correct information on serialEvent() (ie., that I was misled to believe it was an ISR). I moved on to the Serial.available() method as mentioned. I did say, I tried the code [mentioned[ and that it didn't work. At the same time, I spent the time figuring out how to get it to work. I bother posting the non-working sketch because I wanted to, and did, figure out how to make it work. So I skipped a few steps (including posting the non-working code originally, though did finally after repeated requests), and instead posted "AH HA!" I got it working and here is the result.

Delta_G:
Imagine a different story:

US - "Here try this"
YOU - "I tried it, but it didn't work. Here look at it. Can you show me what I did wrong?"
US - "Oh you left this little thing out. Fix it here and try again"
YOU - "OK, but it still gives this little error"
US - "Oh, because you did this little thing wrong. Here is an explanation for why it works this way and not that"
YOU - "Oh now I get it. Cool now I can parse Serial in any program I ever write."
EVERYONE TOGETHER - "Yaaaaayyyy"

Wouldn't that have been better? The only difference is a student who is trying to learn instead of being combative about what he thinks he is owed by a bunch of strangers he hasn't ever done diddly-squat for.

Sure. Too bad that wasn't the way the thread started. The student asked a question and got an explanation then was handed an answer over and over to question that was never asked without explanation of why that was the way to do it. Yes, if pushed, I push back. Explain and I will follow. As for parsing serial, I don't know how many serial parsers I have written. In this particular case, I was trying to find the shortest way to convert a working program from using blocking code to non-blocking code without breaking it too much while trying to avoid starting all over since the blocking program works with the PC program already.

I'm putting the onnus on both. It is a two way street. The student must be able to learn and the teacher must provide the information (not the answer) to learn from. 40+ posts here are the teacher providing the answer key, not the explanation. SerialInputBasics explains the code but not the basis behind it. I had to reverse engineer it to understand the basis in order to adapt it to the PLX-DAQ program. From the first post, it was a matter of how to do it the Arduino way. As we have discussed elsewhere, the issue I have is getting the background on the differences doing it the Arduino way versus coding everything from scratch. I don't need to learn to code, I need to learn to program the Arduino way. (P.S. I have eclipse downloaded, but won't have the time in the next two projects to make it the primary IDE)

Almost but not quite, missing some context, and some lines far off I'm not sure they landed in this thread.

Delta_G:
US- "Here try this way"
YOU- "I don't want to"
US- "Just try it, it will work if you do it right"
YOU- "No, I don't like that method I want this other one"
US- "But it won't work for you, why don't you at least try this"
YOU -"Well I copied it and it didn't work, poo on you why aren't you trying to help me"
US- "We are, show us what went wrong and we can help you fix it right"
YOU- "But I wanted something I could just copy in. You didn't say there'd be more work"
US- "Well you obviously did something wrong, why don't you let us help you?"
YOU- "Why would I ever show you what I tried"
US- "So we can help you understand and fix it."
YOU- "I don't want you to just explain it to me and give me the answer, I want you to just explain it to me and give me the answer"

(retaining the perspective for continuity)

This is a little more realistic.
YOU - "Is Serial.readxxxUntil() blocking"
US - "Yes. Do it this way"
YOU - "I want to use serialEvent()"
US- "Here try this way"
YOU- "I don't want to. I want to use serialEvent()"
US- "Just try it, it will work if you do it right" (won't everything)
YOU- "No, I don't like that method I want to use serialEvent()" (recall, I was expecting serialEvent() to be an ISR)
US- "Show us your code."
YOU - *Here's the code.
US - ' Why don't you "have all the serial handling code in its own function"
YOU - "Like encapsulated in serialEvent() as shown in the reference section?
US - "serialEvent is not and ISR. See here's the code."
YOU - "Oh! OK. Thanks for setting me straight. Here's my new code using Serial.available()'
US - "WHY DIDN'T YOU JUST USE THE CODE IN THE LINK?"
YOU -"Fine. I'll try it..........Well I copied it. It didn't work, poo on you. I fixed it myself."
US- "Show us what went wrong and we can help you fix it right"
YOU- "I was told what to change, copy and go. There was so much much more to it, I reverse engineered it and implemented the most basal concepts."
US- "Well you obviously did something wrong, why don't you show us the broken program and let us help you?"
YOU- (confused) "Why do you want to see the broken code after I already have it working? How about critiquing the final working code?"
US- "So we can help you understand and fix it."
YOU - "But I have already fixed it. If you insist in working through it yourself then help yourself. Here's the code from the point it was broke."

Delta_G:
If you can't see that, then you're going to have a hard time learning to code.

Learning to code? I hope I have a good grasp on programming after nearly 40 years. What I don't have a grasp on is the integration of the "Arduino way" including those items behind the scenes or not documented as we have previously discussed.

After 25 years of posting on forums, I know well how they work. I have learned to keep the questions and responses short and to the point (recent posts aside) or the responders are liable to wonder off in irrelevant directions. See post #1, one line that's it.

That's difference between responding to posts by beginners versus the experience people. The beginners want the water, the experienced people want to know how to get to the water and why they should go that way. If you only give them the water and don't give them the directions and why you should follow them, they get resistive. All the "problems" in this thread stem from that concept.

40 years experience has nothing to do with reading documentation that doesn't exist. We both agree that level of information is not there.

Also a two-way miss. I was proceeding on the explanation I previously received (serialEvent is an ISR). Your educated guess was correct, that I was under the impression that serialEvent() is an ISR. But why would I ask a question I already have an answer to? How many times have you not asked a question because you already had the answer, only to find out you had the wrong information. Once you set me straight we moved along, but I was still badgered with "USE THE CODE IN THE LINK" without any explanation why. Until I submitted, tried it, failed, and then made it work. Then I was criticized for not asking for help when the code didn't work at first and then for not posting the broken code (which was fixed before I thought to post; ie. learning on my own).

I'm not sure whom is being combative in this thread, it seems like there is plenty to share.