PLC and Python Communication, HELP

I have some old S7-300 code that uses Tsend and Trecv to implement a UDP transfer. It worked on a S7-300 with a built in Ethernet port.
I wrote two FBs. One would do a read and the other a write.
The Tsend and Trecv are basically the S7's version of socket commands.
The main problem I see with my code is that it uses a combination of LD and STL so it won't work with S7-1200s or S7-1500s as the STL is different.


I used a different header than a Modbus TCP header. My header is 16 bytes long and ensures all the data is word or dword aligned unlike Modbus TCP.
https://deltamotion.com/peter/S7/Pndp-udp.zip
This code was used only a few times and was ignored after Profinet came out.
 
What's your OS? Can't you use Node-Red? I seem to remember seeing an S7 connector. Modbus is there for sure (I've used it.)

Good Luck!

(8{)} :) .)


Yosi
 
How can i communicate between delta plc with Ethernet support and python with pymodbu

I'm working on an DELTA PLC project and I'm trying to use modbus library to connect to plc
My first test is with a Delta DVP-12SE11R PLC and the connection is with the Modbus TCP/IP protocol. I have a python code written using pymodbustcp module. I have tested that code with a modbus slave simulator and it is working properly. Reading and wriying required registers on simulator. My question is when i connect a plc hardware to PC and provide ip address of plc and port number to python code and it will start reading and writing the registers i specified in code?

This is what i am using:
from pyModbusTCP.client import ModbusClient
c=ModbusClient(host='localhost',port=9999,auto_open=True)

regs=c.read_holding_registers(403705,1)
print("reading register values")


if regs:
print(regs)
else:
print("error")

print("write value to register")
a=int(input())
c.write_single_register(403705,a)
 
Hi,
there are at least three possible ways to communicate with a S7-1200.

1) Using a raw TCP connection
On plc side this is called open communication.
You have to configure a connection (active or passive), and to program the communication functions TSEND/TRECV.
On python side you can use the usual python sockects.
Seems easy, but you remind that TCP is a stream and you have to consider the different endianess in a Siemens plc.

2) Using native S7 protocol with additional communication library
On plc side you have to do nothing.
On python side you need an additional communication library which implements the S7 protocol.
For python this could be this:
https://pypi.python.org/pypi/python-snap7/

You get only access to not-optimized datablocks in your S7-1200.

3) Using Modbus TCP
On plc side you have to program the modbus function blocks.
On python side you'll need a modbus TCP library.


How do I proceed with the 3rd option to communicate with a PLC through my python code using modbus TCP?
 
How do I proceed with the 3rd option to communicate with a PLC through my python code using modbus TCP?

You call the MB_SERVER block from the Siemens library in the S7-1200, enter the data area at the MB_HOLD_REG parameter. Then you can read or write this data from your Python program using a Modbus TCP client library like PyModbus using holding registers. The disadvantage is that the MB_SERVER by default allows the Client to read and write the process image of the S7-1200.
 
I would look carefully at the snap solution Thomas posted a link to/
You don't want to use the TSEND and TRECV because then you would be writing the Ethernet code on both the PLC and whatever is running python.
Yes python can send data by bytes, words or what ever you want but python doesn't make it as easy as with C because python doesn't support structures. You need to pack data in python to build the header or learn how to unpack data to read the header.


It is easy to send a simple text message but harder to do something useful.
 
Salut Thomas_v2

Je n'ai déjà qu'à te remercier mon ami, tu m'as aidé de la même manière, j'ai pu réussir le changement de données !! Maintenant j'ai encore un doute, est-il possible de faire l'inverse ? C'est-à-dire l'automate qui envoie les données cette fois-ci ?

Merci beaucoup!!!!!!!!:DM
 

Similar Topics

Hello everybody! I found option for creating communication with Q series via python. But can't find any tips for connecting with PLC FX series...
Replies
3
Views
5,244
Hi, I need to create a Python script to exchange data with a PLC schneider modicon m580 via Ethernet cable, if anyone knows something and can help...
Replies
14
Views
4,514
Good day dear Experts! Is there a way to simulate a communication between a S7-1200 PLC and python script? I know this is possible physically...
Replies
3
Views
3,525
I'm currently a senior in college working on a senior design project involving PLCs and Raspberry Pi. We have data taken using the PLC that we...
Replies
14
Views
3,999
It is pretty easy to read data from xml, json or .csv files using python. Can Rockwell and/or Siemens trends be saved in any of these formats...
Replies
9
Views
3,035
Back
Top Bottom