Repository navigation
There are some program block in my TIA portal,is it possible to access it with Python-snap7?I am using plc 1200 #759
|
There are some program block in my TIA portal,is it possible to access it with Python-snap7?I am using plc 1200 |
Replies: 3 comments
|
Yes, you can access data blocks on an S7-1200 with python-snap7. Make sure PUT/GET communication is enabled in TIA Portal (PLC properties → Protection & Security → Connection mechanisms → Permit access with PUT/GET). For data blocks (DB), use import snap7
client = snap7.Client()
client.connect("192.168.0.1", 0, 1)
# Read 100 bytes from DB1 starting at offset 0
data = client.db_read(1, 0, 100)Note: the DB must have Optimized block access disabled in TIA (right-click DB → Properties → Attributes → uncheck "Optimized block access"), otherwise S7 protocol cannot address the data by byte offset. For program blocks (OB, FC, FB), you can upload the compiled block bytecode with from snap7.type import Block
data = client.full_upload(Block.FC, 1)This gives you the raw block binary — useful for backup/comparison, but not a human-readable TIA project export. python-snap7 cannot read the TIA Portal project file itself, only what is on the PLC over the network. |
|
One correction on the program-block part, for S7-1200 specifically. The data side above is right: with PUT/GET enabled and "Optimized block access" off, Reading program blocks (OB/FB/FC) is a different matter. The project's own documentation now says to treat block upload and download on S7-1200/1500 as unsupported unless you have verified it on your CPU and firmware (
Even on a CPU that allows it, an upload gives you the compiled block as raw bytes, not SCL/LAD source, and blocks with know-how protection stay protected. In practice, for an S7-1200:
|
|
Thanks @IDavinciCode, you're right, and my earlier answer was wrong about program blocks. Block upload isn't supported on S7-1200/1500 over classic S7 (see |
One correction on the program-block part, for S7-1200 specifically.
The data side above is right: with PUT/GET enabled and "Optimized block access" off,
db_read()/db_write()work on an S7-1200, and so do inputs, outputs and markers.Reading program blocks (OB/FB/FC) is a different matter. The project's own documentation now says to treat block upload and download on S7-1200/1500 as unsupported unless you have verified it on your CPU and firmware (
doc/plc-support.rst, "Feature Availability"). The hardware report in #907 shows why: a CPU 1212C, firmware V4.7.3, with PUT/GET enabled, serves DB reads and writes but refusesupload()with