I need to read in values from a serial port, which arrive in HEX encoded.
For instance, 75.8f = 0x42 0x97 0x99 0x9A When I receive “42 97 99 9A” I need to decode it to “75.800003”. Most of what I can find in Xojo language ref is useful for single values < 255, but not for Floats (Doubles).
The follow C code works, but I’m not sure how to recreate this in Xojo. Thanks for any pointers! (pun intended)
Norman, I’ll be contacting my friends at Mensa and recommending they appoint you immediately. Thanks for the help. The “SingleValue” was where I got stuck, and you solved it before I had time to mention it. Many thanks! This seems to work like a charm:
dim myMB as New MemoryBlock(4)
dim myDouble as Double
Hello everybody!
Here in Bergamo, Italy is so hot … And my neurons have decided to go on vacation …
I was reading your post. And it seems to me very useful for what I have to do.
I need to read a .is2 file (Fluke thermal image);
The temperature map is written using a simple data compression system.
In practice, using LITTLE_ENDIAN I have to read 2 bytes for example 0xDF11 and convert them to a Single Type variable
I wrote a class by translating something that was done in C.
But now I get an error when I try to use the ‘ByteBuffer’ class I can not fix.
Do you try to help me with courtesy?
I’m not familiar with ByteBuffer class, and I cannot follow the link you posted to GitHub (perhaps my IT Director is blocking that URL). Is the class too large to paste directly into this ticket?
Let me make sure I understand, you have (2) bytes and want to convert them to a value, in an Xojo application, correct? I just want to make sure there isn’t something more complicated you are trying to do…
Are you wanting to turn 0xDF11 into “6.41094e-42” (into a Double precision float)?
I have to do some tests because, I do not know exactly how the data is encoded in the file;
I think it works so, because from the beginning of the 0xE89 map at the end 26689 are exactly 153600 bytes, realizing that the map is from 320x240 = 76800 the data is saved in two bytes;
And are values from -1200.99 to 1200.99 so it should be so (and I hope)
Hi Massmiliano, I should hope someone else chimes in on this, but a single-precision floating-point requires 4-bytes, not 2-bytes as you show in your example.
Again, if I’m way off base please, someone give me a slap across my cheek.
Massimiliano, is2 format is a point format (data point) that then you have to convert to double (in a approximated scale)
Sadly it’s a proprietary format so is hard to find some documentation.
I have found a couple of matlab functions that can be easily translated but both are “hard” linked to a specific model (there is no info about where the IR or IMG data starts)
Il formato relativo alla termografia inizia dal byte E89 e termina al byte 26689 . in pratica sono 153600 byte / 2 = 76800.
Se ovviamente il formato 320x240 thermal pixels; altrimenti il formato pi piccolo, 160x120 ad esempio; sono certo gli ultimi due byte DF11 dovrebbero corrispondere a 76,6 ( in fahrenheit degree ) per questo file.
For IMG data, are in RGB format, and are not important now.
Have a Java ( Android ) function and use ‘ByteBuffer’ function for work.
I lost in a glass of water …
I called a friend was working in Fluke;
He just explained that the temperatures are saved on file in format uint16, but we knew it already …
But how are they translated into temperature?
Simple, there is a simple calibration map at the beginning of the file that tells which report to use (such as simple division and subtraction) from the uint16 number to get the double value with a 0.01 degree accuracy.