Splitting Data from Serial, Reading it, and Producing new Data(VB)

Hello Everyone!

Ive got a really complex question, and Im really hoping someone will be able to give a helping hand.

Im sending Data from VB to the Arduino (Due). This isnt the problem. The information will be sent as a string. For example "DDL3(0,0,0)(0,0,0)(0,0,0)". However each value has a meaning and can differ how the data will be finally presented.

The first three characters have no meaning but still need to be presented as they are. However the 4th character, in this case the "3" will affect the rest of the data. For example if the number was:

2, it would be presented like this (0,0)(0,0)(0,0)
4, it would be presented like this (0,0,0,0)(0,0,0,0)(0,0,0,0)

Below is what I have so far but Im not too sure if its anygood. Im a beginner so dont hate:) haha.

Any help is valued, THANK YOU!

String content = "";

char character;

int Counter, DataCounter;

 

 

void loop()

{

 

       if (Serial.available() <= 0) {

      

       }

       while(Serial.available()) {

              character = Serial.read();

              if(character == ','){

                    

                     Serial.println(content);

                     Serial.println(Counter);

                     Serial.println(DataCounter);

                     content="";

                     Counter=0;

                     DataCounter++;

              }

              else

              {

                     content.concat(character);

                     Counter++;

              }

             

       }

 

      

 

}

I can't make sense of your code - what is it supposed to do? and what does it actually do ?

I suggest that a better approach is to receive all the data and then check the 4th char to decide how to proceess it.

The second example in serial input basics should be able to receive the data. If you can change the data format so there is a start- and end-marker it would be more reliable. For example <DDL3(0,0,0)(0,0,0)(0,0,0)> The third example works like that.

With either example, after you have received the data you can have different functions to parse the different structures. For example

  if (receivedChars[3] == '2') {
     parseType2();
  }
  else if (receivedChars[3] == '3') {
     parseType3();
  }
  else {
    parseType4();
  }

...R

Thanks Robin!

Ill give it a go and see if it works out.