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:

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 library so the code will now be as follows:

import snap7 as p

plc = p.client.Client()
print plc.get_connected()
If you import my helper library from github the code is as follows:
import S7200 as p
plc = p.S7_200('',0x1100,0x1100,debug=True)
print plc.getMem('freal10')
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: