Получение данных pyModbus в список - PullRequest
0 голосов
/ 04 декабря 2018

Я использую pymodbus для чтения данных с моего оборудования.

Вот код, который я использую, и он работает!

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= 0x01).registers

print(result)

#Closes the underlying socket connection
client.close()

И результат:

pi@raspberrypi:~ $ python pyserial2.py
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: 0x1 0x4 0x14 0x1 0x52 0x3 0x12 0x0 0xfa 0x3 0x20 0x0 0x0 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0x0 0x1 0xab 0xd6
DEBUG:pymodbus.framer.rtu_framer:Getting Frame - 0x4 0x14 0x1 0x52 0x3 0x12 0x0 0xfa 0x3 0x20 0x0 0x0 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0x0 0x1
DEBUG:pymodbus.factory:Factory Response[ReadInputRegistersResponse: 4]
DEBUG:pymodbus.framer.rtu_framer:Frame advanced, resetting header!!
DEBUG:pymodbus.transaction:Adding transaction 1
DEBUG:pymodbus.transaction:Changing transaction state from 'PROCESSING REPLY' to 'TRANSACTION_COMPLETE'
[338, 786, 250, 800, 0, 65535, 65535, 65535, 65535, 1]

Результат показан с ".registers".Но я не знаю, как превратить значение в список.

...