[英]Pymodbus-read-input-registers CRC invalid, discarding header
我正在使用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'
我如何使這項工作修復 CRC 無效,丟棄標頭?
任何幫助都會很好謝謝。
凱文
排隊:
result= client.read_input_registers(0x00,10,unit= 0x1)
print(result.registers)
你應該打印寄存器數組:
result= client.read_input_registers(0x00,10,unit= 0x1)
print(result.registers[0])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.