Go Down

Topic: Commands (Read 4913 times) previous topic - next topic

zoomkat


Quote
Code: [Select]
    if (readString == "off") {


This is still fundamentally flawed. Serial comms is a streaming protocol. You might get "of" and then "f" neither of which match "off".

You need to have a way of knowing when the input is finished (traditionally a linefeed or carriage-return) and then see what you got before that.


The slight delay in the code slows the retreving of bytes from the input buffer such that there is usually enough time for the next byte to arrive. Did you get "of" and then "f" neither of which match "off" when you tried the code? If so, increase the delay. The test code is based on the premis that the person is typing the commands in the serial monitor text box and sending the commands such that a delimiter is not needed. My test code is for use with the serial monitor so people can have something that usually *works* to start with, instead of "code snippits" and general jawbone support. PaulS always has a whine about my test code, but his apparent anal-retentive issues (potty trained on an electric chair perhaps) have prevented him from ever posting any actual working code (I haven't found any). The old saying "those that can, do. those that can't whine about those that can" is popular with some in the forum. I usually say if you have ***complete working*** code, post it. Other wise...    ;) 
Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0

PoLoMoTo

Well first someone said that
Code: [Select]
if(Serial.read == "off") is fundamentally, therefore implying that it is in my code and second I don't understand why everyone is stuck on the "off" part my code never even gets past "digital"..... Also someone suggested using "strcmp" which I have yet to try since I don't have mt Arduino handy right now.

AWOL

I think that somebody was you.
"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.
I speak for myself, not Arduino.

PoLoMoTo

No actually it was in zoomkat's post of sample code which has nothing to do with my code.

AWOL

#19
Nov 10, 2011, 08:02 pm Last Edit: Nov 10, 2011, 08:41 pm by AWOL Reason: 1
No, I think zoomkat is far too experienced to compare a pointer to an object's method to a constant C string.
You're making this up.
"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.
I speak for myself, not Arduino.

PoLoMoTo

#20
Nov 10, 2011, 08:04 pm Last Edit: Nov 10, 2011, 08:07 pm by AWOL Reason: 1
(Personal insult removed) just go back and read the freaking thing!

PoLoMoTo

Thanks to Graynomad's suggestion my commands are working so I can continue developing it but because of AWOL this topic stayed on top of the list most of the day, taking the attention away from others that needed assistance.

zoomkat


Thanks to Graynomad's suggestion my commands are working so I can continue developing it but because of AWOL this topic stayed on top of the list most of the day, taking the attention away from others that needed assistance.


Don't sell yourself short, everybody loves a forum train wreck/meltdown.  :)
Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0

nickgammon


Well first someone said that
Code: [Select]
if(Serial.read == "off") is fundamentally, therefore implying that it is in my code and second I don't understand why everyone is stuck on the "off" part my code never even gets past "digital"...


<wakes up to forum thread running at full steam>

The someone that initially used the words "fundamentally flawed" was me. However the code I quoted was:

Code: [Select]
if (readString == "off") {

The code I quoted was zoomkat's, not yours PoLoMoTo. However I never said that PoLoMoTo had written that line.

We seemed to have strayed from my point, amongst all the bitterness and recriminations.

Let's go back to the original post:

Quote
Code: [Select]
if(Serial.available() > 0) {
    delay(100);
    for(int i = 0;Serial.available();i++) {
      incomeWord = Serial.read();
    }
    Serial.print(incomeWord);
    if(incomeWord == "digital") {



My point was that with serial comms you don't necessarily get "nothing" or "everything". Your test for  "Serial.available() > 0" only guarantees that you get a single byte (maybe more, but you are testing for more than zero).

So, a few lines further on, to test if you get "digital" is the flawed part. You might get "d" or "di" or "dig" and so on. You might, if the timing is exactly right, actually get "digital".
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

PoLoMoTo

Yea sorry wasn't trying to blame you, and yes that is why I put the delay of 100 in there because earlier I had it print "incomeWord" and it only gave half.

zoomkat

Quote
The someone that initially used the words "fundamentally flawed" was me. However the code I quoted was:


Code:
if (readString == "off") {
The code I quoted was zoomkat's, not yours PoLoMoTo. However I never said that PoLoMoTo had written that line.


I'm not sure that the line you quote is fundimentally flawed. I hope that the flaw you are talking about is the string capture method I posted might not work as expected if there is not some delay between the sending of the strings.
Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0

PoLoMoTo

I think we're getting off topic, also (getting further off topic XD) why was my earlier post "Yea, they are entertaining." removed?

zoomkat

Quote
I think we're getting off topic, also (getting further off topic ) why was my earlier post "Yea, they are entertaining." removed?


Hmmm..., I thought you removed it. It didn't forum politically incorrect material.
Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0

nickgammon


I hope that the flaw you are talking about is the string capture method I posted might not work as expected if there is not some delay between the sending of the strings.


Of course. No insult intended to anyone.

This issue seems to come up quite frequently - if you aren't used to serial comms you expect to get "all or nothing". I never intended to imply that you would make such a mistake, zoomkat.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

zoomkat

Quote
This issue seems to come up quite frequently - if you aren't used to serial comms you expect to get "all or nothing". I never intended to imply that you would make such a mistake, zoomkat.


I've found that people starting out with no working code similar to what they want aren't helped as much by code snippets and suggestions as they are by starting with some similar working code. I think that is why example code is supplied with the IDE.
Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0

Go Up