PLCcom for S7 SDK class library documentation



PLCcom logo




First steps PLCCom for S7 Java 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:
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?

The PLCcom library is a highly performant and optimized component especially designed for Java / .Net-Developer to access data provided by a Siemens PLC in the most comfortable way. With PLCcom you can read and write data from a PLC with ease.

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).

Depending on the package the library consist purely of Java or .Net files. 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.)

The driver will be delivered with Code-Examples, which shows you how easy it is to connect the PLC to your application.

Communication:
Symbolic access is possible to S7 controllers of the 1200 and 1500 series.
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):

  • Reading timers
  • Access via put/get or symbolic addressing
  • User/Password transfer to protected controllers possible with symbolic addressing
  • Reading of data blocks, inputs, outputs, data blocks, flags, timers, counters
  • Several operations possible in one function call, each operation returns a detailed return value.
  • Simultaneous access to different CPUs possible
  • Implemented high-performance access, the required accesses to the PLC are reduced to the absolute minimum.
  • Internal help and conversion functions for simple reading and writing of certain PLC data types
  • Provision of the PLCcom data server for cyclical read accesses with event-controlled notification of value changes
  • Starting and stopping the CPU
  • Reading out the serial number and firmware version
  • Reading out the key switch position
  • Reading LED information
  • Reading and setting the PLC time
  • Reading the system status list
  • Reading the block list
  • Reading block lengths
  • Backup of blocks
  • Restoring blocks
  • Restoring blocks under a changed block number
  • Deleting blocks
  • Output of block details such as code, creation languages, author, etc.
  • Sending the connection password
  • Reading out the diagnostic data
  • AutoConnect
  • Asynchronous connection
  • Subscribing variables
  • Reading actual alarms list
  • Subscribing alarms
  • Acknowledge alarms
  • and much more.


Which programming platforms does PLCcom support?


PLCcom for S7 is available in different versions. This documentation covers the Java version, which provides developers with a Java component for Java application development (e.g. with Eclipse).

Which system components are required for the operation of PLCcom?


The following system components are required for the operation of PLCcom:
  • Java JRE / openJRE 11.23 or higher,tested up to Java 25
  • Android API 21 or higher (Java version, see chapter "Important notes for using PLCcom on Android")
To run the sample programs provided, you need the following programming tools:
  • Eclipse (current version)


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 S7-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):

  1. Allow general access. In the CPU properties, under Protection & Security, enable the option "Allow access to PUT/GET communication from remote partner".
  2. Enable access to your data blocks. Go to the DB properties and disable "optimized access".
  3. Download the changes to the PLC.

If the changes have no effect, use "advanced download to device" to load into the PLC.

Firmware version 3.1 (S7-1500, ET200SP, S7-1200 G2) or 4.7 (S7-1200) and higher:

  1. Go to "Security settings" in the project navigation.
  2. Double-click "Users and Roles" and select the "Roles" tab.
  3. Create a new role and assign it a name (e.g. "HMI_Access").
  4. Open the "Runtime Rights" tab, select the PLC under "Function rights categories", and activate the "HMI access" access level.
  5. Go to the "Users" tab and activate the "Anonymous" user. Confirm the message displayed with "OK".
  6. Assign the newly created role to the anonymous user under "Assigned Roles".
  7. Open "Device View" and go to the CPU Properties.
  8. In the area navigation, select "Protection & Security > Connection Mechanisms" and activate "Allow access via PUT/GET communication by remote partners".
  9. Translate the project and transfer the changes to the CPU.

To perform symbolic access to Siemens S7-1200, S7-1500 controllers 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.


Important notes for using PLCcom on Android


Due to the lack of serial ports, it is not possible to use the following objects on Android:

PLCCom.MPI_Device
PLCCom.PPI_Device

Attempting to create an instance of the above classes ends with an error of type java.lang.NoClassDefFoundError
Furthermore, the usage of the PLCCom.FileSystemConnector object must be at least Android API Version 26 or higher, in deviation to the above mentioned information.
Due to the general system conditions under Android, it is assumed that the use of the above-mentioned objects on Android does not matter and the restrictions are negligible.

Symbolic access is only supported on Android on an experimental basis. Unfortunately, no support can be provided for this.


Supported features depending on PLC type


Feature

S7-1200
S7-1500
ET200SP

Symbolic
Legacy Communication *1)

S7-1200 (G2)
S7-1500
ET200SP

Symbolic
Secure Communication

S7-200
(Put/Get) *7)

S7-300
(Put/Get)

S7-400
(Put/Get)

S7-1200
(Put/Get)

S7-1500
ET200SP

(Put/Get)

WinAC RTX
(Put/Get) *2)

Logo!
(Put/Get) *3)

Read data

Yes Yes Yes Yes Yes Yes Yes Yes Yes

Speed optimizations
combined area reads

Yes Yes Yes Yes Yes Yes Yes Yes Yes

Write data

Yes Yes Yes Yes Yes Yes Yes Yes Yes

Subscribe variables

Yes
native
Yes
native
Yes
via data server
Yes
via data server
Yes
via data server
Yes
via data server
Yes
via data server
Yes
via data server
Yes
via data server

Read structures

Yes Yes No No No No No No No

Read full data blocks
as structure

Yes Yes No No No No No No No

Deep Lookup *6

Yes Yes No No No No No No No

TLS: verify server certificate

Yes Yes No No No No No No No

Advanced optimizations
for fast symbolic reads

Yes Yes No No No No No No No

Subscribing to alarms

Yes
*4)
Yes
*4)
No No No No No No No

Reading actual alarms list

Yes
*4)
Yes
*4)
No No No No No No No

Acknowledging alarms

Yes
*4)
Yes
*4)
No No No No No No No

Reading data from multiple areas combined

Yes Yes Yes Yes Yes Yes Yes Yes Yes

Multiple read and write accesses in a common function call

Yes Yes No Yes Yes Yes Yes Yes Yes

Reading or writing multiple values simultaneously in different areas

Yes Yes No Yes Yes Yes Yes Yes Yes

Starting and stopping the CPU

Yes Yes Yes Yes Yes Yes Yes Yes Yes

Reading and setting the PLC system time

Yes Yes Yes Yes Yes No No Yes Yes

Get basic info from PLC e.g. Modell, ordernumber, Firmware etc.

Yes Yes Yes Yes Yes Yes Yes Yes Yes

Get mode and state from CPU

Yes Yes No Yes Yes No No Yes Yes

Get LEDs mode from PLC
(on, off, indicating)

Yes Yes No Yes Yes No No Yes No

Reading system status list SZL
(if existing)

No No No Yes Yes No No Yes No

Get diagnostic data

No No No Yes Yes No No Yes No

Unlocking a protected connection
via (user) password transfer

Yes
*5)
Yes Yes Yes Yes No No Yes No

Read a list of created PLC objects
(All or specific block type
e.g. only OBs)

Yes Yes Yes Yes Yes No No Yes No

Read length of
a specific block

No No Yes Yes Yes No No Yes No

Read a specific block in
MC7-format and save to a select file
(Backup)

No No Yes Yes Yes No No Yes No

Get specific
block properties e.g.
(version, author,
Create language and many more)

Yes
restricted
Yes
restricted
Yes Yes Yes No No Yes No

Restore block data
from a selectable MC7-file
(Restore)

No No Yes Yes Yes No No Yes No

Restore in
different blocks

No No Yes Yes Yes No No Yes No

Delete blocks

No No Yes Yes Yes No No Yes No
*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 entry
*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-java
*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
Struct Read and Write
Array[n..m] Read and Write
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
NREF Read and Write
DTL Read and Write
ErrorStruct Read and Write
IEC_COUNTER Read and Write
IEC_DCOUNTER Read and Write
IEC_LCOUNTER Read and Write
IEC_LTIMER Read and Write
IEC_SCOUNTER Read and Write
IEC_TIMER Read and Write
IEC_UCOUNTER Read and Write
IEC_UDCOUNTER Read and Write
IEC_ULCOUNTER Read and Write
IEC_USCOUNTER Read and Write


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:



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:



table1



Syntax: Create and initialize PLCcom-Device-Object

Example Put/Get Access

PLCcomDevice Device = new TCP_ISO_Device("192.168.1.100", 0, 2, ePLCType.S7_300_400_compatibel);
Example Symbolic Access

Tls13Device tlsDevice = new Tls13Device("192.168.1.100");

Create a simple PLCcom-Request e.g. read data

Example Put/Get Access

//read 10 Bytes from DB1 at adress 100
ReadDataRequest myReadDataRequest = 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
Example Symbolic Access

ReadSymbolicRequest readRequest = new ReadSymbolicRequest();
readRequest.addFullVariableName("DataBlock_1.ByteValue");
readRequest.addFullVariableName("DataBlock_1.RealValue");
readRequest.addFullVariableName("DataBlock_1.SIntValue");
readRequest.addFullVariableName("DataBlock_1.UDIntValue");

Syntax: Hand over the request to the PLCcom-Device and receive the result

Example Put/Get Access

ReadDataResult res = Device.readData(myReadDataRequest);
Example Symbolic Access

var readResult = tlsDevice.readData(readRequest);

Syntax: Process the result

Example Put/Get Access

if (res.Quality() == OperationResult.eQuality.GOOD) {
   for (Object item : res.getValues()) {
     System.out.println(item.toString());
   }
} 
Example Symbolic Access

if (readResult.getQuality() == OperationResult.eQuality.GOOD || readResult.getQuality() == OperationResult.eQuality.WARNING_PARTITIAL_BAD) {
        for (PlcCoreVariable variable : readResult.getVariables()) {
                System.out.println(variable.getVariableDetails().getFullVariableName() + " Value: " + variable.getValue());
        }
}

Feature overview


Simple reading data from the PLC


The reading of data is initialized by an ReadDataRequest and executed with the function ReadData(). The result is received as a ReadDataResult object.


table



Example Put/Get Access

PLCcomDevice Device = new TCP_ISO_Device("192.168.1.100", 0, 2, ePLCType.S7_300_400_compatibel);
//read 10 Bytes from DB1
ReadDataRequest myReadDataRequest = 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
                                
//read                          
ReadDataResult res = Device.readData(myReadDataRequest);

//evaluate results
if (res.Quality() == OperationResult.eQuality.GOOD) {
   int Position = 0;
   for (Object item : res.getValues()) {
     System.out.println(item.toString());
   }
} 
Example Symbolic Access

Tls13Device tlsDevice = new Tls13Device("192.168.1.100");

//read variable DataBlock_1.ByteValue and variable DataBlock_1.RealValue
ReadSymbolicRequest readRequest = new ReadSymbolicRequest();
readRequest.addFullVariableName("DataBlock_1.ByteValue");
readRequest.addFullVariableName("DataBlock_1.RealValue");
                                
//read                          
var readResult = tlsDevice.readData(readRequest);

//evaluate results
if (readResult.getQuality() == OperationResult.eQuality.GOOD || readResult.getQuality() == OperationResult.eQuality.WARNING_PARTITIAL_BAD) {
        for (PlcCoreVariable variable : readResult.getVariables()) {
                System.out.println(variable.getVariableDetails().getFullVariableName() + " Value: " + variable.getValue());
        }
}

Simple writing data to the PLC


The writing of data will be initialized by a WriteDataRequest object and executed by the WriteData() function. The response is a WriteDataResult object.


table



Example Put/Get Access

//declare a WriteRequest object and
//set the request parameters
WriteDataRequest myWriteRequest = new WriteDataRequest(eRegion.DataBlock,  //Region
                                100,               //DB                                                                     
                                0);            //write start address
            
//add writable Data here
//in  this case => write 4 bytes in DB100
myWriteRequest.addByte(new byte[]{11, 12, 13, 14});

//write
System.out.println("begin write...");
WriteDataResult res = Device.writeData(myWriteRequest);

//evaluate results
if (res.Quality().equals(OperationResult.eQuality.GOOD)) {
    System.out.println("Write successfull! Message: " + res.Message());
}

Example Symbolic Access

List writeVariables = new ArrayList();

/*
 * Before you can write, you need the imported variable. Either you have
 * determined it by a read operation or you have PLCCom output the empty
 * variable (without values)
 */
var variableBody = tlsDevice.getEmptyVariableBody("DataBlock_1.ByteValue");
// Set the value and add the variable to the write list
variableBody.setValue(1);
writeVariables.add(variableBody);

variableBody = tlsDevice.getEmptyVariableBody("DataBlock_1.RealValue");
// Set the value and add the variable to the write list
variableBody.setValue(123.456f);
writeVariables.add(variableBody);

// create a write request
WriteSymbolicRequest writeRequest = new WriteSymbolicRequest(writeVariables);

//write
var writeResult = tlsDevice.writeData(writeRequest);

//evaluate results
if (writeResult.getQuality().equals(OperationResult.eQuality.GOOD)) {
    System.out.println("Write successfull! Message: " + res.Message());
}
else {
                System.out.println("write not successfull! Message: " + writeResult.getMessage());
}


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





table



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

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 myReadDataRequest = 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(myReadDataRequest);

// 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); // startaddress

// 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...
for (ReadDataResult res : results.getReadDataResults()) {
        // for getting read results see chapter simple read
}
// ...and evaluate the results of write operations
for (WriteDataResult res : results.getWriteDataResults()) {
        // for getting write results see chapter simple write
}

Optimized reading of symbolic variables


In the current version of PLCcom for S7, symbolic read access of the request object (ReadSymbolicRequest) can also be optimized. The aim is to reduce the number of PLC read operations required when reading many variables, thereby improving cycle time and network overhead.

Optimization is activated via an additional parameter in the constructor of ReadSymbolicRequest. If no optimization mode is specified, eSymbolicReadOptimizationMode.NONE is automatically applied.
Note: Optimization mode only affects symbolic read accesses. Write accesses are 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).
Optimization possibilities (symbolic access)
The enum eSymbolicReadOptimizationMode has the following members (in ascending order of optimization strength):
  • NONE: No optimization. Each variable is read individually — maximum transparency, but slower with large amounts of variables.
  • OBJECT_BASED: PLCcom for S7 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, best performance. Available only with TLS access (Tls13Device).

Important note on using optimization for symbolic access

During the first read operation with a ReadSymbolicRequest, PLCcom for S7 creates a performance / execution plan (depending on the selected optimization mode) and saves it for reuse.
This plan is automatically discarded as soon as the variable list contained in the request changes (e.g., by adding / removing / changing variables).

Since plan creation requires additional resources and time, the optimizations are most beneficial when the same ReadSymbolicRequest is used multiple times without change; accordingly, the first read pass may be noticeably slower than subsequent cycles.

Example (Wrong): Recreate request in each cycle

// Assume: device is a connected SymbolicDevice (Tls13Device or LegacySymbolicDevice)
// The plan is recreated in each cycle - unnecessary overhead
for (int i = 0; i < 1000; i++) {
    ReadSymbolicRequest 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 = device.readData(req);
    // ... evaluation ...
}
Example (Correct): Create request once, then reuse it

// Assume: device is a connected SymbolicDevice (Tls13Device or LegacySymbolicDevice)
// Create request once (plan is built during the first read)
ReadSymbolicRequest 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");

// Then read again (subsequent cycles benefit from the plan)
for (int i = 0; i < 1000; i++) {
    var res = device.readData(req);
    // ... evaluation ...
}
Example: Optimized symbolic read with TLS device

// Create a device object for the modern TLS access (TIA Version 17 or higher).
SymbolicDevice device = new Tls13Device("192.168.1.100");

// Or, if you want to use the legacy access for older TIA / firmware versions:
// SymbolicDevice device = new LegacySymbolicDevice("192.168.1.100");

// Connect
ConnectResult connectResult = device.connect();
if (connectResult.getQuality() != OperationResult.eQuality.GOOD) {
    System.out.println("Connect not successful! Quality: " + connectResult.getQuality()
        + " Message: " + connectResult.getMessage());
    return;
}

// Choose an optimization mode (change this 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 = device.readData(readRequest);

// Print values
for (PlcCoreVariable variable : readResult.getVariables()) {
    System.out.println(variable.getVariableDetails().getFullVariableName()
        + " Value: " + variable.getValue());
}

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.plccom.net.




table



Example

OperationResult res = 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.plccom.net.




table



Example

OperationResult res = 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.plccom.net.




table



Example

PLCClockTimeResult res = 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.plccom.net.




table



Example

OperationResult res = Device.setPLCClockTime(Calendar.getInstance().getTime());

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.plccom.net.




table



Example

BasicInfoResult res = 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.plccom.net.




table



Example

CPUModeInfoResult res = 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.plccom.net.




table



Example

LEDInfoResult res = 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.plccom.net.




table



Example

SystemStatusListResult res = 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.plccom.net.




table



Example

DiagnosticInfoResult res = 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.


table



Example

PLCComDataServer myDataServer = null;
PLCcomDevice Device = null;

BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
System.out.println("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
System.out.println("Create DataServer PLCDataServerTCP1...");
myDataServer = new PLCComDataServer_TCP("PLCDataServerTCP1", (TCP_ISO_Device)Device, 500);
            
//register incoming events
// register Connection state change event
myDataServer.connectionStateChangeNotifier = new ConnectionStateChangeNotifier(this);
// register incoming log event
myDataServer.incomingLogEntryEventNotifier = new IncomingLogEntryEventNotifier(this);
// register change ReadDataResult event
myDataServer.readDataResultChangeNotifier = new ReadDataResultChangeNotifier(this);

//define new request
System.out.println("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
System.out.println("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 on or more Loggingconnector with logging and writing of a data image into filesystem or database
//in this case create a new FileSystemConnector instance
LoggingConnector con = new FileSystemConnector(new File(".").getAbsolutePath(), //Target folder
                                      "FileSystemConnector1",          //unique connector name
                                      ';',                             //text separator recommendation ';'
                                      true,                            //activate progressive logging
                                      true,                            //activate image writing
                                      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, //You can restrict the maximum size of files. -1 = Disabled.
                                      "");//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();
input.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.plccom.net.




table



Example

OperationResult res = 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.plccom.net.




table



Example

BlockListResult res = 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.plccom.net.




table



Example

BlockListLengthResult res = 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.plccom.net.




table



Example

eBlockType BlockType = eBlockType.FB;
int BlockNumber = 1;

// open SaveFileDialog
final JFileChooser dr = new JFileChooser(new File("."));
FileFilter filter = new FileNameExtensionFilter("Binary Files *.mc7", "mc7");
dr.addChoosableFileFilter(filter);
int returnVal = dr.showSaveDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {

        // read Block into ReadPLCBlockResult
        ReadPLCBlockResult res = Device.readPLCBlock_MC7(BlockType, BlockNumber);

        // evaluate values and write file
        if (res.Quality().equals(OperationResult.eQuality.GOOD)) {              
                // save buffer in specified file
                File file = new File(dr.getSelectedFile().getAbsolutePath());

                // rename file to .mc7, you can adjust the extension
                if (!file.getAbsolutePath().endsWith(".mc7")) {
                        file = new File(dr.getSelectedFile().getAbsolutePath() + ".mc7");
                        // if file doesnt exists, then create it
                        if (!file.exists()) {
                                file.createNewFile();
                        }
                        FileOutputStream fs = new FileOutputStream(file);
                        fs.write(res.getBuffer());
                        fs.close();
                }
        }
}


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.plccom.net.




table



Example

// open SaveFileDialog
final JFileChooser dr = new JFileChooser(new File("."));
FileFilter filter = new FileNameExtensionFilter("Binary Files *.mc7", "mc7");
dr.addChoosableFileFilter(filter);
int returnVal = dr.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
        InputStream is = null;
        byte[] buffer = null;
        try {
                is = new BufferedInputStream(new FileInputStream(dr.getSelectedFile().getAbsolutePath()));
                buffer = new byte[is.available()];
                is.read(buffer);
        } finally {
                if (is != null) {
                is.close();
        }
}

WritePLCBlockRequest Requestdata = new WritePLCBlockRequest(buffer);

// Write Buffer into PLC
OperationResult res = Device.writePLCBlock_MC7(Requestdata);

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.plccom.net.




table



Example


OperationResult res = Device.deleteBlock(bip.BlockType, bip.BlockNumber);

PLCcom for S7 SDK 
Package Description
com.indian.plccom.fors7  
com.indian.plccom.fors7.UnsignedDatatypes