Strings, Integers, and Decimals - What am I missing?
sethen320
Posts: 7
I have an application (Hummingbird_Ctrlr.spin) which is supposed to pulse 4 pins (which will drive pumps) based on characteristics received via RS-232. The characteristics are "off time" and "on time". Both are in milliseconds. Using the attached code I can send the command to change the speed to the propeller and it is able to echo back what I sent with no problems, but it does not have an effect on the output. It seems as if it's not reading the number correctly. If anyone has any clues as to what I may be doing wrong I would really appreciate it. I believe that somewhere I am not handling the conversion from string to integer correctly. I have read the documentation, but I can't find my problem.
ASCII0_STREngine_1.spinExtended_FDSerial.spinFullDuplexSerial.spinHummingbird_Ctrlr_0.spin
ASCII0_STREngine_1.spinExtended_FDSerial.spinFullDuplexSerial.spinHummingbird_Ctrlr_0.spin
Comments
I'd suggest you add statements to display the interger values after the converstions.
For example:
I had to look up the next statement. I haven't ever used it in one of my Spin programs.
I would have used elseif for each condition check (of the same variable) after the first if statemtment.
Using next at the end of a loop isn't necessary.
I plugged in your debugging statements and guess what I realized...I was using the old protocol I had written before, not the new one I put in when I re-wrote it. I was issuing the wrong commands...DUH! I feel like an idiot now. I will be putting in some error handlers.
Thank you again.
Bugs are usually easy to fix once the problem is found.
I sometimes have code that seems to be 90% debug statements. If I add enough, I usually find the problem (and then slap my forehead since it should have been obvious in the first place).
You could indent the NEXTs inside the IF command, but better delete them all, they are not necessary, the loop works without them (the only effect is that it speeds up the loop a bit, but speed does anyway not matter here).
Andy
I didn't catch the indentation of the next statements. Your right. I just assumed they were indented past the previous "if" statement. The "next" statemets looked like they belong were they are because of our experience with C (and I think some forms of BASIC).
If "elseif" statements were used, then subsequent "if" elvaluations wouldn't need to be made also saving time. I assume an unevaluted "elseif" is faster than evaluating an 'if" statement.
Andy
I really appreciate all of the suggestions. This is better learning than the tutorials in the help file.