9

I am running a process on a S7-1200 plc and I need it to send a start signal to my python script, after the script is done running it needs to send something back to the plc to initiate the next phase. Oh, and it has to be done in ladder.

Is there a quick and dirty way to send things over profibus or am I better off using just a RS232 thing?

ZF007
  • 3,318
  • 8
  • 26
  • 39
Megimoo
  • 277
  • 1
  • 2
  • 14

7 Answers7

5

After failing with libnodave and OPC, I created a TCON,TSEND and TRECV communication thing. It transmits a byte over TCP and it works.

Megimoo
  • 277
  • 1
  • 2
  • 14
5

I would go with SNAP7 and python-snap7 libraries. Example on how to install it on a Raspberry pi found in this blog: http://simplyautomationized.blogspot.com/2014/12/raspberry-pi-getting-data-from-s7-1200.html

Update:

Video walkthrough on how to set it up: https://youtu.be/yJNEsI5KJxs

Entrabiter
  • 652
  • 7
  • 12
4

I would use libnodave on PC side to change value of some M tag or a DB tag in a PLC. You can easily make a ladder rung which will monitor this tag and execute further actions. Although libnodave doesn't support Python natively, you can find a python wrapper here.

avra
  • 3,671
  • 16
  • 19
  • I don't suppose you have an example of the wrapper in use? – Megimoo Apr 30 '12 at 13:01
  • I've tried various solutions with libnodave and all of them return in a -1 from connectPLC(). Someone on the internet claims it is because a change in the S7-1200 TCP layer, and I don't know enough C to change that in the dll. – Megimoo Apr 30 '12 at 21:24
  • If I remember well testISO_TCP.exe was working fine. I don't know about other connecting methods. I was just aware of Python wrapper, I didn't use it. I use libnodave with great success in Linux (GCC and FreePascal) and in Windows (Delphi, Lazarus/FPC). I don't have any S7 1200 to test it again, but someone already did with Android: http://www.automation-se.de/index.php/s7droid/s7droidlite. – avra May 04 '12 at 12:54
  • 2
    testISO_TCP.exe worked fine, however studying the source code and writing the exact same thing in python, it returned -1. I couldn't even establish a connection to the PLC. After a week or so of trying or failing, my teacher told me to not waste anymore time. Anyway the project is delivered now and I've learned a lot from trying to make these things work, so you deserve that +1. In the future I'll try to avoid anything made by Siemens. – Megimoo Jun 06 '12 at 13:46
  • @Megimoo, a lot of things improved over time, even in the S7 world. (not a sponsored comment ;p) – ZF007 Dec 23 '18 at 14:31
2

Well, a quick google of 'python rs232' turned up some site talking about doing robotics controls through rs232 using pySerial. So if you know how to hook your widget up to rs232, you could go that route.

John Gaines Jr.
  • 9,766
  • 1
  • 23
  • 25
2

There is a commercial library called "S7connector" by Rothenbacher GmbH (obviously it's not the "s7connector" on sourceforge). It is for the .NET framework, so could be used with IronPython.

It does work with S7-1200 PLCs. You just have to make sure a DB you want to read from / write to is not an optimized S7-1200 style DB, but a S7-300/400 compatible one, an option which you can set when creating a DB in TIA portal. This lib also allows to read and write all I/O ports - the "shadow registers" (not sure what they're called officially) and directly as well, overriding the former.

user1847129
  • 970
  • 1
  • 8
  • 20
2

There are several Modbus TCP Clients available for Python, I have used pyModbusTCP successfully. TIA Portal the IDE for the S7-1200 has Modbus Server function that you can load to your PLC that will allow you to read and write directly to the PLC.

https://support.industry.siemens.com/cs/ww/en/view/83130159

fredm
  • 21
  • 1
1

Ther best way to communicate with S7-1200 PLC cpu's is with OPC UA or Classic OPC (ommonly known as OPC DA. ) Libnodave is made for S7-300 and S7-400 not for S71200 (2.x firmware).

If you use a third party solution to communicate with S7-1200 (or S7-1500) you have to decrease the security level at the PLC by allowing the put and get mechanism. Put and get are pure evil to use. You open the memory of the CPU for every process. Don’t use them anymore. Siemens should actually block this.

This applies for all firmware release for S7-1200. Siemens pushes people you use OPC UA as default communication from PLC. What makes sense, because OPC UA is the protocol for industry 4.0 and IIoT.

Edit: rewrite everything. Info was heavily outdated. If you use a firmware 2 or 3 1200, consider replacement or upgrade. These versions are no longer supported and contains the worm issue.

  • "There is no way that you can communicate with the S7-1200 PLC cpu's without OPC" Not true. See my answer. – user1847129 Jun 05 '14 at 09:21
  • 1
    We are two firmware versions further then when this answer was made. OPC is also finally official released for the S7-1200 with non-optimised access only. –  Jun 06 '14 at 17:04
  • This answer relates to S7-1200 firmware V2.2 (Oct 2011) or older releases. Enjoy your `cleanup` badge ;) – ZF007 Dec 22 '18 at 13:32