Can I read Modbus RS485 data received on a slave computer with Python?

282 views
Skip to first unread message

Yang Cao

unread,
Dec 21, 2017, 9:41:08 AM12/21/17
to modbus-tk

I am working on a slave computer and want to save the data transmitted from the master via Modbus RS485, into a text file. The master computer constantly send writing and reading request to the slave computer I am working on, below is a picture captured by serial port monitor.

enter image description here

I just found with minimalmodbus you can read registers. But it seems to only work if you are a master device. Can I do something similar but on a slave computer?http://minimalmodbus.readthedocs.io/en/master/usage.html

#!/usr/bin/env python
import minimalmodbus

instrument = minimalmodbus.Instrument('/dev/ttyUSB1', 1) # port name, slave 
#address (in decimal)

## Read temperature (PV = ProcessValue) ##
temperature = instrument.read_register(289, 1) # Registernumber, number of 
#decimals
print temperature

## Change temperature setpoint (SP) ##
NEW_TEMPERATURE = 95
instrument.write_register(24, NEW_TEMPERATURE, 1) # Registernumber, value, 
#number of decimals for storage

See the stackoverflow link here:
https://stackoverflow.com/questions/47926257/can-i-read-modbus-rs485-data-received-on-a-slave-computer-with-python
Reply all
Reply to author
Forward
0 new messages