Go Down

Topic: Array to String code behaving awkwardly (Read 3 times) previous topic - next topic

NI$HANT

Quote
My code doesn't waste resources wrapping the char array in  String objects. Yours does.


Sir, Im not wasting resources i did that to print stats on Serial monitor.

Quote
My code properly resets the buffer when a packet is received. Yours doesn't.


OK sir but where?

Quote
My code actually looks for SOP and EOP


Ok
"Real Men can Accomplish  Anything"
-  Website  
- skype : nishants5  

????? ???? !

AWOL

Quote
Sir, Im not wasting resources i did that to print stats on Serial monitor.

Taking a perfectly acceptable C string (that could be compared against a constant string with a simple "strcmp"), and converting it to a String object is wasteful, in my book.
YMMV.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

NI$HANT

I got it is simply appending the values so when first time there is a ON its only a ON in the inData but the second time when OFF is written then in the variable not only ON is there but also OFF so IF condition evaluates false.

first time putting ON okay its

ON
( as inData has ON only)

second time when one puts OFF
its not only OFF but it is:

ON
OFF

"Real Men can Accomplish  Anything"
-  Website  
- skype : nishants5  

????? ???? !

AWOL

Quote
I got it

Not quite.
You reset the buffer as soon as you see "on" so "on" is no longer in the buffer, but then you read the '<'.
Since you never test for this, it stays in the buffer, no matter what else you read in.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

NI$HANT

#34
Mar 29, 2012, 05:21 pm Last Edit: Mar 29, 2012, 05:53 pm by NI$HANT Reason: 1
Cracked! It's because of the Serial.flush(); it just happened to flush the buffer from what was leftover from the previous Serial entry.

Quote
if(Comp("on")==0){
   Serial.write("Motor 1 -> Online\n");
   for(int i=0;i<19;i++){
   inData=0;
   }
   index=0;
   Serial.flush();
 }
 if(Comp("off")==0){
   Serial.write("Motor 1 -> Offline\n");
    for(int i=0;i<19;i++){
   inData=0;
   }
   index=0;
   Serial.flush();
 }


very minimal changes nothing changed except the ARRAY elements/width and removing the following from code:

Code: [Select]
if(index < x) // One less than the size of the array
   {
         .....;
   }
"Real Men can Accomplish  Anything"
-  Website  
- skype : nishants5  

????? ???? !

Go Up