Few hours yesterday and some today debugging Python I was able to solve the task to use S7 Protocol with my LOGO. I have heard that LOGO is based on S7-200 but maybe the correct answer would be S7-200SMART. Maybe someone here knows more. To test the code below you need LOGO or if you change how communication is done with other Siemens PLC.
Here is the code that read/write data-type bool from Network block and Memory flag.
from LECPython import LECPython
from time import sleep
# import inspect
lecp = LECPython()
# res = lecp.SiemensPPIOverTcpConnection("192.168.0.2", 102, 1, "CDAB", True, 2000)
res = lecp.SiemensS7NetConnection("S200SMART", "192.168.0.2", 102, 0, 0, "CDAB", True, 2000)
# res = lecp.ModbusTcpNetConnection("192.168.0.177", 502, 1, "CDAB", True, 2000)
# res = lecp.SiemensFetchWriteNetConnection("192.168.0.2", 102, "CDAB", True, 2000)
if res["IsSuccess"]:
plc = res["Content"]
print("Connection success")
else:
print("Connection error")
## debugging
# frame = inspect.currentframe()
# print(inspect.getargvalues(frame))
# Read memory flag M1
r = lecp.ReadNodeValues(plc, "V1104.0", "bool", 1)
print("M1: ", r["Content"])
sleep(1)
# Write memory flag M1
lecp.WriteNodeValues(plc, "V1104.0", "bool", [True])
r = lecp.ReadNodeValues(plc, "V1104.0", "bool", 1)
print("M1: ", r["Content"])
sleep(1)
lecp.WriteNodeValues(plc, "V1104.0", "bool", [False])
r = lecp.ReadNodeValues(plc, "V1104.0", "bool", 1)
print("M1: ", r["Content"])
sleep(1)
r = lecp.ReadNodeValues(plc, "V0.0", "bool", 1)
print("NI1: ", r["Content"])
sleep(1)
lecp.WriteNodeValues(plc, "V0.0", "bool", [True])
r = lecp.ReadNodeValues(plc, "V0.0", "bool", 1)
print("NI1: ", r["Content"])
sleep(1)
lecp.WriteNodeValues(plc, "V0.0", "bool", [False])
r = lecp.ReadNodeValues(plc, "V0.0", "bool", 1)
print("NI1: ", r["Content"])