繁体   English   中英

Pymodbus-read-input-registers CRC 无效,丢弃报头

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM