Pages

Saturday, January 2, 2016

Raspberry Pi - SCADA - Another Video Tutorial Snap7 Python for S7-1200 PLC

Another Simple snap7 Python Tutorial



Covers creating a simple example on turning on and off a PLC output.

 import snap7.client as c
 from snap7.util import *
 from time import sleep


 def WriteOutput(dev,bytebit,cmd):
     byte,bit = bytebit.split('.')
     byte,bit = int(byte),int(bit)
     data = dev.read_area(0x82,0,byte,1)
     set_bool(data,byte,bit,cmd)
     dev.write_area(0x82,byte,data)

 def main():
     myplc = snap7.client.Client()
     myplc.connect('10.10.54.2',0,1)
     for x in range(10):
         WriteOutput(myplc,'0.0',x%2==0) # turns true every other iteration
         sleep(1)

 if __name__ == "__main__":
     main()

No comments:

Post a Comment