Hello,
I am almost there with the code but last part fails.
I switch the Arduino on and it reads data from the eeprom. I switch on VB program and by USB cable it copies data to some text boxes from Arduino to the program.
Then I send by button command from VB6 a single string of 7 variables to the Arduino.
Arduino receives the data but not all data now changes correctly.
VB code
Private Sub cmdSendDataToController_Click()
strOutput = "10,2,3,4,5,6,11:"
MSComm1.Output = strOutput
End Sub
Arduino code
const int NUMBER_OF_FIELDS = 7; // how many comma separated fields we expect
int fieldIndex = 0; // the current field being received
int values[NUMBER_OF_FIELDS]; // array holding values for all the fields
void loop
if( Serial.available())
{
char ch = Serial.read();
if(ch >= '0' && ch <= '9') // is this an ascii digit between 0 and 9?
{
// yes, accumulate the value
values[fieldIndex] = (values[fieldIndex] * 10) + (ch - '0');
}
else if (ch == ',') // comma is our separator, so move on to the next field
{
if(fieldIndex < NUMBER_OF_FIELDS-1)
fieldIndex++; // increment field index
}
else
{
// any character not a digit or comma ends the acquisition of fields
for(int i=0; i <= fieldIndex; i++)
{
deadbandxValue = (values[0]);
//brakeregenValue = (values[1]);
//regbrakeState = (values[2]);
//regenhyValue = (values[3]);
//brakespeedValue = (values[4]);
//brakespeedState = (values[5]);
modelNumber = (values[6]);
values[i] = 0; // set the values to zero, ready for the next message
}
fieldIndex = 0; // ready to start over
}
}
deadbandxValue = (values[0]); parses 0 back to the vb program which should be 10! modelNumber = (values[6]); correctly parses 11 back to the vb program.
Is there something I overlook as the array spliting is working partialy? for some reason it only reads the last variable in the array.
Paco