Serial Coms with VB

Hi I have written a VB program that sends a string to the arduino in the following format <1,2,0,0,0,1> and a sketch to read and parse this string into values of Option, ServoNo, Option_Val, Write, High_Low_End_Point, Spare and Option2 in that order. The sketch works great. when I type the above string into the serial monitor I get the following out of it. Note the output is from a third party serial monitor not the included serial monitor, however the string is entered in the arduino serial monitor.

<1,2,0,0,0,1> - Raw data = 3c 31 2c 32 2c 30 2c 30 2c 30 2c 31 3e

Option :1, Servo No : 2, Option Val : 0, Write : 0, High/Low : 0, Spare : 0, Option 2 : 1
1,Currently
Currently Air Operated

however if I use the VB program to send the same string <1,2,0,0,0,1> all I get through the serial monitor is bellow

<1,2,0,0,0,1> - Raw data = 3c 31 2c 32 2c 30 2c 30 2c 30 2c 31 3e

No return from the arduino even though both strings are the same and both come through the serial monitor looking the same.

Any ideas???

condensed VB code

Cal_Area = 1
Servo = 2 
Val1 = 0
Write = 0
Spare = 0
Option2 = 1

Serial_Write = "<" & Cal_Area & "," & Servo & "," & Val1 & "," & Write & "," & Spare & "," & Option2 & ">"
SerialPort1.Write(Serial_Write)

Arduino code extract

//=============================================================================================
  //Read Serial String
boolean getSerialString(){
  static byte dataBufferIndex = 0;
  while(Serial.available()>0){
    char incomingbyte = Serial.read();
      
    if(storeString){
      //Let's check our index here, and abort if we're outside our buffer size
      //We use our define here so our buffer size can be easily modified
      if(dataBufferIndex==DATABUFFERSIZE){
        //Oops, our index is pointing to an array element outside our buffer.
        dataBufferIndex = 0;
        break;
      }
            
      if(incomingbyte==endChar){
        dataBuffer[dataBufferIndex] = 0; //null terminate the C string
        //Our data string is complete.  return true
        return true;
      }
      else{
        dataBuffer[dataBufferIndex++] = incomingbyte;
        dataBuffer[dataBufferIndex] = 0; //null terminate the C string
      }
    }
                
    if(incomingbyte==startChar){
      dataBufferIndex = 0;  //Initialize our dataBufferIndex variable
      storeString = true;
    }       
    else{
    }
  }//End of while loop
    
    //We've read in all the available Serial data, and don't have a valid string yet, so return false
    return false;
}//End of boolean getSerialString
//===================================================================================================================
  //Parse Serial String
void ParseSerialString(){
  
  if(getSerialString()){  //getSerialString == true.  String available for parsing
     
     valPosition = strtok (dataBuffer, delimiters);          
    
     for(int i = 0; i < 6; i++){
      Serial_Data[i] = atoi(valPosition);        
      valPosition = strtok(NULL, delimiters);
     } 
    
     Option = Serial_Data[0];
     ServoNo = Serial_Data[1];
     Option_Val = Serial_Data[2];
     Write = Serial_Data[3];
     High_Low_End_Point = Serial_Data[4];
     Option2 = Serial_Data[5];
  }
}//End of void SerialString
//================================================================================================
if(First_Run == true && Option2 == 1){     //Only allow this set of steps to happen once at start
   
 Serial.print("Option :");
 Serial.print(Option);
 Serial.print(", Servo No :");
 Serial.print(ServoNo);
 Serial.print(", Option Val :");
 Serial.print(Option_Val);
 Serial.print(", Write :");
 Serial.print(Write);
 Serial.print(", High/Low :");
 Serial.print(High_Low_End_Point);
 Serial.print(", Option 2 :");
 Serial.println(Option2);
 Serial.println("VB");
   
    CallibrationServo.detach();              //Detach old Callibration Servo
    CallibrationServo.attach(Call_Servo);    //Attach to new callibration Servo

    if(Option == 1 || Option == 2){          //End limits
      ValC = EEPROM.read(ValE);              //Read EEPROM for current callibration area
      Serial.println("1,Currently");        //Send text box 1 info to vb program
      Serial.println("2," + ValC);           //Send ValC - Current EEPROM value to VB program a int from 0 to 90
      CallibrationServo.write(ValC);         //Move servo to current position set in EEPROM
    }
    //Foward/Reverse
    else if(Option == 3){  
      ValC = EEPROM.read(ValE);
      if(ValC == 0) Val_C = "Currently Foward";
      else if (ValC == 1) Val_C = "Currently Reversed"; 
      Serial.println("1," + servo + Val_C);
    }
    //Air opp/Servo opp 
    else if(Option == 5){                                       
      ValC = EEPROM.read(ValE);
      if(ValC == 0) Val_C = "Currently Air Opperated";
      else if (ValC == 1) Val_C = "Currently Servo Opperated"; 
      Serial.println("1," + servo + Val_C);
    }
    //Enable/Disable
    else if(Option == 6){                               
      ValC = EEPROM.read(ValE);
      if(ValC == 0) Val_C = "Currently Enabled";
      else if (ValC == 1) Val_C = "Currently Disabled"; 
      Serial.println("1," + servo + Val_C);
    }
    else if(Option == 4 ||Option == 7 || Option == 8){  //timed vals, speed, delay, etc
      Val_a = EEPROM.read(ValE_A);                      //8 bit hvalue
      Val_b = EEPROM.read(ValE_B);                      //8 bit lvalue
        ValC = word(Val_a, Val_b);                      //Set 16 bit value from 2 8 bit values
        Serial.println(servo + "1,Currently");        //Sent text box 1 info to vb program
        Serial.println("2," + ValC);                    //Send ValC - Current EEPROM value to VB program (2 as will be displayed in the text box 2 - Current value)
    }
    First_Run = false;                                  //Prevent from happening again
    Option2 = 0;
  }

Is the initialization of the COM port in the VB correct? (speed, bits, handshake, ...)

here is the initialization of the com port in the vb program.

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        myPort = IO.Ports.SerialPort.GetPortNames()
        ComPortComboBox.Items.AddRange(myPort)
        ComPortComboBox.Text = ComPortComboBox.Items.Item(0)
        BaudRateComboBox.Text = "9600"

    End Sub

    Private Sub OpenComPort_Click(sender As Object, e As EventArgs) Handles OpenComPort.Click
        Try
            SerialPort1.PortName = ComPortComboBox.Text
            SerialPort1.BaudRate = BaudRateComboBox.Text
            SerialPort1.Open()
        Catch ex As Exception
            'Unable to open the SerialPort - prompt the user
            MsgBox("Unable to Open SerialPort", MsgBoxStyle.Critical)
        End Try

    End Sub

I havnt addressed the handshake and bits. Not sure if I had to. I have done a simple test VB program prior to this that just turned on and off LED 13 depending on what the VB program sent. However it was only sending one value either a 1 or a 0. If I do need to setup the Handshake etc what values should I use?

Thanx

      if(dataBufferIndex==DATABUFFERSIZE){
      if(incomingbyte==endChar){

Isyourspacekeybroken?

    else{
    }

Why?

void ParseSerialString(){
  
  if(getSerialString()){  //getSerialString == true.  String available for parsing

This order is nonsense. You have to have something to parse, first.

if(First_Run == true && Option2 == 1){     //Only allow this set of steps to happen once at start

I’d suggest that you head over to http://snippets-r-us.com. Maybe they can help you. Here, we need to see ALL of your code.

Isyourspacekeybroken?

Yes it must have been for those 2 lines of code. Most other line has spaces in it.....

This order is nonsense. You have to have something to parse, first.

if you follow the code getSerialString = true when there is data there to parse.... If there was no data to parse then it would not work from the arduino serial monitor either (Which it does) would it.. boolean getSerialString(){

Code: else{ } Why?

This code has been modified multiple times there use to be something there however now there is not. Sorry if I upset you by not deleting the whole else statement and not just what was in it....

I'd suggest that you head over to http://snippets-r-us.com. Maybe they can help you. Here, we need to see ALL of your code.

If you want all my code it is currently around 42kb. I doubt anyone has the time to look over all of that for me!!!!! and nore do I need them to. The area that is concerned is the serial coms section which I have included and that If statement of which I have included the whole If statement! Oh just so you dont have to assume I have set the baud rate to 9600 and initiated the Serial port in the Sketch. Other than that what info do you want? Let me know and I will put it up.

if you follow the code getSerialString = true when there is data there to parse.... If there was no data to parse then it would not work from the arduino serial monitor either (Which it does) would it..

When ParseSerialString is called, there may not be any serial data to parse. There is nothing in the name ParseSerialString that indicates that it is going to get the serial data to parse. In fact, getSerialString should call ParseSerialString, not the other way around.

And why does one function start with a lower case letter and the other one start with an upper case letter. Adopting a style, and sticking to it, is important.

If you want all my code it is currently around 42kb

If you want help, post it. On the other hand, what the application does with the serial data after getting and parsing it is irrelevant, so you can DELETE that code.