Skip to main content

Continue SDK from ...

We’ve already tested this in the configuration tool and exported the code. You can find the SDK in the installation directory C:\DARRA\Profinet_Slave\SDK\, or install it from a public repository (NuGet for C#, PyPI for Python, Maven Central for Java, and crates.io for Rust). For C#, simply write using Darra.PnS;.

Minimum Cycle​

Set the hostname and network adapter in the configuration tool. On the application side: new → Start → Map onceProcess data (structures are mapped to the process image; source variables become fields) → Stop.

The cycle switching is performed automatically; there is no need to write your own loop, and any thread can use it simultaneously. Read / Write This type isSnapshot(The copied instances do not change on their own); the mapping entry points are the entry points with InputsMapping the OutputsMapping same name in each language (read-only on the I side, writable on the Q side).

using System.Runtime.InteropServices;
using Darra.PnS;

[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct FromPlc // I: Controller → Device
{
public byte Present;
public short Recipe; // Online IO Controller Endpoint: Simply align it with the upper end; retrieve the value using `Read(ref rx)`
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct ToPlc // Q: Equipment → Controller
{
public byte Ready;
public byte Busy;
}

using (var device = new DarraPnS())
{
device.Start();

// Map once
ref readonly var inp = ref device.ProcessData.InputsMapping<FromPlc>();
ref ToPlc outp = ref device.ProcessData.OutputsMapping<ToPlc>();

while (running)
{
if (!device.Connected)
continue;

byte present = inp.Present; // Read I: Changes on Its Own After Bus Refresh
outp.Ready = 1; // Q: Write the process image directly
}

device.Stop();
}

Multi-byte fields use PROFINET network big-endian (wire) byte order: reading them directly as host short / int reverses the bytes; for host-order values use Read / Write (big-endian encode/decode).

#include "pns.hpp"
using namespace darra::pns;

#pragma pack(push, 1)
struct FromPlc // I: Controller → Device
{
uint8_t Present;
uint8_t Trigger;
int16_t Recipe;
};

struct ToPlc // Q: Equipment → Controller
{
uint8_t Ready;
uint8_t Busy;
uint8_t Ok;
uint8_t Ng;
};
#pragma pack(pop)

PnSService device;
device.Start();

// Map once
const FromPlc& inp = device.ProcessData().InputsMapping<FromPlc>();
ToPlc& outp = device.ProcessData().OutputsMapping<ToPlc>();

while (running)
{
if (!device.Connected())
continue;

uint8_t present = inp.Present; // Read I: Changes on Its Own After Bus Refresh
outp.Ready = 1; // Q: Write the process image directly
}

device.Stop();

Address-based read/write operations (Q0.0 / I0.0) are path-compatible.

Click "Export" in the top toolbar of the configuration tool to generate examples in various languages.

Export Program — 6 Languages Including C#