Shop OBEX P1 Docs P2 Docs Learn Events
Variable and array WITH serial com problem — Parallax Forums

Variable and array WITH serial com problem

grasshoppergrasshopper Posts: 438
edited 2008-05-15 16:06 in Propeller 1
I am having a problem taking a few numbers from an array and adding them together. Once added i wanted to send back the number that should now be a variable. Problem is the number sent back is not the correct number.

If i send the command through the serial port "[noparse][[/noparse]TT S 30]" I get the correct data i just can not add The_STring [noparse][[/noparse] 9 ] and The_ STring [noparse][[/noparse] 10 ] which are 3 and 0 in "[noparse][[/noparse]TT S 30]"


IF (The_STring [noparse][[/noparse] 4 ] == $54) AND (The_STring [noparse][[/noparse] 5 ] == $54) AND (The_STring [noparse][[/noparse] 6 ] == $20) AND (The_STring [noparse][[/noparse] 7 ] == $53)

   NUMBERS := (The_STring [noparse][[/noparse] 9 ] + The_STring [noparse][[/noparse] 10 ]   ' This is the array containing the numbers 
   SER.STR(STRING("[noparse][[/noparse]THE NUMBER IS  "))             ' Sending back the data
   SER.DEC(Numbers)                                          ' The number
   SER.STR(STRING("]"))                                      ' Ending bracket
   Com_PortA                                                      ' return to port A to look for more instructions





P.s This line of code seems to work


  SER.hex(Numbers,4)                                          ' The number






Any help would be great ...

Post Edited (grasshopper) : 5/15/2008 3:36:53 PM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-05-15 15:37
    The_STring[noparse][[/noparse] 9 ] in your example is the value $33 (or "3") and The_STring[noparse][[/noparse] 10 ] is the value $30 (or "0"). If you want the numeric value of the digits, you have to subtract $30 (or "0") from them.
  • grasshoppergrasshopper Posts: 438
    edited 2008-05-15 15:47
    I tried subtracting $30 from the number but it did not help. Keep in mind the the numbers can change. So The_STring [noparse][[/noparse] 9] could be 9 or 3 or 5 etc. And the same with The_STring [noparse][[/noparse] 10 ].

    I may have a input of

    
    [noparse][[/noparse]TT S 51] 
    
    or 
    
    [noparse][[/noparse]TT S 23]
    
    
    



    Later i want to use negative numbers and a range from -100 to 200 so i will increase my array a bit.
  • grasshoppergrasshopper Posts: 438
    edited 2008-05-15 15:52
    Solved thanks mike

    Just needed to rethink the post you made!
  • Mike GreenMike Green Posts: 23,101
    edited 2008-05-15 16:06
    There already exist routines for converting decimal digit strings to numbers. Take a look at the Extended Full Duplex Serial driver from the Propeller Object Exchange.
Sign In or Register to comment.