how to read ascii/rtu data from meter uusing python

600 views
Skip to first unread message

Nagarjuna Reddy

unread,
Aug 16, 2020, 1:22:41 PM8/16/20
to pymodbus
how to read ASCII data from meter using pymodbus python code

Abbad Zafar

unread,
Aug 17, 2020, 5:58:19 AM8/17/20
to pymodbus

import pymodbus
from pymodbus.pdu import ModbusRequest
from pymodbus.client.sync import ModbusSerialClient as ModbusClient
#initialize a serial RTU client instance
from pymodbus.transaction import ModbusRtuFramer

#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', baudrate= 9600)

#Connect to the serial modbus server
connection = client.connect()
print(connection)

#Starting add, num of reg to read, slave unit.
read = client.read_holding_registers(address = 0x01,count =2, unit=1)
data = read.registers

print(data)

#Closes the underlying socket connection
client.close()

Reply all
Reply to author
Forward
0 new messages