Reading REAL and decoding with decode_32bit_float()

1,105 views
Skip to first unread message

BigTuna

unread,
Mar 22, 2014, 5:17:52 PM3/22/14
to pymo...@googlegroups.com
Maybe someone can help me figure out what I'm missing here. I'm following the example exactly:

#!/usr/bin/env python
'''
Pymodbus Payload Building/Decoding Example
--------------------------------------------------------------------------
'''
from pymodbus.constants import Endian
from pymodbus.payload import BinaryPayloadDecoder
from pymodbus.payload import BinaryPayloadBuilder
from pymodbus.client.sync import ModbusTcpClient as ModbusClient


client = ModbusClient('192.168.0.10)
client.connect()

rr = client.read_holding_registers(2654, 2)
decoder = BinaryPayloadDecoder.fromRegisters(rr.registers, endian=Endian.Little)
print decoder.decode_32bit_float()

client.close()

What I'm suppose to get is 33.87. What it prints is 1.46638408846e-34

Using MacModbus App (http://www.modbusapps.com/) I can see the binary in the memory locations:

42654    01110111111101010
42655    0100001000000111

Putting the 2 registers together (01000010000001110111011111101010) and checking here:

http://www.h-schmidt.net/FloatConverter/IEEE754.html

I get my 33.87.

Since I've confirmed everything is there in memory does anyone see what I'm doing wrong with my pymodbus code?

Thanks!



BigTuna

unread,
Mar 22, 2014, 9:16:38 PM3/22/14
to pymo...@googlegroups.com
Made some progress. Confirmed I need to use Big Endian. The problem is that m340 stores the first half in the second register and the function expects in to be first half first.

 

Bashwork

unread,
Jul 24, 2014, 12:08:48 AM7/24/14
to pymo...@googlegroups.com
Sorry I am so late to respond, but I am glad you made progress!

Galen
Reply all
Reply to author
Forward
0 new messages