Hello,
I have used the code shown below in the code snippit on several projects for when I want to change variable values, control states, etc from a PC program.
For example, from the PC based user interface I can send over serial ---> $Data02, 300 and this will set the variable "PumpTime" to 300.
As I've mentioned I've used this code on several projects successfully with Arduino Mega boards.
Recently I started another project with a Teensy 3.2 and wanted to have a PC based interface using this same method but I don't get the same results out of this code on the Teensy 3.2 it seems.
Two things 1) TempString = String(strtok(SerialLine, ",")); results in the variable TempString being empty and 2) if (TempString != NULL) gives me the error "ambiguous overload for 'operator!=' (operand types are 'String' and 'int')"
Does StrTok need to be used in a different way with Teensy?
I have used the code shown below in the code snippit on several projects for when I want to change variable values, control states, etc from a PC program.
For example, from the PC based user interface I can send over serial ---> $Data02, 300 and this will set the variable "PumpTime" to 300.
As I've mentioned I've used this code on several projects successfully with Arduino Mega boards.
Recently I started another project with a Teensy 3.2 and wanted to have a PC based interface using this same method but I don't get the same results out of this code on the Teensy 3.2 it seems.
Two things 1) TempString = String(strtok(SerialLine, ",")); results in the variable TempString being empty and 2) if (TempString != NULL) gives me the error "ambiguous overload for 'operator!=' (operand types are 'String' and 'int')"
Does StrTok need to be used in a different way with Teensy?
Code:
char SerialLine [64];
char SerialByte;
int cnt = 0;
String TempString = "";
void MySerialReader () {
while (Serial.available()) {
if (Serial.available() > 0) {
SerialByte= Serial.read();
SerialLine[cnt++] = char(SerialByte);
}
}
TempString = String(strtok(SerialLine, ","));
if (TempString == "$Data02") {
TempString = String(strtok(NULL, ","));
if (TempString != NULL) {
PumpTime = TempString.toFloat();
}
}
if (TempString == "$Data03") {
TempString = String(strtok(NULL, ","));
if (TempString != NULL) {
SetTemp = TempString.toFloat();
}
}
if (TempString == "$Data04") {
TempString = String(strtok(NULL, ","));
if (TempString != NULL) {
PowerON = TempString.toFloat();
}
}
if (TempString == "$Data05") {
TempString = String(strtok(NULL, ","));
if (TempString != NULL) {
LightTime = TempString.toFloat();
}
}
if (TempString == "$Data06") {
TempString = String(strtok(NULL, ","));
if (TempString != NULL) {
TimeZoneShift = TempString.toFloat();
}
}
if (TempString == "$Data07") {
TempString = String(strtok(NULL, ","));
if (TempString != NULL) {
PumpSpeed = TempString.toFloat();
}
}
memset(SerialLine, 0, sizeof(SerialLine));
cnt = 0;
}