Pages

Saturday, April 25, 2015

Raspberry Pi SCADA: Communitating with S7-200 Using Python

Video Demo

For how to compiling snap7 on the pi click here

Since the S7-200 is a bit different then the newer S7-1500/S7-1200 PLCs it took a bit of work to get it working. The python-snap7 library was missing the connection method for the old TSAP method of connecting. So I forked the library and added the missing function to connect. I did a pull request to get it merged back with the original and it's pending currently. Here is the link to the forked library:
https://github.com/SimplyAutomationized/python-snap7

I've also been working on a din rail enclosure for the pi that wasn't so large.   I'm going to be adding a 24vdc to 5vdc dc-dc converter to the enclosure it so I don't have to bring in usb to it.





Anyway back to the good stuff. I added the Cli_Connection in the Client.py library so the code will now be as follows:

import snap7 as p

plc = p.client.Client()
plc.set_connection_params('10.10.55.250',11,11)
plc.connect()
print plc.get_connected()
if(plc.get_connected()):
    plc.disconnect()
If you import my helper S7200.py library from github the code is as follows:
import S7200 as p
plc = p.S7_200('10.10.55.250',0x1100,0x1100,debug=True)
plc.writeMem('QX0.0',True)
print plc.getMem('freal10')
plc.writeMem('freal10',3.141592653589)
print plc.getMem('freal10')
print plc.getMem('QX0.0')


  • This will turn on output 1 (Q0.0, will turn on if there's no ladder associated with it). 
  • Then read the real number stored in V memory 10. 
  • Then write pi to it ;-). 
  • Then read from it again.
  • Then read if output 1 (Q0.0) is on still\
Github for helper library found here:
https://github.com/SimplyAutomationized/raspberrypi/blob/master/S7-200pi/S7200.py



4 comments:

  1. Hi
    can you speci
    plc.set_connection_params('10.10.55.250',11,11)
    how to set them (11,11) ?

    ReplyDelete
  2. Hello,
    what type of Siemens is the gateway for TCP-IP for communicating with S7-200. Can you give me too correct 6SE7 ... number
    Thanks Stijn

    ReplyDelete
  3. How to read the V Memory location in the S7 200 PLC

    ReplyDelete