Pages: 1 2 [3]   Go Down
Author Topic: Array to String code behaving awkwardly  (Read 2994 times)
0 Members and 1 Guest are viewing this topic.
ਪੰਜਾਬ
Offline Offline
Edison Member
*
Karma: 12
Posts: 1601
Another year! Alone! :(
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

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

ਫ਼ਤੇਹ ਕਰੂਂ !

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26349
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

"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.

ਪੰਜਾਬ
Offline Offline
Edison Member
*
Karma: 12
Posts: 1601
Another year! Alone! :(
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

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

ਫ਼ਤੇਹ ਕਰੂਂ !

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26349
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

"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.

ਪੰਜਾਬ
Offline Offline
Edison Member
*
Karma: 12
Posts: 1601
Another year! Alone! :(
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
if(index < x) // One less than the size of the array
    {
          .....;
    }
« Last Edit: March 29, 2012, 10:53:50 am by NI$HANT » Logged

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

ਫ਼ਤੇਹ ਕਰੂਂ !

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 616
Posts: 49433
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Cracked! It's because of the Serial.flush(); it just happened to flush the buffer from what was leftover from the previous Serial entry.
So, try that on Arduino 1.0.
Logged

ਪੰਜਾਬ
Offline Offline
Edison Member
*
Karma: 12
Posts: 1601
Another year! Alone! :(
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
So, try that on Arduino 1.0.

Tried in the Serial of Arduino 1.0 working.

Sir, the code is too heavy in Arduino 1.0 its about 3842 bytes about 4kb  smiley-eek-blue and in 0022 its about 2.7kb

EDIT: 2 problems with using the Arduino 1.0:

1) Very heavy code, almost double as compared to when compiled in 0022.
2) Problems flush isn;t that working.

but then there are problems already with the Arduino 1.0 functioning like Wishield's no library works on it, even the library that was good on the 0022.
« Last Edit: March 29, 2012, 11:13:00 am by NI$HANT » Logged

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

ਫ਼ਤੇਹ ਕਰੂਂ !

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 616
Posts: 49433
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Tried in the Serial of Arduino 1.0 working.
Well, that's interesting, since the Serial.flush() function on 1.0 only affects outgoing data.

Quote
the code is too heavy in Arduino 1.0 its about 3842 bytes about 4kb and in 0022 its about 2.7kb
I'm pretty sure that the Arduino can handle the increased "weight".
Logged

ਪੰਜਾਬ
Offline Offline
Edison Member
*
Karma: 12
Posts: 1601
Another year! Alone! :(
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I posted the EDIT in my above post.

You are right,Sir, there are problem with Serial.flush() but it works , this function is so smooth in 0022 but jumbles up in 1.0 but works as compared to nothing happening previously.
 
EDIT:
Quote
I'm pretty sure that the Arduino can handle the increased "weight".

I do not like specially this trait of new Arduino 1.0 IDE , i still use a lot of ATmega8's , infact all this that im doing here im testing and working with a ATmega8, what about guys like us?
« Last Edit: March 29, 2012, 11:17:48 am by NI$HANT » Logged

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

ਫ਼ਤੇਹ ਕਰੂਂ !

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26349
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

And does flush still work when you remove the debug prints?

Flush is a sticking plaster fix.
A sticking plaster with added anthrax.
Logged

"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.

ਪੰਜਾਬ
Offline Offline
Edison Member
*
Karma: 12
Posts: 1601
Another year! Alone! :(
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Flush is a sticking plaster fix.
A sticking plaster with added anthrax.

The behaviour of elements is so irrational and haywire that controlling them all the time becomes messy in Serial, This has worked for me pretty nicely achieving what i want! but then i will manage to make it work without flushing stuff.
Logged

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

ਫ਼ਤੇਹ ਕਰੂਂ !

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26349
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The behaviour of elements is so irrational and haywire that controlling them all the time becomes messy in Serial,
I couldn't agree less.
Logged

"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.

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 616
Posts: 49433
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I couldn't agree less.
Exactly.

I am a firm believer in the use of start and end of packet markers because they work so well to avoid NI$HANT's issues, with the need for delay() or flushing anything.
Logged

ਪੰਜਾਬ
Offline Offline
Edison Member
*
Karma: 12
Posts: 1601
Another year! Alone! :(
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I am a firm believer in the use of start and end of packet markers because they work so well to avoid NI$HANT's issues,

Yes YES Sir, I also treat them needy so i incorporated the end markers, they are there in the code.
Logged

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

ਫ਼ਤੇਹ ਕਰੂਂ !

Pages: 1 2 [3]   Go Up
Jump to: