[SOLVED] Low performance using readBytes()


hello,

i'm using function readbytes() follows:

code: [select]

void loop() {
 if(serial.available()>0)
 {
   bytesread = serial.readbytes(buffer,10);
   buffer[bytesread] = '\0';
   strg = buffer;
   
   if(strg.substring(0,1) == "r")  serial.println("ok");
}


i'm having low performance (it takes 1 second print "ok"). however, if change length 1 (serial.readbytes(buffer,1)) prints "ok" immediately. need high performance , length 10. do?

the readbytes() function being asked read 10 bytes. so, if there 20 in buffer, return right away 10 bytes. if, instead, there 3 bytes, function going wait time expire or 7 more bytes arrive.

what sending data? have control on sender?

there other methods use, readbytesuntil(), block until specific character arrived.

or, read data, , store in array, , deal contents of array (not string).

using substring() extract, , discard, string waste. there [] operator give specific character @ position, without overhead of constructing , destructing string. or 2 of them in snippet.

quote
i need high performance

but i'm willing piss away time using strings...


Arduino Forum > Using Arduino > Programming Questions > [SOLVED] Low performance using readBytes()


arduino

Comments

Popular posts from this blog

Connecting Raspberry Pi 2 to P10(1R)-V706 LED Dot Matrix - Raspberry Pi Forums

TypeError: <unknown> is not a numpy array - Raspberry Pi Forums

datso and removing imagetitle - Joomla! Forum - community, help and support