Long awaited video on how to use the Rpi GPIO to control aspects of the PLC.
Showing posts with label Video Series. Show all posts
Showing posts with label Video Series. Show all posts
Wednesday, December 28, 2016
Rasberry Pi - Tutorials - S7-1200 & Snap7 Python - Controlling the PLC Using Rpi GPIO
Long awaited video on how to use the Rpi GPIO to control aspects of the PLC.
Monday, February 29, 2016
Raspberry Pi - Python Snap7 - Mapping and Reading Datablocks
import snap7.client from snap7.snap7types import * from snap7.util import * class DBObject(object): pass offsets = { "Bool":2,"Int": 2,"Real":4,"DInt":6,"String":256} db=\ """ Temperature Real 0.0 Cold Bool 4.0 RPis_to_Buy Int 6.0 Db_test_String String 8.0 """ def DBRead(plc,db_num,length,dbitems): data = plc.read_area(areas['DB'],db_num,0,length) obj = DBObject() for item in dbitems: value = None offset = int(item['bytebit'].split('.')[0]) if item['datatype']=='Real': value = get_real(data,offset) if item['datatype']=='Bool': bit =int(item['bytebit'].split('.')[1]) value = get_bool(data,offset,bit) if item['datatype']=='Int': value = get_int(data, offset) if item['datatype']=='String': value = get_string(data, offset) obj.__setattr__(item['name'], value) return obj def get_db_size(array,bytekey,datatypekey): seq,length = [x[bytekey] for x in array],[x[datatypekey] for x in array] idx = seq.index(max(seq)) lastByte = int(max(seq).split('.')[0])+(offsets[length[idx]]) return lastByte if __name__ == "__main__": plc = snap7.client.Client() plc.connect('10.10.55.109',0,0) itemlist = filter(lambda a: a!='',db.split('\n')) deliminator='\t' items = [ { "name":x.split(deliminator)[0], "datatype":x.split(deliminator)[1], "bytebit":x.split(deliminator)[2] } for x in itemlist ] #get length of datablock length = get_db_size(items,'bytebit','datatype') meh = DBRead(plc,10,length,items) print """ Cold:\t\t\t{} Tempeature:\t\t{} RPis_to_Buy:\t{} Db_test_String:\t{} """.format(meh.Cold,meh.Temperature,meh.RPis_to_Buy,meh.Db_test_String) plc.disconnect();
Wednesday, February 3, 2016
Python Snap7 S7-1200 Simple Reading/Writing Memory Example
import snap7.client as c from snap7.util import * from snap7.snap7types import * def ReadMemory(plc,byte,bit,datatype): result = plc.read_area(areas['MK'],0,byte,datatype) if datatype==S7WLBit: return get_bool(result,0,bit) elif datatype==S7WLByte or datatype==S7WLWord: return get_int(result,0) elif datatype==S7WLReal: return get_real(result,0) elif datatype==S7WLDWord: return get_dword(result,0) else: return None def WriteMemory(plc,byte,bit,datatype,value): result = plc.read_area(areas['MK'],0,byte,datatype) if datatype==S7WLBit: set_bool(result,0,bit,value) elif datatype==S7WLByte or datatype==S7WLWord: set_int(result,0,value) elif datatype==S7WLReal: set_real(result,0,value) elif datatype==S7WLDWord: set_dword(result,0,value) plc.write_area(areas["MK"],0,byte,result) if __name__=="__main__": plc = c.Client() plc.connect('10.10.54.2',0,1) print ReadMemory(plc,420,0,S7WLReal) WriteMemory(plc,420,0,S7WLReal,3.141592) print ReadMemory(plc,420,0,S7WLReal) #DONE!!
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()
Thursday, December 24, 2015
New S7-1200 & Snap7 Walkthrough Video Uploaded
I'm going to try and start a series of videos on python snap7 tutorial using my Raspberry Pi.
Here's the setup walkthrough :-)
Youtube link: https://youtu.be/yJNEsI5KJxs
Subscribe to my channel to keep up to date Channel Link
Let me know what kind of things you'd like to see in the series :-)
Enjoy!
Subscribe to:
Posts (Atom)