I am trying to use a Raspberry Pi 3 Model B to read values from an Allen Bradly PLC. I'm using the Pymodbus Modbus TCP protocol to communicate between them.
When I run a test client I get the following error:
pi@raspberrypi:/var $ python test1.py
Got here 1
Traceback (most recent call last):
File "test1.py", line 12, in <module>
request = client.read_holding_registers(0,1)
File "build/bdist.linux-armv7l/egg/pymodbus/client/common.py", line 109, in read_holding_registers
File "build/bdist.linux-armv7l/egg/pymodbus/client/sync.py", line 82, in execute
pymodbus.exceptions.ConnectionException: Modbus Error: [Connection] Failed to connect[10.0.0.237:502]
Here is the code for the test client:
from pymodbus.client.sync import ModbusTcpClient
#modbus connection
client = ModbusTcpClient(host='10.0.0.237')
connection = client.connect()
#test print
print "Got here 1"
#read register
request = client.read_holding_registers(0,1)
print request
client.close()
I can ping the IP address of the PLC's ethernet card (10.0.0.237) just fine. (The PLC is on and shows up in RSLinx and RSLogix5000.) But when I try to check port 502 (which Modbus uses) with the command:
telnet 10.0.0.237 502
I get the error:
Trying 10.0.0.237...
telnet: Unable to connect to remote host: Connection refused
The research I've done told me to check whether that port is open, but that is for PCs, I don't know how you check/configure the ports on a PLC.
In addition, I am wondering if the problem is that I am trying to just use Modbus to go between the Raspbery Pi and PLC. I have found prosoft gateways that do the interfacing. But I couldn't find any information on whether those were just another option or whether they were required.
I am new to PLCs and networking, so any help would be appreciated.