Hello
Im using arduino serial port 1 to communicate with serial 232 device (using max232 chip) i send to the device text command and getting the temp on the device
The device has some issues with buffer and to overcome the issue i need to send a dummy command so it will clean the buffer and than i send again the temp command ...so far so good the code works perfect and i reciving valid data parsit to float and life is good however i want to be able to reset the value if there is no device connected
When im shutoff the device im stack at " case 0" and its look like after the serial1.print command done everything freez if there is no port alive
My Q is how can i detect if the communication was stop ??
char myByte;
int str;
float Fstr;
int c =0;
String inString = "";
void setup() {
// initialize both serial ports:
Serial.begin(38400);
Serial1.begin(38400);
}
void loop() {
switch (c)
{
case 0:
Serial1.print("read-temp .s\r"); // sending request to device for temp
delay(10);
c = 1;
case 1:
if (Serial1.available()>0) {
int inChar = Serial1.read(); // reciving the data and parsing it to get clean temp
if (isDigit(inChar))
{
inString += (char)inChar;
}
if (inChar == '\n') {
inString.remove(3);
str = inString.toInt();
Fstr =float(str)/10; // this is the value i want to reset if there no communication
Serial.println (Fstr,1);
inString = "";
}
break;
}
else
c=2;
case 2:
Serial1.print("unknown command \r"); // after every command need to send false data and ignore the return value before i send again the temp command
delay(10);
c =3;
case 3:
if (Serial1.available()>0) {
myByte = Serial1.read(); ignore ther return data
break;
}
else
delay(10);
c=0; // return to another round to get fresh temp value
}
// Serial.println (Fstr); if i print heare the value and turn off the device i will get the last result was update and i cant find way to reset it ....
}