Shop OBEX P1 Docs P2 Docs Learn Events
Code Problem — Parallax Forums

Code Problem

computer guycomputer guy Posts: 1,113
edited 2007-09-20 07:33 in Propeller 1
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

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
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

Comments

  • Graham StablerGraham Stabler Posts: 2,510
    edited 2007-09-17 22:06
    Robot displays value and you defined this as a byte which is only 8 bits, the maximum value being 255.

    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
  • Mark BramwellMark Bramwell Posts: 56
    edited 2007-09-18 02:01
    I am surprised it compiled.

    VAR
    
            long      range, ID, Value
            word      mode
            byte  RSSI, Message[noparse][[/noparse]MaxStrLen], ID, Value 
    
    
    



    You have "ID" and "Value" defined twice. Which one is supposed to be there?
  • computer guycomputer guy Posts: 1,113
    edited 2007-09-18 06:36
    byte is the correct one.
    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. smile.gif

    Graham I don't get what you are trying to say.
    Please explain it more clearly for the dumb people like me.

    Thank you. 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
  • deSilvadeSilva Posts: 2,967
    edited 2007-09-18 06:55
    What Graham said was:

    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
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2007-09-18 09:11
    What deSilva was trying to say that I was trying to say is:

    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
  • computer guycomputer guy Posts: 1,113
    edited 2007-09-18 12:40
    Ah I get it now thank you.
    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 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
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2007-09-18 13:11
    You have now defined the value as a long and a byte.

    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
  • computer guycomputer guy Posts: 1,113
    edited 2007-09-20 07:33
    All works well.

    Thank you both. 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
Sign In or Register to comment.