PDA

View Full Version : Variable and array WITH serial com problem



grasshopper
05-15-2008, 09:57 PM
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 "[TT S 30]" I get the correct data i just can not add The_STring [ 9 ] and The_ STring [ 10 ] which are 3 and 0 in "[TT S 30]"





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

NUMBERS := (The_STring [ 9 ] + The_STring [ 10 ] ' This is the array containing the numbers
SER.STR(STRING("[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

Mike Green
05-15-2008, 10:37 PM
The_STring[ 9 ] in your example is the value $33 (or "3") and The_STring[ 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.

grasshopper
05-15-2008, 10:47 PM
I tried subtracting $30 from the number but it did not help. Keep in mind the the numbers can change. So The_STring [ 9] could be 9 or 3 or 5 etc. And the same with The_STring [ 10 ].

I may have a input of





[TT S 51]

or

[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.

grasshopper
05-15-2008, 10:52 PM
Solved thanks mike

Just needed to rethink the post you made!

Mike Green
05-15-2008, 11:06 PM
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.