Java SDK Overview
Java class libraries for developing PROFINET IO Device applications. In the code import com.darra.pns.service.PnSService;.
Installation
Install from Maven Central:
<dependency>
<groupId>xyz.darra</groupId>
<artifactId>darra-profinet-slave</artifactId>
<version>1.6.3</version>
</dependency>
Gradle:
implementation 'xyz.darra:darra-profinet-slave:1.6.3'
Package Page:central.sonatype.com/artifact/xyz.darra/darra-profinet-slave
You can also access it fromDownload Pageupload it darra-profinet-slave.jar, or use the copy located SDK\SDK_Java\ in the installation directory.
Environment
- Windows 10 / 11 x64
- JDK 11+
- Darra Profinet Slave Installed
Quick Start
After "Start," set I / Q Map onceCreate a structure, then use this variable to read and write fields. The structure is mapped to the process image; when the source changes, the fields change accordingly; readStruct / writeStruct is a snapshot—copied instances will not change on their own.I-region read-only: Writing to element ports, address ports, or integer region ports in the I-region will be rejected (UnsupportedOperationException / PnSServiceException), and attempts to write to the I-region’s mapped areas will also write() be rejected.
Cycle exchange happens automatically; you do not need to write your own cycle loop. Reads may be concurrent, writes must be serialized by the caller. Java Structure fields are a managed cache: after changing outp you must call write() for it to reach the process image, and to read the latest inp you must call read().
import com.darra.pns.service.PnSService;
import com.darra.pns.service.PnSServiceException;
import com.sun.jna.Structure;
import com.sun.jna.Structure.FieldOrder;
@FieldOrder({"present", "recipe"})
class FromPlc extends Structure { // I: Controller → Device
public byte present;
public short recipe;
public FromPlc() { super(ALIGN_NONE); }
}
@FieldOrder({"ready", "busy"})
class ToPlc extends Structure { // Q: Equipment → Controller
public byte ready;
public byte busy;
public ToPlc() { super(ALIGN_NONE); }
}
try (PnSService device = new PnSService()) {
device.start();
// Map once
FromPlc inp = device.getProcessData().getInputsMapping(FromPlc.class);
ToPlc outp = device.getProcessData().getOutputsMapping(ToPlc.class);
while (running) {
if (!device.isConnected())
continue;
inp.read(); // Process Image → Managed Cache
byte present = inp.present; // Read I: Changes on Its Own After Bus Refresh
outp.ready = 1;
outp.write(); // Write Q: Cached in memory → Process image
}
device.stop();
} catch (PnSServiceException e) {
System.err.println(e.getMessage());
}
Snapshot readStruct / writeStruct(Implementation ProcessData.Packed) — The copied instance does not change on its own.