1

I want to parse the data of the incoming buffer from the serial read bytes, but I don't really know how to get the data out of the array and save it to different variables.

This is my code:

void setup() {
  Serial.begin(9600);
}

struct buf {
  byte FunctionCode;
  byte Length;
  byte Message;
  byte Checksum;
} data;



void loop() {
  int Length = Serial.available();
  byte Buffer[Length];
  byte IncomingData[Length];
  if (Length >= 0)
  {
    Serial.readBytes(Buffer, Length);
    data.FunctionCode = Buffer[0 - 1];
  }
}
8
  • What data? How is it formatted? Look at strtok() to do the heavy work for you.
    – Majenko
    Jun 12 at 16:19
  • @Majenko this is the incoming data: |61|191|16|0|61|191|100|23|0|0|0|0|0|0|131|2| (without the "|"), I can't use strtok because I'm not using string, they're just bytes Jun 12 at 16:20
  • A string is just bytes...
    – Majenko
    Jun 12 at 17:14
  • @Majenko Yeah, btw I fixed everything just by using a for loop and some if statements Jun 12 at 17:51
  • @alessandromrc, is it fair to say that you don't control for the format of the data being sent to you?
    – timemage
    Jun 12 at 18:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.