09-13-2009 06:11 AM
I am getting data over the serial port as a string of U8 bytes.
I convert the string to a sub string which reads 3B43 CD7B which corresponds to a value of 410.0 .( Or in other words my conversion should result in this value )
I tried to feed the above sub string to a typecast set for double. But the value reads as 3.27607E-23.
Any hints ?
Solved! Go to Solution.
09-13-2009 07:16 AM
Sorry, but something or someone (possibly me) is seriously confused.
To convert the string "3B43CD7B" into a U32 requires a SCAN FROM STRING with a "%x" (hex) specifier.
Outputs 1 and 2 in the pic show that this is done correctly.
When you cast that to a SGL, you get 0.00298.
I don't know why you would cast it to a DBL, a 4-byte float is a SGL.
If you reverse the byte order, you get a huge (E+36) number, so that's not it.
If you take the binary number (00111011010000111100110101111011) apart, according to IEE 754 (standard SGL format), you get:
Sign = 0 = positive.
exponent = 01110110 (118) - bias (127) = -9
mantissa = 100001111.... = 271 / 512 = 0.529297
Accounting for the assumed MSB makes it 1.529297
2 ^ -9 = 0.001953
1.529297 * 0.001953 = 0.002987 (I didn't carry all the digits).
So that conversion is correct.
I don't see how to get 410.0 from the data you gave us.
Blog for (mostly LabVIEW) programmers: Tips And Tricks
09-13-2009 07:26 AM
I convert the string to a sub string which reads 3B43 CD7B
--- Perhaps an error occurs there. Perhaps you're pulling the wrong pieces out.
Converting 410.0 to SGL results in a value of 43CD0000 Notice the 43CD similarity?
"3B" is ASCII code for ";" (semicolon).
Looks like you're not accounting for something in your string.
Blog for (mostly LabVIEW) programmers: Tips And Tricks
09-14-2009 09:23 PM - edited 09-14-2009 09:26 PM
Hello Steve,
Thanks for the analysis. And trying to typecast a 32 bit to a double was a mistake, that happened over many iterations of different combinations !
Will collect a few more samples and try out based on the hints you gave. Shall revert shortly.
09-15-2009 08:30 AM
09-15-2009 08:42 AM - edited 09-15-2009 08:43 AM
09-15-2009 12:17 PM - edited 09-15-2009 12:25 PM
Yes of course knowing the type of instrument is a good place to start. It is a EM6400 energy manager from Conzerv( now Schneider). I am attaching the data format details it returns to a query.
I am also attaching the full U8 byte array returned by the instrument from where I am trying to "strip" the data value corresponding to 410.0 ( when I captured this is what the instrument was displaying ).
Thanks
09-15-2009 12:25 PM
It's hard to tell from that doc what you're doing.
How are you extracting the string to convert from the string it's supplied in?
It looks to me like you're extracting 4 bytes from an offset that's off by one.
IOW, you're starting at offset 10 when it should be 11, or something.
I suggest you try changing that procedure and seeing what happens.
Blog for (mostly LabVIEW) programmers: Tips And Tricks
09-15-2009 12:42 PM
09-15-2009 01:32 PM
Raghunathan,
Your current code reads two registers at unknown address ? Modify your code to read 4 registers starting at the same address and post the resulting array of bytes.