To download NI software, including the products shown below, visit ni.com/downloads.
Overview
This example provides a library of LabVIEW VI's that can be used to communicate with a Siemens S7-300 PLC via an Ethernet port over TCP/IP.
Description
This example communicates with a S7-300 series PLC through Ethernet TCP/IP - no adapter is needed. The example provides an API to read from / write to registers on the PLC.
To my knowledge, Siemens has never released the details of the S7 protocol. Much of what is publicly available on S7 is based on observations of the protocol by others. There is an open source S7 data exchange package available at http://libnodave.sourceforge.net/ that documents many S7 features.
These VIs were based upon the example posted at http://decibel.ni.com/content/docs/DOC-5467. They were modified by observing and mimicking a S7 data exchange between a protocol converter and a S7-300 series PLC. The observations were accomplished with the wireshark network protocol analyzer, available at http://www.wireshark.org/ and the Wireshark Plugin für S7-Protokoll, available at http://sps-forum.de/showthread.php?p=202763.
Steps to Execute Code
The example contains two top-level VIs: S7Com_Once.vi and S7Com_W+R_Loop.vi.
1.S7Com_Once.vi performs one read or write per execution. It writes to the target PLC from an array of I32, it reads from the target PLC into an array of I32. The number of bytes written is proportional to the number of elements in the array to be written and the transport size parameter.
2.S7Com_W+R_Loop.vi regularly writes to and reads from a pair of DBs in the target PLC. In order to use it, your Step7 PLC project should provide two Data Blocks, DB11 and DB12. See the screen capture image db11&12.PNG for their layout. After downloading the DBs to your PLC, monitor and change DB VAlues with a VAT. As can be seen in the VI, the transfer size is DWORD.
3. For more information, refer to the Read Me included in the download.
Requirements
Software
LabVIEW 8.5 or Later
Hardware
Siemens S7-300
Download Versions
Siemens S7 TCP v3_3 LV 8_5.zip
This code is setup to be fault tolerant; i.e. - if a cable is disconnected or connection is lost the "S7_Error_Reconnect.vi" can be called to cleanup the bad connection and re-open a good connection. There are some optimizations for reading multiple registers from a single DB block.This code is derived from the Serial MPI S7 Protocol Exaple
S7Com_2009_11_06.zip
This code was provided by a fellow developer (thanks!) and uses a slightly different architecture.
Note - the attached files are experimental VIs provided for educational purposes only. No warrantee is expressed or implied. You should test your code and completely understand the implications of writing to or reading from an operating PLC.
**This document has been updated to meet the current required format for the NI Code Exchange.**
Description-Separate-2Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.
I tried this library with S7-300 and it works very very fine.
Does this library can be used with S7- 1500 PLCs?
If yes, Please provide necessary modifications in code.
Thanks in advance.
Rasesh J.Dave
Email : raseshjd@yahoo.com
Please refer to the context help of the driver VIs, and to our Dokuwiki which I linked to in my last post, it contains information on how to configure the driver for different PLC types (no source code changes needed):
https://dokuwiki.hampel-soft.com/kb/production/s7-communication/constants#plc_types
Since my last post here, we‘ve packaged the driver into a .vip and released it on vipm.io:
https://www.vipm.io/package/hse_lib_s7netcom/
DSH Pragmatic Software Development Workshops (Fab, Steve, Brian and me)
Release Automation Tools for LabVIEW (CI/CD integration with LabVIEW)
HSE Discord Server (Discuss our free and commercial tools and services)
DQMH® (Developer Experience that makes you smile )
Dear All,
I am able to perform Read and Write Operations with provided source code.
Now ,I would like to write array (~ 30 WORD) in single DB.
Please suggest necessary changes in VI.
I am using Siemens S7 TCP v3_3 LV 8_5.zip
Thanks in advance.
Rasesh J.Dave
raseshjd@yahoo.com
I'm sorry, we cannot give support for legacy VIs we did not create.
Feel free to give our open-source toolkit S7NetCom a try, maybe it helps with your problem. It is available via vipm.io.
If you think there is a bug in the S7NetCom toolkit, please create an issue at https://gitlab.com/hampel-soft/open-source/s7netcom/-/issues
For commercial support, please contact office@hampel-soft.com.
DSH Pragmatic Software Development Workshops (Fab, Steve, Brian and me)
Release Automation Tools for LabVIEW (CI/CD integration with LabVIEW)
HSE Discord Server (Discuss our free and commercial tools and services)
DQMH® (Developer Experience that makes you smile )
When I connect PLC with S7NetCom, there is an error as shown in the picture. Please help to answer it, thank you
When I change the execution of the TPKT-Read Packet.vi attribute to non-reentre, there will be no error, but there will be a delay when multiple PLCS fetch DB area
Dear All
I would like to communicate with the attached file 'S7Com_2009_11_06.zip' with S7-1500.
Could you inform the 'TPKT', 'TPDU' Packet and slot number?
is not working.
Could someone please help me to resolve this issue ?
Thanks in advance
@kim-momo can you share more details about the setup you used when running into the described error? I've created issue #29 in the S7NetCom driver's GitLab project, it'd be great if we could continue the discussion there. Thank you!
DSH Pragmatic Software Development Workshops (Fab, Steve, Brian and me)
Release Automation Tools for LabVIEW (CI/CD integration with LabVIEW)
HSE Discord Server (Discuss our free and commercial tools and services)
DQMH® (Developer Experience that makes you smile )