Is there any downside in using the readBytesUntil() of the Stream base class?
/* Handle TCP/IP communication. */
EthernetClient client = server.available();
client.setTimeout(1000); // 1 second timeout
/* client.available() will be only evaluated if the first is OK*/
if ( (client) && (client.available()) > 5)
{
// We waited for a 5-byte command:
// 1 byte: Which external instrument...
// 1 byte: On/Off
// 2 bytes: setpoint
byte buf[5] = { 0,0,0,0,0 };
char term = '\n';
for (int i = 0; i < 5; ++i)
{
client.readBytesUntil('\n', buf, 5);
}
// Much more code is here...
Ethernet.maintain();
}
The reason why I am asking: That function is not included in the ethernet client documentation, and everybody seems to use the Read() function, which is of course much more work if there is a readBytesuntil method...
That function is not included in the ethernet client documentation
I agree that the inter-linkage of the Reference is rather bad but in the Stream Reference the function is documented and it also informs that the EthernetClient class uses that as a base.
indeed you discovered a bug in my code: I shouldn't be calling it 5x. I used Read() before, and then I would have needed to call it 5x. Thanks a lot.
I can't see that calling read() in the loop is "much more work".
I need to do that a lot, so using readBytesUntil(...) is quite useful, or I would have written my very own readBytesUntil method.
I wouldn't say that the reference is bad: I am just new to the Arduino world and therefore I was interested if there is a relevant reason not to use readBytesUntil. Maybe it doesn't work for ethernet or so.