我想使用Raspberry Pi 3模型B從Allen Bradly PLC讀取值。我使用Pymodbus Modbus TCP協議在它們之間進行通信。Pymodbus無法連接PLC從站和樹莓派主站
當我運行一個測試客戶端,我得到了以下錯誤:
[email protected]:/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]
下面是測試客戶端代碼:
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()
我可以ping PLC的網卡的IP地址(10.0.0.237)就好了。 (PLC的是和在RSLinx和RSLogix5000中顯示出來。)但是,當我嘗試用命令來檢查端口502(它的Modbus使用):
telnet 10.0.0.237 502
我得到的錯誤:
Trying 10.0.0.237...
telnet: Unable to connect to remote host: Connection refused
我所做的研究告訴我要檢查該端口是否打開,但這是針對PC的,我不知道如何檢查/配置PLC上的端口。
此外,我想知道是否問題是我試圖只使用Modbus來Raspbery Pi和PLC之間。我找到了可以實現接口的優秀網關。但我找不到任何有關這些是否只是另一種選擇的信息,或者是否需要這些信息。
我是新來的PLC和網絡,所以任何幫助,將不勝感激。