首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Pymodbus-read-input-registers无效,正在丢弃标头

Pymodbus-read-input-registers无效,正在丢弃标头
EN

Stack Overflow用户
提问于 2020-01-13 13:08:39
回答 1查看 449关注 0票数 0

我正在与PZEM-004T 3.0 Version合作

我有一个单位现在响应错误。

代码语言:javascript
复制
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()

这是输出

代码语言:javascript
复制
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无效,丢弃报头?

任何帮助都是很好的,谢谢。

凯文

EN

回答 1

Stack Overflow用户

发布于 2021-12-02 02:40:41

在队列中:

代码语言:javascript
复制
result= client.read_input_registers(0x00,10,unit= 0x1)
print(result.registers)

您应该打印寄存器数组:

代码语言:javascript
复制
result= client.read_input_registers(0x00,10,unit= 0x1)
print(result.registers[0])
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59710844

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档