hi everyone,
I'm new in this forum... I have a problem with read a buffer by serialPort.
I receive a bytes buffer by serial and I need to convert some byte in char and others in int...
When I write Serial.parseInt() I can't convert only one bytes, he convert it all.
For example:
FF7F050A6D6167696B
the third byte must I convert in int, because it tell me the length of the next string(char).
Is the data that you receive terminated in any way, perhaps with a carriage return and/or linefeed ?
Does the string always start at the same place in the received data ?
How long is the string in the example you gave ? Can you please provide a second example with a different length string.
Do you have control over the format of the data being sent ?
Please post your program as it is now but read this first and follow the advice on formatting the code and using code tags
if the length is the third character you could use
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
char data[]="FF7F050A6D6167696B";
int length=data[2]-'0';
Serial.println(length);
}
prints 7
however, what if the length is 17? is it always less than 10?
Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.