Basic python code with PLC

FUMMY

Member
Join Date
Feb 2017
Location
Newport
Posts
5
I like to understand and know how to write a basic python code to connect and interact with Siemens PLC S7-300 and S7-1200 using Snap7. Please kindly guide me on what to do step by step!
 
I like to understand and know how to write a basic python code to connect and interact with Siemens PLC S7-300 and S7-1200 using Snap7. Please kindly guide me on what to do step by step!

Step 1, learn python.
Step 2, Read the documentation on S7-300 and S7-1200, especially the communication options.
Step 3, Read the documentation on python modules.
Step 4, purchase the appropriate equipment.
Step 5, code and test.
 
sample python codes for testing and to interact / connect S7300 using snap7

Step 1, learn python.
Step 2, Read the documentation on S7-300 and S7-1200, especially the communication options.
Step 3, Read the documentation on python modules.
Step 4, purchase the appropriate equipment
----------------------------------------------------

Thank you for the reply....all the step 1 to step 4 have been attended to. I need a sample python codes for testing such like Basic Python Code to interact and connect Siemens PLC S7-300 OR s7-1200 using SNAP7
 
Step 1, learn python.
Step 2, Read the documentation on S7-300 and S7-1200, especially the communication options.
Step 3, Read the documentation on python modules.
Step 4, purchase the appropriate equipment
----------------------------------------------------

Thank you for the reply....all the step 1 to step 4 have been attended to. I need a sample python codes for testing such like Basic Python Code to interact and connect Siemens PLC S7-300 OR s7-1200 using SNAP7

Using that library that I link'd, this looks like an example:

https://github.com/gijzelaerr/python-snap7/blob/master/example/example.py
 
Basic Python Code to interact and connect Siemens PLC S7-300 OR s7-1200 using SNAP7

Thank you for the sample code. I am completely new on coding....
Please kindly share with me also a sample code in Linux style too
I wanted to know how this is working on Linux.
 
basic python code to communicate and interact with PLCs

Thank you.

I ran the code and changed the IP to my own but with no result. I ran it, no error but not sure if this is communicating.
please what of if I need to read a data (db), network connections from PLCs that was connected on a network. kindly send a sample code...thank you
 
Well you can't use the example as is, you'd need to modify it to work with your program, it even says in the comments.

If you back up a directory on the github link I provided there is a "boolean.py" example, maybe it will be easier.

I don't really know anything about Siemens PLC's or snap7. You're going to have to put in some effort yourself. Even if I did, I don't know anything about your specific hardware or application.
 
Thank you.

I ran the code and changed the IP to my own but with no result. I ran it, no error but not sure if this is communicating.

You need to do some basic testing, that should be obvious, and move on from there. If you still need help, you need to give us the details of your problems and details of your testing. If you can't do it with the hardware sitting in front of you, what makes you think we can help? You have not given us any details.

Here's a little basic troubleshooting advice, which should be obvious, but I'm going to tell you anyway. You don't know if it is communicating. What do you expect to see if it is communicating? Are you getting it? If you think you are getting it, but think it is in error, then make sure that you can't communicate and see if you get the same result. Unplug the Ethernet. Do you get the same result?
 
Basic Python Snap7 install

You are correct "dmroeder" and everyone thank you....Agreed. I need to report the error....
I tried to install using "pip install snap7" ...done!

At the moment...there is an error:

Traceback (most recent call last):
File "test_snap7.py", line 4, in <module>
from db_layouts import rc_if_db_1_layout
ImportError: No module named db_layouts
 
Like I said before, go back a directory on that github page (here) and start with the one that is called boolean.py, that one looks much simpler. We should start out trying to do the simplest thing possible, then build on it.

And FYI, the error is telling you that it is trying to find the file db_layouts.py, which is in the directory where you got example.py (link'd above).

I give you credit for taking the time to learn Python and although there is nothing wrong with jumping in and trying to figure this out, you should also be working on learning the basics at the same time. If you had went through that Learn Python link that I provided above (or any other class/book), this error would have been more obvious.

That being said, start off with the simple example and we'll go from there. We could probably even strip some stuff out of boolean.py to make it even simpler. Looking at that file, maybe start with this?

import snap7

plc = snap7.client.Client()
plc.connect('192.168.200.24', 0, 3)

# In this example boolean in DB 31 at byte 120 and bit 5 is changed. = 120.5
reading = plc.db_read(31, 120, 1) # read 1 byte from db 31 staring from byte 120
print reading
plc.disconnect()

Someone that knows snap7 better than myself might be able to advise you on the parameters that are in the read function.
 

Similar Topics

A simple PID simulator for my first steps with Python, might come in handy for some demos https://github.com/Destination2Unknown/PythonPID_Simulator
Replies
22
Views
10,844
Hi all, I have a noob question regarding data handling from sensors. I understand configurations and I/O mapping sensor input/output variables...
Replies
2
Views
218
Hello I am new here and new to PLC's, I wrote this program for a class that I am taking and my local tech school. The description is switch 7 will...
Replies
0
Views
411
Hello I am new here and new to PLC's, I wrote this program for a class that I am taking and my local tech school. The description is switch 7 will...
Replies
10
Views
1,965
I’m a bit stuck on HMI (KTP-1200) programming… See the picture attached. The PASS or FAIL box should only appear when the toggle switch is...
Replies
7
Views
1,066
Back
Top Bottom