I'm trying to get voltage or current from PM5300 meter, but always come 32768 only. The code:
from pymodbus.constants import Endian
from pymodbus.payload import BinaryPayloadDecoder
from pymodbus.client.sync import ModbusSerialClient as ModbusClient
import logging
FORMAT = ('%(asctime)-15s %(threadName)-15s '
'%(levelname)-8s %(module)-15s:%(lineno)-8s %(message)s')
logging.basicConfig(format=FORMAT)
log = logging.getLogger()
log.setLevel(logging.DEBUG)
UNIT = 0x01
def run_sync_client():
client = ModbusClient(method='rtu', port='COM15', timeout=1, baudrate=19200, parity='E', stopbits=1, bytesize=8)
client.connect()
request = client.read_holding_registers(address=43010, count=2, unit=UNIT)
result = request.registers
print(result)
decoder = BinaryPayloadDecoder.fromRegisters(result, Endian.Little, wordorder=Endian.Big)
#dc2 = (decoder.decode_32bit_float() + 32768 /1000)
#print(dc2)
print(decoder.decode_32bit_float())
client.close()
if __name__ == "__main__":
run_sync_client()
The address 3010 in register list matches to current (4 is the holding register).
The log and print with Endian.Little:
2020-06-16 20:11:24,349 MainThread DEBUG transaction :115 Current transaction state - IDLE
2020-06-16 20:11:24,349 MainThread DEBUG transaction :120 Running transaction 1
2020-06-16 20:11:24,350 MainThread DEBUG transaction :219 SEND: 0x1 0x3 0xa8 0x2 0x0 0x2 0x45 0xab
2020-06-16 20:11:24,350 MainThread DEBUG sync :75 New Transaction state 'SENDING'
2020-06-16 20:11:24,350 MainThread DEBUG transaction :228 Changing transaction state from 'SENDING' to 'WAITING FOR REPLY'
2020-06-16 20:11:24,364 MainThread DEBUG transaction :304 Changing transaction state from 'WAITING FOR REPLY' to 'PROCESSING REPLY'
2020-06-16 20:11:24,365 MainThread DEBUG transaction :233 RECV: 0x1 0x3 0x4 0x80 0x0 0x80 0x0 0xb2 0x33
2020-06-16 20:11:24,365 MainThread DEBUG rtu_framer :180 Getting Frame - 0x3 0x4 0x80 0x0 0x80 0x0
2020-06-16 20:11:24,365 MainThread DEBUG factory :266 Factory Response[ReadHoldingRegistersResponse: 3]
2020-06-16 20:11:24,365 MainThread DEBUG rtu_framer :115 Frame advanced, resetting header!!
2020-06-16 20:11:24,366 MainThread DEBUG transaction :383 Adding transaction 1
2020-06-16 20:11:24,366 MainThread DEBUG transaction :394 Getting transaction 1
2020-06-16 20:11:24,366 MainThread DEBUG transaction :193 Changing transaction state from 'PROCESSING REPLY' to 'TRANSACTION_COMPLETE'
[32768, 32768]
**2020-06-16 20:11:24,366 MainThread DEBUG payload :312 [32768, 32768]**
2020-06-16 20:11:24,367 MainThread DEBUG payload :368 [b'\x00\x80', b'\x00\x80']
1.1755122874426309e-38
With Endian.Big the result: -4.591774807899561e-41
Thanks a lot!