PLCcom for S7 SDK class library documentation
First steps PLCCom for S7 .NET SDK
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 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 |
| 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 |
| Struct | Read Access, and Write Access to Individual Elements |
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 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 (please note: java version 12 is not supported due to tls 1.3 problems)
- Android API 21 or higher
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 accessible DBs. The access to a S7-1200 or 1500 is disabled by default. You have to process the following steps:
- Allow the general access. Activate in the property settings section protection the option 'Connection mechanism - Allow access PUT/GET communication from remote partner'.
- Enable access to your DBs. Go to DB properties and deactivate 'optimized access'.
- Load to PLC, done!
- If the changes don't have any effect, use 'extended download to device' to load to PLC.
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):
- Unrestricted symbolic access to PLC and PLCSim
- S7-1200: Firmware version V4.5 or higher (tested up to V4.7)
- S7-1500: Firmware version V2.9 or higher (tested up to V4.0)
- Authentication via password or user/password possible
Legacy access (prior to TIA version 17):
- Symbolic access to PLC with password authentication possible
- Direct symbolic access to PLCSim without password
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
|
PLC Type/Function |
S7-200 |
S7-300 |
S7-400 |
S7-1200/1500 |
S7-1200 |
S7-1500 |
WinAC RTX |
Logo |
|
Read data |
||||||||
|
Write data |
||||||||
|
Subscribe data areas |
via data server |
via data server |
via data server |
native |
via data server |
via data server |
via data server |
via data server |
|
Subscribe variables |
||||||||
|
Subscribe alarms |
||||||||
|
Reading actual alarms list |
||||||||
|
Acknowledge alarms |
||||||||
|
Reading data from |
||||||||
|
Send password |
||||||||
|
Start and stop a PLC |
||||||||
|
Get or set PLC time |
||||||||
|
Get basic info from PLC |
||||||||
|
Get mode and state from CPU |
||||||||
|
Get LEDs mode from PLC |
||||||||
|
Read data from |
||||||||
|
Get diagnostic data |
||||||||
|
Read a list of created PLC objects. |
||||||||
|
Read lenght of |
||||||||
|
Read a specific block in |
||||||||
|
Get specific |
restricted |
|||||||
|
Restore block data |
||||||||
|
Restore in |
||||||||
|
Delete blocks |
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:
//Note: Without any licence informations (blank fields), the library is working for 15 minutes
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
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.
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.
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
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
}
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
Example
OperationResult res = Device.deleteBlock(bip.BlockType, bip.BlockNumber);
| Package | Description |
|---|---|
| com.indian.plccom.fors7 | |
| com.indian.plccom.fors7.UnsignedDatatypes |