Byte Arrays and Integers
Roger Pierson
Posts: 62
I'm sure this has been asked before, but I can't find the answer.
Suppose I query a power supply with "V?" and it sends back its voltage setting in this format:
V 12.45 [noparse][[/noparse]CR]
I'm using an RSB509 serial buffer (nice piece of hardware, by the way) to catch the reply and feed it to my STAMP (BS2) one byte at a time. The data gets stored in a byte array. I can't use the SERIN decimal qualifier because I'm reading the data byte by byte. In any case, the decimal point would screw it up.
My question is, how can I extract the value 12.45 from a string array and store it as an integer (or two integers to deal with the decimal point) so that I can manipulate it with math operations and more importantly, so that it takes up less variable space? I suppose I could just pull each number out of the array and deal with it independantly, but there must be a better way!
Thanks in advance for the help!
-Roger
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Roger Pierson
Senior Electronics Technicain
DTI Assoicates
Suppose I query a power supply with "V?" and it sends back its voltage setting in this format:
V 12.45 [noparse][[/noparse]CR]
I'm using an RSB509 serial buffer (nice piece of hardware, by the way) to catch the reply and feed it to my STAMP (BS2) one byte at a time. The data gets stored in a byte array. I can't use the SERIN decimal qualifier because I'm reading the data byte by byte. In any case, the decimal point would screw it up.
My question is, how can I extract the value 12.45 from a string array and store it as an integer (or two integers to deal with the decimal point) so that I can manipulate it with math operations and more importantly, so that it takes up less variable space? I suppose I could just pull each number out of the array and deal with it independantly, but there must be a better way!
Thanks in advance for the help!
-Roger
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Roger Pierson
Senior Electronics Technicain
DTI Assoicates
Comments
Your byte-by-byte approach is what you should use. There are no conversion utilities, macros or other similar conversion routines. This is LOW LEVEL programming, and most of us LOVE IT
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
·
·· Another possibility would be to use the WAIT modifier on your SERIN and then grab both sections of the variable as follows…
·
SERIN Pin, Baud, [noparse][[/noparse]WAIT(“V”[noparse];)[/noparse], DEC temp1, DEC temp2]
·
·· I believe this would get the 12 into temp1 and the 45 into temp2 based on how the SERIN formatters handle non-numeric data.· Essentially the period would terminate the first variable (12) and the CR would terminate the second half (45).· I hope this helps.· Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support