pack and unpack ?

S

Steve

Sorry to be thick, but I have googled this and ended-up more confused
than ever. So I hope you don't mind if I come back on this question.

I am reading a series of bytes from a com port. Having looked at the
data and the way it changes, I *believe* that some or all of the bytes

123 101 60 117

represent a signed floating-point with the value of approximately +24
(+/- 1)

Could someone kindly explain how I get to the value from the raw
bytes?

Thanks
 
M

Michael Fuhr

I am reading a series of bytes from a com port. Having looked at the
data and the way it changes, I *believe* that some or all of the bytes

123 101 60 117

represent a signed floating-point with the value of approximately +24
(+/- 1)

Why do you believe that? What evidence leads you to that conclusion?
Could someone kindly explain how I get to the value from the raw
bytes?

Find out for certain what kind of data is represented, how it's
represented, and that you're looking at the right portion of the
data. Beware of looking for a solution before you fully understand
the problem.

Here's one way to create a string of those four bytes and then
unpack that string as a floating-point number:

my $s = pack("C*", 123, 101, 60, 117); # assumes the numbers are decimal
my $f = unpack("f", $s);

On my i386 machine this yields 2.38821e+32; on my sparc it yields
1.19026e+36 (differences due to endianness). If the bytes do indeed
represent a floating-point number around 24 then this method of
unpacking is wrong.
 
I

ineverlookatthis

Thanks, that helps and I will play further along those lines. I
suspect that 2.38821e+32 is very close to 24 if I ignore some high end
bits.
What evidence leads you to that conclusion?

I am reading temperature data from a device which receives data
wirelessly from many transmitters and then sends it via serial to the
PC.

I see a series of characters every time the device receives input from
a sensor, including the identity of the device in plain text and the
time in a series of decomals, so I know I have the comm protocol
right. If I change the temp, only those 4 columns of numbers change, I
know the temperature at the probe, I know the devices own software
shows the temp to 3 decimal places and has a range of -50 to +150 C.

Of course there could be some unique coding in here, but they are very
profligate with data, (sending some 30 characters of text), so I doubt
that they will have bothered to pack it in a cunning way.

The obvious question is 'what does the manufacturer say', the answer is
they don't respond to questions!
 
M

Michael Fuhr

I see a series of characters every time the device receives input from
a sensor, including the identity of the device in plain text and the
time in a series of decomals, so I know I have the comm protocol
right. If I change the temp, only those 4 columns of numbers change, I
know the temperature at the probe, I know the devices own software
shows the temp to 3 decimal places and has a range of -50 to +150 C.

Could you post several samples, showing the data you receive and
the corresponding temperature at the probe? If the numbers do
indeed represent the temperature then maybe we can find the pattern.
 
I

ineverlookatthis

OK, here is the data I see. The numbers are all generated by
ord(character)

Note that 2 temeratures are being sent, an internal and an external
(probe) temp.
All degrees Centigrade. All were taken when the system was stable
EXCEPT the two
marked as approx.

internal 27.33 external 26.330
corresponding data looks like this:
3 10 80 72 113 88 126 12 72 123 109 53 117

internal 24* approx external 0
3 10 80 72 113 88 127 12 72 123 47 61 117

internal 16.5* approx external 0
3 10 80 72 113 89 127 12 72 123 47 86 117

internal 27.33 external -24
3 10 80 72 113 88 127 12 72 123 14 53 117

internal 27.33 external -50
3 10 80 72 113 88 127 12 72 123 4 53 117




Thanks
 
I

ineverlookatthis

Here's more. I should have done this sytematically before.
It may be relevant that the scale of the external reading is -50 to
+100
and of the internal reading -30 to +50.


6.5 l 0
3 10 80 72 113 90 127 12 72 123 47 121 117

5.25 0
3 10 80 72 113 91 127 12 72 123 47 125 117

21.67 50
3 10 80 72 113 88 126 12 72 123 33 68 117

27.33 88
3 10 80 72 113 88 127 12 72 123 74 53 117
27.67 96
3 10 80 72 113 88 127 12 72 123 78 52 117
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

pack/unpack help please 6
pack /unpack issue 1
bug with unpack('m') / pack('m') ? 0
pack and unpack integer data 3
pack, unpack and 64-bit values 3
pack and hex 9
pack/unpack bits 1
pack problem? 2

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top