Robin2 and J-M-L. I was reading yours posts and really was very helpfull for me.
I modified a little J-M-L example, sending_several_lines_of_characters.ino, to receive some commands from a VB.Net program.
I started changing your code
const char * labelsOfInterest[] = {"V", "I", "VPV", "PPV", "CS"};
const unsigned int maxLabelsOfInterest = sizeof(labelsOfInterest) / sizeof(*labelsOfInterest);
changed to
const char *cmds[] = {"*?", "f", "f?", "v", "v?", "i", "i?"};
const unsigned int maxCmds = sizeof(cmds) / sizeof(*cmds);
recvWithEndMarker() is same as your example but I changed a little your void parseNewData() to
void parseCalibrationData()
{
const char *delim = " ";
char *item;
boolean cmdFound;
int cmdIndex = 0;
item = strtok (receivedChars, delim);
cmdFound = false;
Serial.println(item); // to show cmd received in to VB.NET program
for (int i = 0; i < maxCmds; ++i)
{
if (!strcmp(cmds[i], item))
{
// {"*?", "f", "f?", "v", "v?", "i", "i?"}
cmdFound = true;
cmdIndex = i;
break; // ends the for loop as we found a cmd
} //ends if !strcmp(cmds[i], item)
}
if (cmdFound == true)
{
switch (cmdIndex)
{
case 0:
Serial.println("Calibration Software");
break;
case 1:
item = strtok(NULL, delim);
if (item != NULL)
{
frequency = atol(item);
}
break;
case 2:
item = strtok(NULL, delim);
if (item == NULL)
{
Serial.println(frequency);
}
break;
case 3:
item = strtok(NULL, delim);
if (item != NULL)
{
voltage = atol(item);
}
break;
case 4:
item = strtok(NULL, delim);
if (item == NULL)
{
Serial.println(voltage);
}
break;
case 5:
item = strtok(NULL, delim);
if (item != NULL)
{
fTotalCurrent = atol(item);
}
break;
case 6:
item = strtok(NULL, delim);
if (item == NULL)
{
Serial.println(fTotalCurrent/1000,3);
}
break;
break;
} // ends switch
} // ends if cmdFound = true
}
When I open monitor on Arduino 1.65 IDE or Serial COM11, in my case, on Atmel Studio 6.2.1563 Service Pack 2 and send any command, f? for example, everything works fine, Monitor reads f? 0. I close and open monitor several times and always works fine.
I close monitor or Serial Com11 and run my program in VB.Net, connect Serial COM11 and I send f? first time, I get ððððf? without frecuency value because if (!strcmp(cmds, item)) fails.
If I resend again same command, f?, I get f? 0.
I used Advanced USB Port Monitor 2.7.1.629 to spy USB communication and you can see I send f? + vblf (66 3F 0A) to arduino and I received ððððf? (F0 F0 F0 F0 66 3F 0D 0A) first time and I resend again f? + vblf (66 3F 0A) and I receive f? 0 (66 3F 0D 0A 30 0D 0A) that is wright answer
---------------
[2002] 20171117231914.991 (TX)
66 3F 0A (f?. )
---------------
[1983] 20171117231914.994 (RX)
F0 F0 F0 F0 66 3F 0D 0A (ððððf?.. )
---------------
Transfer buffer length: 0
---------------
[2005] 20171117231934.878 (TX)
66 3F 0A (f?. )
---------------
[2004] 20171117231934.883 (RX)
66 3F 0D 0A 30 0D 0A (f?..0.. )
---------------
Transfer buffer length: 0
How I can fix that?
I really appreciate your help