Here is a "plain" python script using TCP, can you test it on your setup, it should print out some (debug)data, just to see if the connection is ok
Alter the parameters when needed.
*edit updated the script to print out data values
Code: Select all
#!/usr/bin/env python
from pymodbus.client.sync import ModbusTcpClient
# configure the client logging
import logging
logging.basicConfig()
log = logging.getLogger()
log.setLevel(logging.DEBUG)
client = ModbusTcpClient('192.168.1.21', port=502)
# OR is a unit address (with TCP) also needed if there are more devices on one address?
# client = ModbusTcpClient('192.168.1.21', port=502, unit=1)
data = client.read_input_registers(1009, 2) # FUNCTION 04 - Read register 1009, length=2
print (data)
print (data.registers[0])
print (data.registers[1])
Code: Select all
sudo pip install -U pymodbus
Code: Select all
sudo python test.py