DarraPnS
PROFINET IO Device The interface. Start the device, write to Q and read from I, view the operating status, and run diagnostics.
This product is designed SDK exclusively for this purpose PROFINET IO Deviceand does not provide interfaces for other fieldbus protocols.
Class Structure
DarraPnS // device instance
│
├── ProcessData → PnSProcessData // process data, write Q / read I
│ ├── InputsMapping<T>() / OutputsMapping<T>() // map once
│ ├── Read<T> / Write<T> / SubmitStruct<T> // snapshot; values do not change on their own
│ ├── In // read I (module input), read-only
│ └── Out // write Q (module output), writable
├── Events → PnSEvents // runtime events
│ ├── ConnectedChanged // cyclic exchange up/down
│ ├── StateChanged // state changes
│ ├── ErrorOccurred // runtime errors
│ ├── IoStatusChanged // IOPS BAD count changes
│ ├── LinkChanged // NIC physical link changes
│ └── Logged // each of the above also raises this
├── Variables → PnSVariables // variable completion
├── Diagnostics → PnSDiagnostics // diagnostics sub-object (snapshot / IOPS / alarms / records)
│ ├── Snapshot // diagnostics snapshot
│ ├── IoStatus // IOPS / IOCS
│ ├── Alarms / AlarmHistory // local alarms / history
│ └── Records // user-area records
│
├── Connected / State / WaitReason // cyclic exchange / state / wait reason
├── EverConnected / ErrorCode // ever connected / runtime errors
└── ImData // I&M identification
Write Q (module output, device → controller), read I (module input, controller → device). The "flat" attribute
DiagSnapshot/ is stillAlarmsavailable and corresponds toDiagnosticsthe same data.
Usage
Start-Stop
using Darra.PnS;
using (var device = new DarraPnS())
{
PnSErrorCode rc = device.Start();
if (rc != PnSErrorCode.Success)
return;
while (running)
{
if (!device.Connected)
{
// device.WaitReason
continue;
}
device.ProcessData.Out[0].SetBit(0, true); // Write Q0.0
bool fromPlc = device.ProcessData.In[0].AsBool; // Read I0.0
}
device.Stop();
}
You don't need to check the status new: DarraPnS.IsServiceReady / ServiceConnected / ServiceWaitReason.
Process Data
| Method | Visit | Note |
|---|---|---|
| Process Data | device.ProcessData.InputsMapping<T>() / OutputsMapping<T>() | Map once |
| Process Data | device.ProcessData | Snapshot Read / Write, In / Out bytes |
Identification
string name = device.ImData.StationName;
uint vendor = device.ImData.VendorId;
uint product = device.ImData.DeviceId;
Reading and Writing Process Data
Structures must be [StructLayout(LayoutKind.Sequential, Pack = 1)]. Word and double-word types must be big-endian.
The gold path is a one-time mapping: when the source changes, the field changes automatically. The host sequence value must be in Read / Write(big-endian encoding/decoding). The I side returns ref readonly T read-only (the controller overwrites the entire segment every cycle; writing to I returns NotSupported), and the Q side returns ref T writable.
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct FromPlc
{
public byte A;
public short B;
public bool Flag;
}
// Map once
ref readonly FromPlc inp = ref device.ProcessData.InputsMapping<FromPlc>();
ref FromPlc outp = ref device.ProcessData.OutputsMapping<FromPlc>();
byte present = inp.A; // Changes on its own after the bus is refreshed (read-only on the I side)
outp.A = 1; // Lands directly in the Q process image
// Snapshot: It won't change on its own after you copy it out
FromPlc rx = new FromPlc();
device.ProcessData.Read(ref rx);
device.ProcessData.Out[0].Content = 0x11;
byte v = device.ProcessData.In[0].Content;
Diagnostics and Alarms
Through diagnostic reading device.Diagnostics (read-only snapshots: links, frame count, watchdog, jitter, and alarm monitoring).
var snap = device.Diagnostics.Snapshot;
if (!snap.Ok)
Console.WriteLine(snap.Message);
foreach (var a in device.Diagnostics.Alarms)
Console.WriteLine(a.Message);