Я работаю с PZEM-004T 3.0 Версия
У меня сейчас устройство отвечает с ошибками.
import pymodbus
import serial
from pymodbus.pdu import ModbusRequest
from pymodbus.client.sync import ModbusSerialClient as ModbusClient #initialize a serial RTU client instance
from pymodbus.transaction import ModbusRtuFramer
import logging
logging.basicConfig()
log = logging.getLogger()
log.setLevel(logging.DEBUG)
#count= the number of registers to read
#unit= the slave unit this request is targeting
#address= the starting address to read from
client= ModbusClient(method = "rtu", port="/dev/ttyUSB0", stopbits = 1, bytesize = 8, parity = 'N', baudrate= 9600)
#Connect to the serial modbus server
connection = client.connect()
print (connection)
#Starting add, num of reg to read, slave unit.
result= client.read_input_registers(0x00,10,unit= 0x1)
print(result.registers)
#Closes the underlying socket connection
client.close()
Это вывод
True
DEBUG:pymodbus.transaction:Current transaction state - IDLE
DEBUG:pymodbus.transaction:Running transaction 1
DEBUG:pymodbus.transaction:SEND: 0x1 0x4 0x0 0x0 0x0 0xa 0x70 0xd
DEBUG:pymodbus.client.sync:New Transaction state 'SENDING'
DEBUG:pymodbus.transaction:Changing transaction state from 'SENDING' to 'WAITING FOR REPLY'
DEBUG:pymodbus.transaction:Changing transaction state from 'WAITING FOR REPLY' to 'PROCESSING REPLY'
DEBUG:pymodbus.transaction:RECV: 0x0 0x7f 0xdf 0xdd 0xdf 0xfc 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xb3 0xff 0xff 0xfb 0x51 0xff 0xff 0xff 0xff 0x31 0x39
DEBUG:pymodbus.framer.rtu_framer:CRC invalid, discarding header!!
DEBUG:pymodbus.framer.rtu_framer:Resetting frame - Current Frame in buffer - 0x0 0x7f 0xdf 0xdd 0xdf 0xfc 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xb3 0xff 0xff 0xfb 0x51 0xff 0xff 0xff 0xff 0x31 0x39
DEBUG:pymodbus.framer.rtu_framer:Frame check failed, ignoring!!
DEBUG:pymodbus.framer.rtu_framer:Resetting frame - Current Frame in buffer -
DEBUG:pymodbus.transaction:Getting transaction 1
DEBUG:pymodbus.transaction:Changing transaction state from 'PROCESSING REPLY' to 'TRANSACTION_COMPLETE'
Traceback (most recent call last):
File "test9.py", line 27, in <module>
print(result.registers)
AttributeError: 'ModbusIOException' object has no attribute 'registers'
Как заставить эту работу исправить недействительный CR C, отбрасывая заголовок?
Любая помощь будет хорошей, спасибо.
Кевин