Code Problem
I have a controller and a robot.
The controller send the robot some variables and the robot acts accordingly.
However when the controller sends 1500 the robot displays it as 236.
What could be wrong with my code.
Code is attached.
Thank you![smile.gif](http://forums.parallax.com/images/smilies/smile.gif)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my robot using the propeller robot.tmcp.com.au
If you offer cheap PCB fabrication, perl programming or any other helpful services please email me at.
anthonybmyatt@yahoo.com.au
The controller send the robot some variables and the robot acts accordingly.
However when the controller sends 1500 the robot displays it as 236.
What could be wrong with my code.
Code is attached.
Thank you
![smile.gif](http://forums.parallax.com/images/smilies/smile.gif)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my robot using the propeller robot.tmcp.com.au
If you offer cheap PCB fabrication, perl programming or any other helpful services please email me at.
anthonybmyatt@yahoo.com.au
spin
![](/plugins/FileUpload/images/file.png)
4K
Comments
Always try to think of ways to test your code for example if you had done:
Value := 1500
tv.dec(Value)
It would have still given the wrong answer and shown it was not the data transfer at fault (or not the only fault).
Graham
You have "ID" and "Value" defined twice. Which one is supposed to be there?
I added long by accident whilst trying to fix the problem.
I never tried to compile it. As you stated it probably wouldn't.
Thank you.
Graham I don't get what you are trying to say.
Please explain it more clearly for the dumb people like me.
Thank you.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my robot using the propeller robot.tmcp.com.au
If you offer cheap PCB fabrication, perl programming or any other helpful services please email me at.
anthonybmyatt@yahoo.com.au
In line 95 you write:
Value := num.FromStr(Xb.RxData+4,num#dec) ' get and convert value from rest of string
As you have confirmed in your recent posting "Value" is a BYTE, so this assignment will truncate the transmitted data wrt modulus 256
A variable declared as a byte has only 8 bits and can only hold numbers up to 255, you try to load 1500 into value which is a byte so the 32 bit binary number gets truncated (shortend) down to 8 bit loosing several bits. Make value a long and it will probably work.
The second thing I was trying to say was that by adding
value := 1500 just before you displayed it would have shown the same error and would have proven that the comms was not the problem.
That may have made you look at the way you were displaying it or the variable itself.
Debugging code is a matter of experimentation and thinking of ways to isolate the problem and I'm trying to show you one way you might have done that for this problem. Another way of looking at debuging is modifying the code so that one element "must work" then finding out why it doesn't.
Graham
I am assuming that I would have to make Message[noparse][[/noparse]MaxStrLen] a long as well.
And change 'byteMove' to 'longMove' and 'bytefill' to 'longfill'. Is this correct, because after doing so Value becomes NULL on the robot side.
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my robot using the propeller robot.tmcp.com.au
If you offer cheap PCB fabrication, perl programming or any other helpful services please email me at.
anthonybmyatt@yahoo.com.au
It looks like when communicating you are sending a string of bytes and then using num.FromStr to convert that in to a number, it is that number, "value" that needs to be a float the string you send will still be bytes because you will send:
"1" "5" "0" "0" using FromStr becomes 1500
Try to think about how your program works rather than just try random things out.
Graham
Thank you both.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my robot using the propeller robot.tmcp.com.au
If you offer cheap PCB fabrication, perl programming or any other helpful services please email me at.
anthonybmyatt@yahoo.com.au