Go Down

Topic: Serial.readBytesUntil() (Read 3134 times) previous topic - next topic

adwsystems

Does the program stall and wait for Serial.readBytesUntil() to complete or is this command interrupt driven?

pert

It's a blocking function. It just sits there waiting until the terminator character is detected, the determined length has been read, or it times out. The default timeout is 1000 ms but you can change it via Serial.setTimeout():
https://www.arduino.cc/en/Reference/StreamSetTimeout

adwsystems

Thank you.

That's what I thought or was afraid of.

sterretje

#3
Aug 06, 2017, 07:23 am Last Edit: Aug 06, 2017, 07:23 am by sterretje
or was afraid of.
Why ;) You can easily work around that by modifying Robin2's example #2 in Serial Input Basics. You can even add a non-blocking timeout if needed.
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

adwsystems

Because the program was written by someone else using readBytesUntil(). The functionality I need to add needs to use serialEvent(), so I will have to rewrite the majority of the program including parsing and retesting the modified existing functionality. It is what it is.

sterretje

Although I have never used serial event, it should be straight forward; mix it with Robin's code and you should be done.

Why the need for serial event? Do you have any blocking code?
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

adwsystems

Yes. Serial.readBytesUntil()

There will be "commands" coming in the serial port at any random time therefore Serial.readBytesUntil() cannot be used.

sterretje

No, that's not what I meant. Any others (e.g. a for loop that takes ages due to complex calculations)? If not, I have great difficulty understanding why you need serial event unless the current code also uses it and it's the easiest adjustment.
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

adwsystems

Let me ask this:

What happens if I add one Serial.readBytesUntil() to the program to wait for serial input; not knowing when the input will be received?

Robin2

Let me ask this:

What happens if I add one Serial.readBytesUntil() to the program to wait for serial input; not knowing when the input will be received?
It will wait until its timeout expires for the "until" character and then it will return. I think the default timeout is 1 second.


You have received a lot of advice that you do not seem to have been able to make use of so you need to post your complete program so we can understand what you are having a problem with.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

sterretje

It will wait till the requested character is received. If it's already received, there will not be a delay. If the requested character is not received within the given time, it will result in corrupted data and a delay.

It's all the things that you don't want but I guess that you already figured that out.
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

adwsystems

#11
Aug 06, 2017, 03:30 pm Last Edit: Aug 06, 2017, 03:31 pm by adwsystems
It's all the things that you don't want but I guess that you already figured that out.
I have other things to do during the timeout period.

You have received a lot of advice that you do not seem to have been able to make use of so you need to post your complete program so we can understand what you are having a problem with.

...R
Actually I haven't received any "advice...to make use of". I have received valuable information on the operation of the Serial.readBytesUntil() function.

At this time, the program is still a work in progress. I'm working to convert the PLX-DAQ sample program from Serial.readBytesUntil() to serialEvent(), to add it in to an existing program. Using Serial.readBytesUntil() to wait for commands via the serial port will have a large detrimental impact on the execution of the current program.

sterretje

Actually I haven't received any "advice...to make use of".
Maybe read reply #3 again.
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

adwsystems

#13
Aug 06, 2017, 03:54 pm Last Edit: Aug 06, 2017, 03:55 pm by adwsystems
Maybe read reply #3 again.
OK. Read it again. Still  haven't received any "advice...to make use of". Reply #3 is almost irrelevant at Robin2 doesn't like serialEvent() and provides no examples to that end.

Thanks for the link though. I do like read other solutions, even if irrelevant, as they may provide an idea to morph and use myself.

Robin2

OK. Read it again. Still  haven't received any "advice...to make use of". Reply #3 is almost irrelevant at Robin2 doesn't like serialEvent() and provides no examples to that end.
This sounds like a problem for every solution.

Post your complete program and then maybe someone can suggest something useful.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up