PLCCom for S7 Class Library
First steps PLCCom for S7 .NET SDK
About this document
This document is intended to provide you with information about the provided functionalities. This is not a complete documentation, but a guide to help you getting started.
Further information can be found in
- Code examples within our Github repositories
- Code examples and FAQ on our website
- The online help (index.html) within the software package
All information is supplied without any liability. All rights reserved and subject to change. The contents of this document are protected under international copyright laws. Without prior written consent from the copyright holder, no part of this documentation may be reproduced by means of photocopying, microfilm or other processes, or transcribed or translated into another language or computer language in any form.
Note: All product names or other names or brands referred to in this documentation are the trademarks or registered trademarks of their respective owners and are the property of those copyright owners. Any mention of brands serves purely as an indication to the intended purpose.
What provides PLCCom for S7 SDK?
Plccom for S7 offers you the option of accessing address ranges with absolute addressing using Put/Get, as well as optionally accessing variables within optimized and non-optimized ranges using symbolic addressing (only in the Expert Symbolic Edition).
The driver can be integrated directly as a reference so that no API calls are necessary. PLCcom is platform independent and works on 32 as well as 64bit.
Within the scope of supply are various code examples to illustrate the connection between your application and different controllers. These examples can also be used in your own projects.
In its current version, PLCcom is compatible with S7 controllers (200, 300, 400, 1200, 1500, SoftSPS WinAC RTX as well as Logo! 0BA7 / 0BA8 / 0BA0 / 0BA1 / 0BA2) as well as CPUs from other manufacturers (e.g. VIPA 100V/200V/300V/300S, etc.)
Symbolic access is possible to S7 controllers of the 1200 and 1500 series.
The driver will be delivered with Code-Examples, which shows you how easy it is to connect the PLC to your application.
Communication:
Serial adapter MPI, Serial adapter PPI, MPI adapter USB, Ethernet TCP/IP, Green Cable (VIPA PLC only)
The following functions are also available (depending on the PLC type):
- Access via put/get or symbolic addressing (S7-1200 / 1500 series only)
- Password transfer to protected controllers with symbolic addressing
- Read datablocks, inputs, outputs, flags, timer, counter
- Subscribing to data areas (put/get) or variables (symbolic access)
- Subscribing of alarms
- Reading the actual alarm list
- Acknowledge alarms
- Multiple operations in a single function call. Every function returns a detailed result.
- Simultaneous access of multiple CPUs
- High performance access. Requests sent to the controller are reduced to the absolute necessary
- Internal functions to read and write certain PLC datatypes with ease
- Supply of the PLCcom dataserver for cyclically read accesses with event controlled notifications on value changes
- Start and stop functionality for the CPU
- Read serial number as well as firmware version
- Read position of key switches
- Read LED info
- Read and write PLC time
- Read system status list
- Read block list
- Read block lengths
- Backup blocks
- Restore blocks
- Restore blocks with changed block number
- Delete blocks
- Read block details like code, generation language, author and more
- Send connection password
- Read diagnostic data
- Auto Connect
- Asynchronous connect
- …and many more
Which programming platforms does PLCcom support?
PLCcom for S7 is available in the following .NET variants:
- .NET Framework 4.7.2
- .NET Framework 4.8
- .NET Standard 2.1
- .NET 5
- .NET 6
- .NET 7
- .NET 8
- .NET 9
- .NET 10
Which system components are required for the operation of PLCcom?
The following system components are required for the operation of PLCcom:
- Microsoft .net Framework 4.7.2 or higher (.net version)
- Microsoft .net 5.0 up to .net 10 (.net version)
To run the sample programs provided, you need the following programming tools:
- Visual Studio 2022 or higher (.net version)
Important information about using the .net version outside of Windows
Serial support is implemented within the current .net version with the System.IO.Ports dependency. Due to known lack of support for individual functionalities within the dependency, the following objects cannot be used outside of Windows:
- PLCCom.MPI_Device
- PLCCom.PPI_Device
Attempting to create an instance of the above classes outside of Windows results in a PlatformNotSupportedException.
Important notes for using PLCcom with S7-1200/1500 controllers
Prerequisites for the Put/Get access
It is possible to access inputs, outputs, flags, and non-optimized DBs. Access to an S7-1200 or 1500 is disabled by default. You must perform the following steps:
Up to firmware version 3.0 (S7-1500 and ET200SP) or 4.6 (S7-1200):
- Allow general access. In the Properties settings, under Protection, enable the option 'Allow access to PUT/GET communication from remote partner'.
- Enable access to your databases. Go to the database properties and disable 'optimized access'.
- Load into the PLC, done!
If the changes have no effect, use "advanced download to device" to load into the PLC.
Firmware version 3.1 (S7-1500, ET200SP, or S7-1200 G2) or 4.7 (S7-1200) and higher:
- Go to "Security settings" in the project navigation.
- Double-click on "Users and Roles."
- Select the "Roles" tab.
- Create a new role and assign it a name, for example, "HMI_Access."
- Open the "Runtime Rights" tab.
- Select the appropriate PLC in the "Function rights categories."
- Activate the "HMI access" access level in the "Function rights."
- Go to the "Users" tab in the "Users and roles" area.
- Activate the "Anonymous" user.
- Confirm the message displayed with "OK."
- Assign the newly created role to the anonymous user under "Assigned Roles."
- Open the "Device View."
- Go to the "Properties" of the CPU.
- Select "Protection & Security > Connection Mechanisms" in the area navigation.
- Activate the option "Allow access via PUT/GET communication by remote partners."
- Translate the project and transfer the changes to the CPU.
To perform symbolic access to Siemens S7-1200, S7-1500, or PLCSim with PLCcom, the following requirements apply:
TLS access (TIA version 17 or higher):
- Supports symbolic access to PLC and PLCSim
- S7-1200: Firmware from V4.5 tested up to V4.7 [TIA V21] *
- S7-1200 G2: Firmware from V4.0 tested up to V4.1 [TIA V21] *
- S7-1500: Firmware from V2.9 tested up to V4.1 [TIA V21] *
- Authentication possible using password or username/password
Legacy access (up to TIA version 16) ** :
- S7-1200: Firmware tested from V4.1 to V4.7 [TIA V21] *
- S7-1500: Firmware tested from V2.1 to V4.1 [TIA V21] *
- Symbolic access to PLC with password authentication
- Authentication possible (exception: no password-protected access to PLCSim)
* Tested and approved within the specified firmware versions. Older or newer versions have not been tested; functionality is not guaranteed.
** Depending on the firmware version, legacy access must be explicitly enabled within the controller.
Supported features depending on PLC type
Feature | S7-1200 | S7-1200 (G2) | S7-200 | S7-300 | S7-400 | S7-1200 | S7-1500 | WinAC RTX | Logo! |
Read data | |||||||||
Speed optimizations | |||||||||
Write data | |||||||||
Subscribe variables | native | native | via data server | via data server | via data server | via data server | via data server | via data server | via data server |
Read structures | |||||||||
Deep Lookup *6 | |||||||||
Read full data blocks | |||||||||
Deep Lookup *6 | |||||||||
TLS: verify server certificate | |||||||||
TLS: provide trusted server certificates | |||||||||
Advanced optimizations | |||||||||
Subscribing to alarms | *4) | *4) | |||||||
Reading actual alarms list | *4) | *4) | |||||||
Acknowledging alarms | *4) | *4) | |||||||
Reading data from multiple areas combined | |||||||||
Multiple read and write accesses in a common function call | |||||||||
Reading or writing multiple values simultaneously in different areas | |||||||||
Starting and stopping the CPU | |||||||||
Reading and setting the PLC system time | |||||||||
Get basic info from PLC e.g. Modell, ordernumber, Firmware etc. | |||||||||
Get mode and state from CPU | |||||||||
Get LEDs mode from PLC | |||||||||
Reading system status list SSL | |||||||||
Get diagnostic data | |||||||||
Unlocking a protected connection | *5) | ||||||||
Read a list of created PLC objects. | |||||||||
Read length of | |||||||||
Read a specific block in | |||||||||
Get specific | restricted | restricted | |||||||
Restore block data | |||||||||
Restore in | |||||||||
Delete blocks | |||||||||
|
*1) Legacy Communication not for S7-1200 G2 *2) WinAC RTX from version 2010 onwards *3) Logo! Controller from 0BA7 *4) Not available for S7-1200 *5) Connections to simulated controllers only without password *6) Subvariables directly from the result – even if only a parent node (DB/Struct/Array) was read. See: https://github.com/Indi-An/PLCcomforS7-examples-dotnet *7) Due to the lack of availability of S7-200 SMART controllers within Europe, these controllers are not officially supported. | |||||||||
The following data types are supported for Put/Get optimized read and write functions:
| Data Type | Access |
|---|---|
| Raw (Byte Array) | Read and Write |
| Bit | Read and Write |
| Byte | Read and Write |
| Word | Read and Write |
| DWord | Read and Write |
| LWord | Read and Write |
| INT | Read and Write |
| DINT | Read and Write |
| LINT | Read and Write |
| Real | Read and Write |
| LReal | Read and Write |
| BCD8 | Read and Write |
| BCD16 | Read and Write |
| BCD32 | Read and Write |
| BCD64 | Read and Write |
| Date | Read and Write |
| Time | Read and Write |
| LTime | Read and Write |
| Date_And_Time | Read and Write |
| LDate_And_Time | Read and Write |
| Time_OF_DAY | Read and Write |
| LTime_OF_DAY | Read and Write |
| DTL | Read and Write |
| S5Time | Read and Write |
| Char | Read and Write |
| String | Read and Write |
| S7_String | Read and Write |
| S7_WString | Read and Write |
The following data types are supported for symbolic optimized read and write functions:
| Data Type | Access |
|---|---|
| Array[n..m] | Read and Write the entire structure or individual elements |
| Bool | Read and Write |
| Byte | Read and Write |
| Word | Read and Write |
| DWord | Read and Write |
| LWord | Read and Write |
| SInt | Read and Write |
| Int | Read and Write |
| DInt | Read and Write |
| LInt | Read and Write |
| USInt | Read and Write |
| UInt | Read and Write |
| UDInt | Read and Write |
| ULInt | Read and Write |
| Real | Read and Write |
| LReal | Read and Write |
| Date | Read and Write |
| Time | Read and Write |
| LTime | Read and Write |
| Date_And_Time | Read and Write |
| LDate_And_Time | Read and Write |
| Time_Of_Day | Read and Write |
| LTime_Of_Day | Read and Write |
| S5Time | Read and Write |
| Char | Read and Write |
| WChar | Read and Write |
| String | Read and Write |
| WString | Read and Write |
| Timer | Read and Write |
| Counter | Read and Write |
| CREF | Read and Write the entire structure or individual elements |
| NREF | Read and Write the entire structure or individual elements |
| DTL | Read and Write the entire structure or individual elements |
| ErrorStruct | Read and Write the entire structure or individual elements |
| IEC_COUNTER | Read and Write the entire structure or individual elements |
| IEC_DCOUNTER | Read and Write the entire structure or individual elements |
| IEC_LCOUNTER | Read and Write the entire structure or individual elements |
| IEC_LTIMER | Read and Write the entire structure or individual elements |
| IEC_SCOUNTER | Read and Write the entire structure or individual elements |
| IEC_TIMER | Read and Write the entire structure or individual elements |
| IEC_UCOUNTER | Read and Write the entire structure or individual elements |
| IEC_UDCOUNTER | Read and Write the entire structure or individual elements |
| IEC_ULCOUNTER | Read and Write the entire structure or individual elements |
| IEC_USCOUNTER | Read and Write the entire structure or individual elements |
| Struct | Reading permitted for the entire structure or individual elements, writing only for individual elements |
Passing the license key:
Before using the PLCcom library, you must have a license key for the current version. You can either purchase this license key as a time-limited trial key or purchase a license key in advance.
This license key must be passed to the library as follows:
C#//Note: with blank fields the library runs 15 minutes during a debugging session. authentication.User = "your user name"; authentication.Serial = "your user serial key";VB'Note: with blank fields the library runs 15 minutes during a debugging session. authentication.User = "your user name" authentication.Serial = "your user serial key"
First programming steps:
Embedding the PLCcom library in your project couldn’t be easier. It’s done with a few lines of code as shown in this few steps:
Syntax: Create and initialize PLCcom-device-Object
Example Put/Get Access
C#PLCcomDevice device = new TCP_ISO_Device("192.168.1.100", 0, 2, ePLCType.S7_300_400_compatibel);VBDim device As PLCcomDevice = New TCP_ISO_Device("192.168.1.2", 0, 2, ePLCType.S7_300_400_compatibel)
Example Symbolic Access
C#// Create a device object for the modern TLS access (TIA version 17 or higher) SymbolicDevice mySymbolicDevice = new Tls13Device("192.168.1.10"); // Connect ConnectResult connectResult = mySymbolicDevice.Connect(); if (connectResult.Quality != OperationResult.eQuality.GOOD) { Console.WriteLine($"Connect not successfull! Quality: {connectResult.Quality} Message: {connectResult.Message}"); return; }VB' Create a device object for the modern TLS access (TIA version 17 or higher) Dim mySymbolicDevice As SymbolicDevice = New Tls13Device("192.168.1.10") ' Connect Dim connectResult As ConnectResult = mySymbolicDevice.Connect() If connectResult.Quality <> OperationResult.eQuality.GOOD Then Console.WriteLine($"Connect not successfull! Quality: {connectResult.Quality} Message: {connectResult.Message}") Return End If
Optimized reading and writing of data
For optimized reading and writing, the read and write accesses in a ReadWriteRequestSet object are grouped together.
The optimized access to the PLC data is initialized via one or more ReadDataRequest and / or WriteDataRequest objects.
These requests are passed to the ReadWriteRequestSet-Object and triggered with the command ReadWriteData and processed optimally on request.
The result of the operation is returned to the developer as ReadWriteResultSet, where the individual ReadDataResult and / or WriteDataResult objects are located for further evaluation.
Note: Function not available for PPI connections, please refer to the function overview on our website www.plccom.net
Optimization options
The ReadWriteRequestSet object has been equipped with various parameterization and optimization options. The method RequestSet.SetOperationOrder(eOperationOrder) can be used to specify whether the write or read accesses are performed first. By default, the data is first written and then read. The following methods are used to parameterize the data optimization to be performed: RequestSet.SetReadOptimizationMode(eReadOptimizationMode) and RequestSet.SetWriteOptimizationMode(eWriteOptimizationMode).
By default, the optimizations are disabled "NONE".
The enum eReadOptimizationMode has the following members:
- NONE:
No optimization, all read requests are read one after the other. Safe but slow. - CROSS_AREAS:
In CROSS_AREAS mode, the read requests are merged across areas. Advantage: fragmented areas (e.g., data across multiple datablocks) can be read and written simultaneously - COMBINE_AREAS:
In COMBINE_AREAS mode, read requests from the same areas are combined. Advantage: Fast and high-performance access to data of the same areas (for example, data in the same datablock) - AUTO:
PLCcom automatically selects the best optimization method. Only the minimum required PLC read accesses are carried out.
Only in Expert edition available
The enum eWriteOptimizationMode has the following members:
- NONE:
No optimization, all read requests are written one after the other. Safe but slow. - CROSS_AREAS:
In CROSS_AREAS mode, the read requests are merged across areas. Advantage: fragmented areas (e.g. data across multiple datablocks) can be read and written simultaneously
Example
C#PLCcomDevice device = new TCP_ISO_Device("192.168.1.100", 0, 2, ePLCType.S7_300_400_compatibel); ReadWriteRequestSet myRequestSet = new ReadWriteRequestSet(); //set optimize options myRequestSet.SetOperationOrder(eOperationOrder.WRITE_BEVOR_READ); myRequestSet.SetReadOptimizationMode(eReadOptimizationMode.AUTO); myRequestSet.SetWriteOptimizationMode(eWriteOptimizationMode.CROSS_AREAS); //declare a ReadRequest object set the request parameters, //in this case => read 10 Bytes from DB1 at Byte 0 ReadDataRequest readRequest = new ReadDataRequest(eRegion.DataBlock, //Region 1, //DB only for datablock operations otherwise 0 0, //read start adress eDataType.BYTE, //desired datatype 10); //Quantity of reading values //add the read request to the request set myRequestSet.AddRequest(readRequest); //declare a WriteRequest object set the request parameters, //in this case => write 4 bytes to DB100 at address 0 WriteDataRequest myWriteRequest = new WriteDataRequest(eRegion.DataBlock, //Region 100, //DB 0); //start address //add writable Data here //in this case => write 4 bytes in DB100 myWriteRequest.addByte(new byte[] { 11, 12, 13, 14 }); //add the write request to the request set myRequestSet.AddRequest(myWriteRequest); //....... add more requests to request set //read, write and getting the results ReadWriteResultSet results = device.ReadWriteData(myRequestSet); // evaluate the results of read operations... foreach (ReadDataResult res in results.GetReadDataResults()) { //for getting read results see chapter simple read } //...and evaluate the results of write operations foreach (WriteDataResult res in results.GetWriteDataResults()) { //for getting write results see chapter simple write }VBDim device As PLCcomDevice = New TCP_ISO_Device("192.168.1.100", 0, 2, ePLCType.S7_300_400_compatibel) Dim myRequestSet As ReadWriteRequestSet = New ReadWriteRequestSet() //set optimize options myRequestSet.SetOperationOrder(eOperationOrder.WRITE_BEVOR_READ) myRequestSet.SetReadOptimizationMode(eReadOptimizationMode.AUTO) myRequestSet.SetWriteOptimizationMode(eWriteOptimizationMode.CROSS_AREAS) 'declare a ReadRequest object set the request parameters, 'in this case => read 10 Bytes from DB1 at Byte 0 Dim readRequest As ReadDataRequest = New ReadDataRequest(eRegion.DataBlock, _ 1, _ 0, _ eDataType.[BYTE], _ 10) 'add the read request to the request set myRequestSet.AddRequest(readRequest) Dim myWriteRequest As WriteDataRequest = New WriteDataRequest(eRegion.DataBlock, 100, 0) 'add writable Data here 'in this case => write 4 bytes in DB100 myWriteRequest.addByte(New Byte() { 11, 12, 13, 14 }) 'add the write request to the request set myRequestSet.AddRequest(myWriteRequest) '....... add more requests to request set 'read, write and getting the results Dim results As ReadWriteResultSet = device.ReadWriteData(myRequestSet) 'evaluate the results of read operations... For Each res As ReadDataResult In results.GetReadDataResults() 'for getting write results see chapter simple write Next '...and evaluate the results of write operations For Each res As WriteDataResult In results.GetWriteDataResults() 'for getting write results see chapter simple write Next
Optimized reading of symbolic variables
In the current version of PLCcom for S7, symbolic read access via ReadSymbolicRequest can be optimized to reduce the number of PLC read operations when reading many variables. This can improve cycle time and reduce network overhead.
Optimization is enabled by passing an additional parameter to the constructor of ReadSymbolicRequest. If no optimization mode is specified, eSymbolicReadOptimizationMode.NONE is applied automatically.
Note: The optimization mode only affects symbolic read access. Write access is not affected.
Limitations:- The optimization options are only available in the Expert Edition.
- The SMART optimization mode is only available for TLS access (SymbolicDevice is Tls13Device).
The enum eSymbolicReadOptimizationMode provides the following members (in ascending order of optimization strength):
- NONE: No optimization. Each variable is read individually (maximum transparency, slower for large variable sets).
- OBJECT_BASED: PLCcom can group variables within a root object (e.g., within the same data block/structure/array).
- CROSS_OBJECT: Like OBJECT_BASED, variables can also be grouped across multiple root objects (e.g., multiple data blocks).
- SMART: Intelligent execution plan for best performance (TLS only with Tls13Device).
During the first read operation with a ReadSymbolicRequest, PLCcom creates an internal execution plan based on the chosen optimization mode and caches it for reuse. This plan is discarded as soon as the variable list in the request changes (e.g., variables are added/removed/modified). Therefore, optimizations are most beneficial when the same request instance is reused across cycles; the first read may be noticeably slower than subsequent cycles.
❌ Example Wrong: Recreate request in each cycle
✅ Example Correct: Create request once, then reuse itC#// The plan is recreated in each cycle -> unnecessary overhead for (int i = 0; i < 1000; i++) { var req = new ReadSymbolicRequest(eSymbolicReadOptimizationMode.CROSS_OBJECT); req.AddFullVariableName("DataBlock_1.ByteValue"); req.AddFullVariableName("DataBlock_1.RealValue"); req.AddFullVariableName("DataBlock_1.SIntValue"); req.AddFullVariableName("DataBlock_1.UDIntValue"); var res = mySymbolicDevice.ReadData(req); // ... evaluation ... }VB' The plan is recreated in each cycle -> unnecessary overhead For i As Integer = 0 To 999 Dim req As New ReadSymbolicRequest(eSymbolicReadOptimizationMode.CROSS_OBJECT) req.AddFullVariableName("DataBlock_1.ByteValue") req.AddFullVariableName("DataBlock_1.RealValue") req.AddFullVariableName("DataBlock_1.SIntValue") req.AddFullVariableName("DataBlock_1.UDIntValue") Dim res = mySymbolicDevice.ReadData(req) ' ... evaluation ... Next
C#// Create request once (plan is built during the first read) var reqReuse = new ReadSymbolicRequest(eSymbolicReadOptimizationMode.CROSS_OBJECT); reqReuse.AddFullVariableName("DataBlock_1.ByteValue"); reqReuse.AddFullVariableName("DataBlock_1.RealValue"); reqReuse.AddFullVariableName("DataBlock_1.SIntValue"); reqReuse.AddFullVariableName("DataBlock_1.UDIntValue"); // Then read again (subsequent cycles benefit from the plan) for (int i = 0; i < 1000; i++) { var res = mySymbolicDevice.ReadData(reqReuse); // ... evaluation ... }VB' Create request once (plan is built during the first read) Dim reqReuse As New ReadSymbolicRequest(eSymbolicReadOptimizationMode.CROSS_OBJECT) reqReuse.AddFullVariableName("DataBlock_1.ByteValue") reqReuse.AddFullVariableName("DataBlock_1.RealValue") reqReuse.AddFullVariableName("DataBlock_1.SIntValue") reqReuse.AddFullVariableName("DataBlock_1.UDIntValue") ' Then read again (subsequent cycles benefit from the plan) For i As Integer = 0 To 999 Dim res = mySymbolicDevice.ReadData(reqReuse) ' ... evaluation ... Next
Complete Example
C#// Create a device object for the modern TLS access (TIA Version 17 or higher). SymbolicDevice mySymbolicDevice = new Tls13Device("192.168.1.100"); // Or, if you want to use the legacy access for older TIA / firmware versions: // SymbolicDevice mySymbolicDevice = new LegacySymbolicDevice("192.168.1.100"); // Connect ConnectResult connectResult = mySymbolicDevice.Connect(); if (connectResult.Quality != OperationResult.eQuality.GOOD) { Console.WriteLine(string.Concat( "Connect not successful! Quality: ", connectResult.Quality, " Message: ", connectResult.Message)); return; } // Choose an optimization mode. // You can change this single line to test the impact on performance. eSymbolicReadOptimizationMode optimizationMode = eSymbolicReadOptimizationMode.CROSS_OBJECT; // Build request (the optimization mode is applied here). ReadSymbolicRequest readRequest = new ReadSymbolicRequest(optimizationMode); readRequest.AddFullVariableName("DataBlock_1.ByteValue"); readRequest.AddFullVariableName("DataBlock_1.RealValue"); readRequest.AddFullVariableName("DataBlock_1.SIntValue"); readRequest.AddFullVariableName("DataBlock_1.UDIntValue"); // Read from device var readResult = mySymbolicDevice.ReadData(readRequest); // Print values foreach (PlcCoreVariable variable in readResult.Variables) { Console.WriteLine(string.Concat( variable.VariableDetails.FullVariableName, " Value: ", variable.Value)); }VB' Create a device object for the modern TLS access (TIA Version 17 or higher). Dim mySymbolicDevice As SymbolicDevice = New Tls13Device("192.168.1.100") ' Or, if you want to use the legacy access for older TIA / firmware versions: ' Dim mySymbolicDevice As SymbolicDevice = New LegacySymbolicDevice("192.168.1.100") ' Connect Dim connectResult As ConnectResult = mySymbolicDevice.Connect() If connectResult.Quality <> OperationResult.eQuality.GOOD Then Console.WriteLine(String.Concat( "Connect not successful! Quality: ", connectResult.Quality, " Message: ", connectResult.Message)) Return End If ' Choose an optimization mode. ' You can change this single line to test the impact on performance. Dim optimizationMode As eSymbolicReadOptimizationMode = eSymbolicReadOptimizationMode.CROSS_OBJECT ' Build request (the optimization mode is applied here). Dim readRequest As New ReadSymbolicRequest(optimizationMode) readRequest.AddFullVariableName("DataBlock_1.ByteValue") readRequest.AddFullVariableName("DataBlock_1.RealValue") readRequest.AddFullVariableName("DataBlock_1.SIntValue") readRequest.AddFullVariableName("DataBlock_1.UDIntValue") ' Read from device Dim readResult = mySymbolicDevice.ReadData(readRequest) ' Print values For Each variable As PlcCoreVariable In readResult.Variables Console.WriteLine(String.Concat( variable.VariableDetails.FullVariableName, " Value: ", variable.Value)) Next
Start PLC
A PLC can be started by calling StartPLC(). An OperationResult object is received as the result.
Not available for all CPUs. Please note the function overview on our website https://www.indi-an.com/en/plccom/for-s7/overview-of-features/.
Example
C#OperationResult res = device.StartPLC();VBDim res As OperationResult = device.StartPLC()
Stop PLC
A PLC can be stopped by calling StopPLC(). An OperationResult object is received as the result.
Not available for all CPUs. Please note the function overview on our website https://www.indi-an.com/en/plccom/for-s7/overview-of-features/.
Example
C#OperationResult res = device.StopPLC();VBDim res As OperationResult = device.StopPLC()
Get PLC time
To get the current time of the PLC you can use the function getPLCClockTime(). A PLCClockTimeResult object will be returned.
Not available for all CPUs. Please note the function overview on our website https://www.indi-an.com/en/plccom/for-s7/overview-of-features/.
Example
C#PLCClockTimeResult res = device.GetPLCClockTime();VBDim res As PLCClockTimeResult = device.GetPLCClockTime()
Set PLC time
The time of the PLC can be set by using the SetPLCClickTime command. A date object has to be given as a parameter to the function. A PLCClockTimeResult object will be returned as the result.
Not available for all CPUs. Please note the function overview on our website https://www.indi-an.com/en/plccom/for-s7/overview-of-features/.
Example
C#OperationResult res = device.SetPLCClockTime(DateTime.Now);VBDim res As OperationResult = device.SetPLCClockTime(DateTime.Now)
Get basic PLC information
With the command GetBasicInfo you can get information like type, module version or firmware version of the CPU. A BasicInfoResult object is returned as the result.
Not available for all CPUs. Please note the function overview on our website https://www.indi-an.com/en/plccom/for-s7/overview-of-features/.
Example
C#BasicInfoResult res = device.GetBasicInfo();VBDim res As BasicInfoResult = device.GetBasicInfo()
Get CPU mode
To get the current mode of the CPU (e.g. run, startup, stop, etc.) you can use the command GetCPUMode. A CPUModeInfoResult object will be returned as the result.
Not available for all CPUs. Please note the function overview on our website https://www.indi-an.com/en/plccom/for-s7/overview-of-features/.
Example
C#CPUModeInfoResult res = device.GetCPUMode();VBDim res As CPUModeInfoResult = device.GetCPUMode()
Get LED state
To get the current LED state (e.g. on, off, flashing, etc.) you can use the command GetLEDInfo. A LEDInfoResult object will be returned as the result
Not available for all CPUs. Please note the function overview on our website https://www.indi-an.com/en/plccom/for-s7/overview-of-features/.
Example
C#LEDInfoResult res = device.GetLEDInfo();VBDim res As LEDInfoResult = device.GetLEDInfo()
Get system status list
The function GetSystemStatusList enables you to access the system status list in the PLC. For further information on the system status list contact the PLC manufacturer or read the corresponding manual.
As a result a SystemStatusList object will be returned.
Not available for all CPUs. Please note the function overview on our website https://www.indi-an.com/en/plccom/for-s7/overview-of-features/.
Example
C#SystemStatusListResult res = device.GetSystemStatusList(SSL_ID, SSL_Index);VBDim res As SystemStatusListResult = device.GetSystemStatusList(SSL_ID, SSL_Index)
Get diagnostic info
The command GetDiagnosticInfo serves for requesting the current diagnostic data list from the CPU. As the result a DiagnosticInfoResult object will be returned.
Not available for all CPUs. Please note the function overview on our website https://www.indi-an.com/en/plccom/for-s7/overview-of-features/.
Example
C#DiagnosticInfoResult res = device.GetDiagnosticInfo();VBDim res As DiagnosticInfoResult = device.GetDiagnosticInfo()
PLCcom data server (only in expert version)
With the PLCcom data server you’re able to monitor memory ranges on the PLC. Whenever data changes an event is fired to inform the user. The communication between PLCcom and the PLC is optimized in a way that needed requests are reduced to a minimum.
Furthermore it’s possible to define connectors for filesystem or SQL database logging. It’s also possible to save an image of current variables and values into the filesystem or SQL database. For extended security these data can be stored encrypted. Methods for decryption are enclosed.
Example
C#PLCcom.PLCComDataServer.PLCComDataServer myDataServer = null; PLCcomDevice device = null; Console.WriteLine("Start Connect to TCPIP device..."); //Create an PLCcom-device instance device = new TCP_ISO_Device("192.168.1.100", 0, 2, ePLCType.S7_300_400_compatibel); //set autoconnect to true and idle time till disconnect to 10000 milliseconds device.setAutoConnect(true, 10000); //Create an instance depending on the device type Console.WriteLine("Create DataServer PLCDataServerTCP1..."); myDataServer = new PLCcom.PLCComDataServer.PLCComDataServer_TCP("PLCDataServerTCP1", (TCP_ISO_Device)device, 500); //register incoming events myDataServer.OnConnectionStateChange += new PLCcom.PLCComDataServer.PLCComDataServer.ConnectionStateChangeEventHandler(myDataServer_OnConnectionStateChange); myDataServer.OnReadDataResultChange += new PLCcom.PLCComDataServer.PLCComDataServer.ReadDataResultChangeEventHandler(myDataServer_OnReadDataResultChange); myDataServer.OnIncomingLogEntry += new PLCcom.PLCComDataServer.PLCComDataServer.OnIncomingLogEntryDelegate(myDataServer_OnIncomingLogEntry); //define new request Console.WriteLine("Create new Request Read 4 Bytes from DB1 at address 0 ..."); ReadDataRequest RequestItem1 = new ReadDataRequest(eRegion.DataBlock, //Region 1, //datablock 0, //startAdress eDataType.BYTE, //target data type 4); //Quantity //add new request to plccom data server myDataServer.AddReadDataRequest(RequestItem1, "Request1"); //define new request Console.WriteLine("Create new Request Read 10 DWord from Flags_Markers at address 4 ..."); ReadDataRequest RequestItem2 = new ReadDataRequest(eRegion.Flags_Markers, //Region 0, //datablock 4, //startAdress eDataType.DWORD, //target data type 4); //Quantity //add new request to plccom data server myDataServer.AddReadDataRequest(RequestItem2, "Request2"); //add one or more Logging connectors with logging and writing of a data image into filesystem or database //in this case create a new FileSystemConnector instance PLCcom.ExternalLogging.LoggingConnector con = new PLCcom.ExternalLogging.FileSystemConnector( System.Threading.Thread.GetDomain().BaseDirectory, //Target folder "FileSystemConnector1", //unique connector name ';', //text separator recommendation ';' true, //activate progressive logging true, //activate image writing PLCcom.ExternalLogging.eImageOutputFormat.dat, //output format .dat or .xml 10, //restrict the maximum number of files. -1 = Disabled. 24, //restrict the maximum age of files. -1 = Disabled. 30, //restrict the maximum size of files. -1 = Disabled. string.Empty); //If you enter an encryption password, the data is stored in encrypted form. //add Connector to Dataserver myDataServer.AddOrReplaceLoggingConnector(con); //start PLCcom data server myDataServer.StartServer(); Console.ReadLine(); //stop PLCcom data server myDataServer.StopServer();VBDim myDataServer As PLCcom.PLCComDataServer.PLCComDataServer = Nothing Dim device As PLCcomDevice = Nothing Console.WriteLine("Start Connect to TCPIP device...") 'Create an PLCcom-device instance device = New TCP_ISO_Device("192.168.1.2", 0, 2, ePLCType.S7_300_400_compatibel) 'set autoconnect to true and idle time till disconnect to 10000 milliseconds device.setAutoConnect(True, 10000) 'Create an instance depending on the device type Console.WriteLine("Create DataServer PLCDataServerTCP1...") myDataServer = New PLCcom.PLCComDataServer.PLCComDataServer_TCP("DataServerTCP1", DirectCast(device, TCP_ISO_Device), 500) 'register incoming events AddHandler myDataServer.OnConnectionStateChange, AddressOf myDataServer_OnConnectionStateChange AddHandler myDataServer.OnReadDataResultChange, AddressOf myDataServer_OnReadDataResultChange AddHandler myDataServer.OnIncomingLogEntry, AddressOf myDataServer_OnIncomingLogEntry Console.WriteLine("Create new Request Read 4 Bytes from DB1 at address 0 ...") 'Parameter: '-Region '-datablock '-startAdress '-target data type '-Quantity Dim RequestItem1 As New ReadDataRequest(eRegion.DataBlock, 1, 0, eDataType.[BYTE], 4) 'add new request to plccom data server myDataServer.AddReadDataRequest(RequestItem1, "Request1") Console.WriteLine("Create new Request Read 10 DWord from Flags_Markers at address 4 ...") 'Parameter: '-Region '-datablock '-startAdress '-target data type '-Quantity Dim RequestItem2 As New ReadDataRequest(eRegion.Flags_Markers, 0, 4, eDataType.DWORD, 4) 'add new request to plccom data server myDataServer.AddReadDataRequest(RequestItem2, "Request2") 'add one or more Logging connectors with logging and writing of a data image into filesystem or database. Parameter: '-Target folder '-unique connector name '-text separator recommendation ';' '-activate progressive logging '-activate image writing '-output format .dat or .xml '-restrict the maximum number of files. When the value is exceeded the old files are automatically deleted. -1 = Disabled. '-restrict the maximum age of files. When the value is exceeded the old files are automatically deleted. -1 = Disabled. '-restrict the maximum size of files. When the value is exceeded the old files are deleted. -1 = Disabled. '-If you enter an encryption password, the data is stored in encrypted form. Dim con As PLCcom.ExternalLogging.LoggingConnector = New PLCcom.ExternalLogging.FileSystemConnector(System.Threading.Thread.GetDomain().BaseDirectory, "FileSystemConnector1", _ ";"c, _ True, _ True, _ PLCcom.ExternalLogging.eImageOutputFormat.dat, _ 10, _ 24, _ 30, _ String.Empty) 'add Connector to Dataserver myDataServer.AddOrReplaceLoggingConnector(con) 'start PLCcom data server myDataServer.StartServer() Console.ReadLine() 'stop PLCcom data server myDataServer.StopServer()
Send password (only in expert version)
The function sendPassWord allows users to unlock password protected PLCs by passing the password to the function. An OperationResult object will be returned.
Not available for all CPUs. Please note the function overview on our website https://www.indi-an.com/en/plccom/for-s7/overview-of-features/.
Example
C#OperationResult res = device.sendPassWord("PW");VBDim res As OperationResult = device.sendPassWord("PW")
Get object list from PLC (only in expert version)
With the command GetBlockList you’re able to get a complete object list, or a list of specific block type (e.g. data block), from the PLC. A BlockListResult object is returned which contains all data.
Not available for all CPUs. Please note the function overview on our website https://www.indi-an.com/en/plccom/for-s7/overview-of-features/.
Example
C#BlockListResult res = device.GetBlockList(BlockType);VBDim res As BlockListResult = device.GetBlockList(BlockType)
Get length of an object (only in expert version)
The command GetBlockLength returns a BlockListLengthResult object containing the length of the requested object from the PLC.
Not available for all CPUs. Please note the function overview on our website https://www.indi-an.com/en/plccom/for-s7/overview-of-features/.
Example
C#BlockListLengthResult res = device.GetBlockLenght(BlockType, BlockNumber);VBDim res As BlockListLengthResult = device.GetBlockLenght(BlockType, BlockNumber)
Backup an object (only in expert version)
With the function ReadPLCBlock_MC7 the code of a specific block can be accessed and saved in mc7 format. Further block details like code, language, author, etc. are read. A ReadPLCBlockResult object will be returned.
Not available for all CPUs. Please note the function overview on our website https://www.indi-an.com/en/plccom/for-s7/overview-of-features/.
Example
C#eBlockType BlockType = eBlockType.FB; int BlockNumber = 1; //open SaveFileDialog SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "*.mc7|*.mc7|*.bin|*.bin|*.*|*'.*"; DialogResult dr = sfd.ShowDialog(); if (dr == DialogResult.OK) { //read Block into ReadPLCBlockResult ReadPLCBlockResult res = device.ReadPLCBlock_MC7(BlockType, BlockNumber); if (res.Quality == OperationResult.eQuality.GOOD) { //save buffer in specified file System.IO.FileStream fs = new System.IO.FileStream(sfd.FileName, System.IO.FileMode.Create, System.IO.FileAccess.Write); fs.Write(res.Buffer, 0, res.Buffer.Length); fs.Close(); MessageBox.Show("Block " + BlockType.ToString() + BlockNumber.ToString() + "successful saved" + sfd.FileName, "", MessageBoxButtons.OK, MessageBoxIcon.Information); } }VBDim BlockType As eBlockType = eBlockType.FB Dim BlockNumber As Integer = 1 'open SaveFileDialog Dim sfd As New SaveFileDialog() sfd.Filter = "*.mc7|*.mc7|*.bin|*.bin|*.*|*'.*" Dim dr As DialogResult = sfd.ShowDialog() If dr = DialogResult.OK Then 'read Block into ReadPLCBlockResult Dim res As ReadPLCBlockResult = device.ReadPLCBlock_MC7(BlockType, BlockNumber) If res.Quality = OperationResult.eQuality.GOOD Then 'save buffer in specified file Dim fs As New System.IO.FileStream(sfd.FileName, System.IO.FileMode.Create, _ System.IO.FileAccess.Write) fs.Write(res.Buffer, 0, res.Buffer.Length) fs.Close() MessageBox.Show(("Block " + BlockType.ToString() + BlockNumber.ToString() + "successful_saved") + sfd.FileName, "", MessageBoxButtons.OK, MessageBoxIcon.Information) End If End If
Restore an object (only in expert version)
Supplemental to the backup function, the function WritePLCBlock_MC7 restores a backup file back into the PLC. It’s also possible to restore the data with a changed block number. To pass the data a WritePLCBlockRequest is used. An OperationResult object will be returned.
Not available for all CPUs. Please note the function overview on our website https://www.indi-an.com/en/plccom/for-s7/overview-of-features/.
Example
C#OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "*.mc7|*.mc7|*.bin|*.bin|*.*|*'.*"; DialogResult dr = ofd.ShowDialog(); if (dr == DialogResult.OK) { System.IO.FileStream fs = new System.IO.FileStream(ofd.FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read); byte[] buffer = new byte[fs.Length]; fs.Read(buffer, 0, (int)fs.Length); fs.Close(); WritePLCBlockRequest Requestdata = new WritePLCBlockRequest(buffer); //Write Buffer into PLC OperationResult res = device.WritePLCBlock_MC7(Requestdata); if (res.Quality == OperationResult.eQuality.GOOD) { MessageBox.Show("Block " + Requestdata.BlockInfo.Header.BlockType.ToString() + Requestdata.BlockInfo.Header.BlockNumber.ToString() + resources.GetString("successful_saved_PLC") + ofd.FileName, } }VBDim ofd As New OpenFileDialog() ofd.Filter = "*.mc7|*.mc7|*.bin|*.bin|*.*|*'.*" Dim dr As DialogResult = ofd.ShowDialog() If dr = DialogResult.OK Then Dim fs As New System.IO.FileStream(ofd.FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read) Dim buffer As Byte() = New Byte(fs.Length - 1) {} fs.Read(buffer, 0, CInt(fs.Length)) fs.Close() Dim Requestdata As New WritePLCBlockRequest(buffer) 'Write Buffer into PLC Dim res As OperationResult = device.WritePLCBlock_MC7(Requestdata) If res.Quality = OperationResult.eQuality.GOOD Then MessageBox.Show(("Block " + Requestdata.BlockInfo.Header.BlockType.ToString() + Requestdata.BlockInfo.Header.BlockNumber.ToString() + resources.GetString("successful_saved_PLC")) + ofd.FileName, "", MessageBoxButtons.OK, MessageBoxIcon.Information) End If End If
Delete an object (only in expert version)
The function DeleteBlock enables one to delete a specific PLC object. An OperationResult object with additional information will be returned.
Not available for all CPUs. Please note the function overview on our website https://www.indi-an.com/en/plccom/for-s7/overview-of-features/.
Example
C#OperationResult res = device.DeleteBlock(BlockType, BlockNumber);VBDim res As OperationResult = device.DeleteBlock(BlockType, BlockNumber)
Namespaces
| PLCcom | Global Namespace for PLCCom for S7 Assembly |
| PLCcom.Core | Core components shared by PLCcom for S7 (common infrastructure and utilities). |
| PLCcom.Core.S7Plus | S7+ core implementation (symbolic access, data model, and communication building blocks). |
| PLCcom.Core.S7Plus.AddressSpace | Address space and node handling for symbolic navigation and variable resolution. |
| PLCcom.Core.S7Plus.Alarm | Alarm and event related types for S7+ controllers. |
| PLCcom.Core.S7Plus.DataTypes | PLC data type definitions and conversion helpers for S7+ datatypes. |
| PLCcom.Core.S7Plus.Interfaces | Public interfaces used by the S7+ core (abstractions for extensibility and testing). |
| PLCcom.Core.S7Plus.Subscription | Subscription and cyclic read infrastructure for S7+ variables and events. |
| PLCcom.Core.S7Plus.Tls | TLS/security related helpers for encrypted S7+ communication. |
| PLCcom.Core.S7Plus.Variables | Variable model for S7+ (typed variables, metadata, and value handling). |
| PLCcom.Core.S7Plus.Variables.Arrays | Array variable types and array-specific handling for S7+. |
| PLCcom.Core.S7Plus.Variables.SparseArrays | Sparse array representations and helpers for efficient access to large arrays. |
| PLCcom.Core.S7Plus.Variables.Structs | Struct/UDT variable types and hierarchical child variable handling. |
| PLCcom.Core.S7Plus.Variables.Structs.Arrays | Arrays of structs and related typed handling for S7+. |
| PLCcom.Enums.S7Plus | Enumerations used by the S7+ API and implementation. |
| PLCcom.ExternalLogging | Extension of PLCCom namespace for logging in external databases or to the file system |
| PLCcom.PLCComDataServer | Extension of PLCCom namespace to create instances of PLCComDataServer objects |
| PLCcom.Requests.S7Plus | Request types for S7+ operations (read/write, browse, subscription, etc.). |
| PLCcom.Results.S7Plus | Result/response types returned by S7+ requests (read results, status, metadata). |