我正在尝试使用带有 python 的 snap7 连接到 plc,以前代码工作正常,但现在当我尝试运行时显示错误 b'CLI:现在无法更改此参数'我尝试在不同版本的 python 上运行它,我也重新安装snap7 库现在我尝试使用 python-snap7 1.1 库和 snap7 版本的 1.4 运行。
import snap7.client as c
from snap7.util import *
from snap7.types import *
class Comms():
"""Controller PLC Comms """
def __init__(self, ip_addr, rack, slot):
"""Initialize connection attributes."""
self.plc = c.Client()
self.ip_addr = ip_addr
self.rack = rack
self.slot = slot
def connect(self):
"""Establish connection to PLC """
try:
self.plc.connect(self.ip_addr, self.rack, self.slot)
message = "Connection Successfull!!!!"
status = 1
except:
message = "Connection Failed - Unreachable peer, check plc setup and connection"
status = 2
return status
def ReadMemory(self, area, index, start, lenght):
"""Read Memory Area """
try:
self.data = self.plc.read_area(areas[area], index, start, lenght)
bytes = []
for self.data in self.data:
bytes.append(self.data)
return bytes
except:
message = 'Failed to read Data'
return message
def ReadBool(self, byte_index, bool_index):
'''Read bool from array'''
try:
boolVal = get_bool(self.data, byte_index, bool_index)
print(boolVal)
return boolVal
except:
pass
if __name__ == "__main__":
plc = Comms('192.168.1.10', 0, 1)
plc.connect()
print(plc.connect())