Skip to main content

PnSService

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​

PnSService                                         // device instance
│
├── ProcessData() → PnSProcessData // write Q / read I
│ ├── InputsMapping<T>() / OutputsMapping<T>() // map once
│ ├── Read<T>() / Write<T>() / SetOutputs() // 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 on/off
│ ├── StateChanged // operating state change
│ ├── ErrorOccurred // runtime error
│ ├── IoStatusChanged // IOPS BAD count change
│ ├── LinkChanged // NIC link change
│ └── Logged // every event above also fires this
├── Diagnostics() → PnSDiagnostics // diagnostics and alarms
│ ├── Snapshot() // diagnostics snapshot
│ ├── Alarms() / AlarmHistory() // local alarms / history
│ └── Records() // user-area records
│
├── Connected() / Status() / WaitReason() // cyclic exchange / run state / wait reason
├── EverConnected() / ErrorCode() // ever connected / runtime error
└── ImData() // I&M identity

Write Q (module output, device → controller), read I (module input, controller → device). Flat DiagSnapshot() / GetAlarms() still available, same Diagnostics() data as .

Usage​

Start-Stop​

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

PnSService device;
if (!device.Start())
return;

while (running)
{
if (!device.Connected())
{
// device.WaitReason()
continue;
}
device.WriteBool("Q0.0", true); // Write Q
bool fromPlc = device.ReadBool("I0.0"); // Read I
}
device.Stop();

You don't need to construct the following to check the status: IsServiceReady() / ServiceConnected() / ServiceWaitReason().

Process Data​

MethodVisitNote
Process Datadevice.ProcessData().InputsMapping<T>() / OutputsMapping<T>()Map once
Process Datadevice.ProcessData()Snapshot Read / Write, In() / Out() bytes

Identification​

auto im = device.ImData();
std::string name = im.station_name;
uint16_t vendor = im.vendor_id;
uint16_t product = im.device_id;

Reading and Writing Process Data​

Structures are byte-tightly packed in the order they are declared; this is mandatory #pragma pack(push, 1)( static_assert unless compiled with the "unpack" option). Words and double words are big-endian.

The "Golden Path" involves a single mapping: when the source changes, the field changes accordingly. The host values must pass through a typed accessor that performs "automatic conversion" (big-endian encoding/decoding). The I side returns const T& read-only values (the controller overwrites the entire segment every cycle; writing to I results in an exception PnSException), while the Q side returns writable T& values.

#pragma pack(push, 1)
struct FromPlc
{
uint8_t a;
int16_t b;
uint8_t flag;
};
#pragma pack(pop)

// Map once
const FromPlc& inp = device.ProcessData().InputsMapping<FromPlc>();
FromPlc& outp = device.ProcessData().OutputsMapping<FromPlc>();
uint8_t 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 = device.ProcessData().Read<FromPlc>();

device.ProcessData().Out()[0].Content(0x11);
uint8_t v = device.ProcessData().In()[0].Content();

Diagnostics and Alarms​

By device.Diagnostics() reading the diagnostics and alarms.

auto snap = device.Diagnostics().Snapshot();
if (!snap.ok)
printf("%s\n", snap.message.c_str());

for (const auto& a : device.Diagnostics().Alarms())
printf("%s\n", a.message.c_str());