Yesterday I wanted to reconfigure all the PLCs in my lab with settings for a specific use case.
This involves changing the values of 3 registers to make the PLCs listen to a server over DHCP.
my lab has 12 FC6A plcs. and loading windLDR on all of them would have been a pain.
So i wrote this python script using FC6A python library to configure all the PLCs automatically.
#!/usr/bin/env python3
from fc6a import FC6AMaint
from time import sleep
# Configure every PLC on the subnet to be MCPLA comatable.
# Remote mode M2031
def confPLC(plc):
setMCPLA_lock = 7077 # 1=mcpla on 0=mcpla off
setDHCP = 1330 # DHCP setting
setRmote = 2031
plc.write_word(setMCPLA_lock, 1)
plc.write_word(setRmote, 0)
plc.write_word(setDHCP, 0)
masq = "192.168.1."
for i in range(1, 255):
ip = masq + str(i)
plc = FC6AMaint(ip)
try:
confPLC(plc)
print("OK", ip)
except Exception:
pass
Sure, the code is a bit hap hazard, Im literally sending the PLC register configuration to every device in the class D subset of the lab.
but only the PLCs will respond to the Maintenance protocol on port 2101, so its low risk even if its substandard code.