Variable formatting and manipulating
JimCook
Posts: 3
·Below is a simple routine grabbing some data from the HEX string (below code) which belongs to the serial output of a weather station. What I have works perfectly but here is where the problem lies:
·The variables (SerData, SerStr, Tempe) display perfectly in the debug screen·because I can format them with the DEC formatter (or for that matter HEX·and binary also) but you cannot use those formatters with the variable names to perform math on them (like SerData * 621 / 10000). Actually it cannot be formatted at all except with a very few commands which are not useful to manipulate the data. The variables contain no data or just a single letter ASCII character without the formatter or may even produce a null which clears the debug screen.·
·Any ideas you may have would be a great help.
Thanks in advance
DO
SERIN 3, Baud, [noparse][[/noparse]WAIT ("!!"), HEX4 SerData]
PAUSE 500
DEBUG· CR, "Wind",· DEC4 SerData
SERIN 3, Baud, [noparse][[/noparse]WAIT ("!!"), SKIP 4, HEX4 SerStr]
PAUSE 500
DEBUG CR, "Direction", DEC4 SerStr
SERIN 3, Baud, [noparse][[/noparse]WAIT ("!!"), SKIP 8, HEX4 Tempe]
PAUSE 500
DEBUG CR, "Temp", DEC4 Tempe
LOOP
!!008100FA02BE0000
0000002300000080
·The variables (SerData, SerStr, Tempe) display perfectly in the debug screen·because I can format them with the DEC formatter (or for that matter HEX·and binary also) but you cannot use those formatters with the variable names to perform math on them (like SerData * 621 / 10000). Actually it cannot be formatted at all except with a very few commands which are not useful to manipulate the data. The variables contain no data or just a single letter ASCII character without the formatter or may even produce a null which clears the debug screen.·
·Any ideas you may have would be a great help.
Thanks in advance
DO
SERIN 3, Baud, [noparse][[/noparse]WAIT ("!!"), HEX4 SerData]
PAUSE 500
DEBUG· CR, "Wind",· DEC4 SerData
SERIN 3, Baud, [noparse][[/noparse]WAIT ("!!"), SKIP 4, HEX4 SerStr]
PAUSE 500
DEBUG CR, "Direction", DEC4 SerStr
SERIN 3, Baud, [noparse][[/noparse]WAIT ("!!"), SKIP 8, HEX4 Tempe]
PAUSE 500
DEBUG CR, "Temp", DEC4 Tempe
LOOP
!!008100FA02BE0000
0000002300000080
Comments
What is this:
>>!!008100FA02BE0000
0000002300000080
The numbers on the right are not a decimal translation of the numbers on the left. What is the Baud rate? The Stamp can do the Waits, Skips, and HEX4 inputs correctly only at relatively low baud rates, like 2400 and under.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Thanks for your reply, Jim
SERIN 3, Baud, [noparse][[/noparse]WAIT ("!!"), HEX4 SerData]
then SerData will contain $0081 or 129 (the same in hex or decimal) after the SERIN. You could even get all three values in one statement with
SERIN 3, Baud, [noparse][[/noparse]WAIT("!!"), HEX4 SerData, HEX4 SerStr, HEX4 Tempe]
After the SERIN, SerData will contain $0081, SerStr will contain $00FA, and Tempe will contain $02BE. Since the first two values are only 8 bits, you could define SerData and SerStr as bytes. Temp3 is 10 bits, so you will need a word for that value.
Hex is just another method to represent a number. We're taught growing up the decimal counting system (0,1,2,...,9,10,11,...,99,100,...) but there are other bases available. Hex just counts from 1,2,3,...,9,A,B,C,D,E,F,10,11,...,19,1A,1B,...
There are lots of hex to decimal converters available online that you can use. Wikipedia is also another excellent resource.
So, $81 means (8*16) + (1*1) or 129.