get float ?
Hi!
I have been trying to read values from a digital mutimeter. The values comes in scientific form, eg. 3,2E+3. Cant find any suitable way to do this...
Is there a "getfloat" command, or something similar?
Thanks in advance!
I have been trying to read values from a digital mutimeter. The values comes in scientific form, eg. 3,2E+3. Cant find any suitable way to do this...
Is there a "getfloat" command, or something similar?
agi.get[color=#990000] ???[/color](agiVal) agiVal := (flo.FloatToString(agiVal)) agiVal := (vfd.StrToDec(agiVal)) vfd.dec(agiVal)
Thanks in advance!

Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
However, I can't seem to find any command to collect this floating point number from the multimeter.
Str2Float(str_ptr) : float_n 'test BYTE[noparse][[/noparse]str_ptr] 'if == '-' set negative flag for mantissa then increment str_ptr 'set mantissa equal to BYTE[noparse][[/noparse]str_ptr] - "0" then increment str_ptr by 2 (skipping decimal place) 'repeat until BYTE[noparse][[/noparse]str_ptr] == "E" 'mantissa := (mantissa * 10) + BYTE[noparse][[/noparse]str_ptr] - "0" (shift mantissa and add next decimal place) 'increment str_ptr 'str_ptr++ (skip past E) 'if BYTE[noparse][[/noparse]str_ptr] == '-' set negative flag for exponent, increment str_ptr 'exponent := BYTE[noparse][[/noparse]str_ptr] - "0" 'str_ptr++ 'if BYTE[noparse][[/noparse]str_ptr] <> 0 'exponent := (exponent * 10) + BYTE[noparse][[/noparse]str_ptr] - "0" 'Now you have 4 variables filled: mantissa, exponent and the negative flags for each 'if a negative flag is set, perform the two's compliment of the corresponding value 'pack a 32 bit integer (variable float_n) with the exponent and mantissa fields according to IEEE-754 standardAfter the routine is performed you will have a floating point representation of the string
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
Post Edited (Paul Baker (Parallax)) : 5/6/2008 6:20:58 PM GMT
repeat agi.getstr(agiVal) stf.StringToFloat(agiVal, @vfdVal) vfd.str(string($0C)) vfdVal := fmath.FSub(vfdVal, tara) vfd.str(fstr.FloatToString(vfdVal)) agi.rxflushProblem is, "tara" is supposed to be a "calibration-value". I am writing this program for someone, the idea is that he can tune the sufficient calibration and then turn the propeller off. And when he switches it on again the tara-value is still the same as it was when he turned the chip off, and hence he doesn't have to recalibrate it every time he starts up propeller chip. My spontaneous idea was to store this tara-value in the EEPROM, it's just that I can't seem to find any simple way to do that... Is there a way to achieve this?
you can use the Format object function bscanf
OBJ
· fmt: "Format"
k var long
buf var byte[noparse][[/noparse]10] 'assumed to hold received value string
i var long
f var long
e var long
k := fmt.bscanf(@buf,0,string("%d"),@i)· 'convert integer part, reads up to the decimal point (comma)
k := fmt.bscanf(@buf,k,string(",%d"),@f)· 'convert fractional part, skips the decimal point·(comma)
k := fmt.bscanf(@buf,k,string("E%d"),@e)· 'convert exponent, skips the E
Both i and e can be positive, zero or negative, f can be zero or positive.
Now you just need to combine i, f and e into a floating point number.
You will find the Format object in the object exchange under Tools.
regards peter