Skip to main content

Equipment API Structure

PROFINET IO Device The C entry point, used to initialize the device, write to Q and read from I, and monitor the operating status and diagnostics. The handle is pns_service_handle_t.

This product is designed SDK exclusively for this purpose PROFINET IO Deviceand does not provide interfaces for other fieldbus protocols.

API Structure​

Static— pns_* no session required. The first parameter of the session function is session. Diagnostic functions are grouped together and correspond to C# device.Diagnostics.

static
├── pns_is_service_ready / pns_service_connected / pns_service_state
├── pns_service_wait_reason / pns_service_status_message
└── pns_last_error / pns_last_error_code / pns_runtime_error_message

pns_service_handle_t session
│
├── PnSServiceConnectRealtime / PnSServiceStart / PnSServiceStop / PnSServiceClose
│
├── Process Data In (read I, module input, read-only)
│ ├── PnSProcessDataInputsMapping / PnSProcessDataInputsMappingRO // mapped once, fields change themselves (I read-only; RO = read-only view)
│ ├── PnSProcessDataInI8 / PnSProcessDataInU8 / PnSProcessDataInI16 / PnSProcessDataInU16
│ ├── PnSProcessDataInI32 / PnSProcessDataInU32 / PnSProcessDataInI64 / PnSProcessDataInU64
│ ├── PnSProcessDataInF32 / PnSProcessDataInF64
│ ├── PnSProcessDataInBool / PnSProcessDataInBit
│ ├── PnSProcessDataReadStruct / PnSProcessDataCopyInputsTo // snapshot
│ └── PnSServiceRead / ReadArea / ReadBool / ReadInt16 / ReadInt32
├── Process Data Out (write Q, module output, writable)
│ ├── PnSProcessDataOutputsMapping // changing bytes changes the process image
│ ├── PnSProcessDataOutI8 / PnSProcessDataOutU8 / PnSProcessDataOutI16 / PnSProcessDataOutU16
│ ├── PnSProcessDataOutI32 / PnSProcessDataOutU32 / PnSProcessDataOutI64 / PnSProcessDataOutU64
│ ├── PnSProcessDataOutF32 / PnSProcessDataOutF64
│ ├── PnSProcessDataOutBool / PnSProcessDataOutBit
│ ├── PnSProcessDataWriteStruct / PnSProcessDataCopyToOutputs // snapshot
│ └── PnSServiceWrite / WriteArea / WriteBool / WriteInt16 / WriteInt32
│
├── Events
│ ├── PnSServiceOnConnectedChanged
│ ├── PnSServiceOnStateChanged
│ ├── PnSServiceOnErrorOccurred
│ ├── PnSServiceOnIoStatusChanged
│ ├── PnSServiceOnLinkChanged
│ └── PnSServiceOnLogged
│
├── PnSServiceIsConnected / GetState / GetWaitReason / GetEverConnected / GetErrorCode
│
├── Diagnostics (corresponds to C# device.Diagnostics)
│ ├── PnSServiceGetDiag
│ ├── PnSServiceGetIoStatus
│ ├── PnSServiceGetAlarms / GetAlarmHistory
│ └── PnSServiceGetRecords
│
└── PnSServiceGetIm

Write Q (module output, device → controller), read I (module input, controller → device).

Usage​

Start-Stop​

#include "pns.h"

pns_service_handle_t session = NULL;
if (PnSServiceConnectRealtime(&session) != PNS_OK)
return 1;
if (PnSServiceStart(session) != PNS_OK)
return 1;

while (running)
{
if (!PnSServiceIsConnected(session))
{
/* PnSServiceGetWaitReason(session) */
continue;
}
PnSServiceWriteBool(session, "Q0.0", true); /* Write Q */
{
bool from_plc = false;
PnSServiceReadBool(session, "I0.0", &from_plc); /* Read I */
}
}

PnSServiceStop(session);
PnSServiceClose(session);

No need to start a session to check the status: pns_is_service_ready / pns_service_connected / pns_service_wait_reason.

Process Data​

MethodVisitNote
Process DataPnSProcessDataInputsMapping / PnSProcessDataInputsMappingRO / PnSProcessDataOutputsMappingMap once (for read-only views RO)
Process DataPnSProcessDataIn* / PnSProcessDataOut*Snapshot / Typed Offset

Identification​

PnSServiceGetIm Fill in the blanks pns_service_im_info_t. I&M1–I&M3 has been enabled by the native stack and read back accurately; I&M4 has not been enabled. Missing fields remain empty; do not invent values.IO If the controller has not written to a field, the value read is the stack’s factory default placeholder, not an empty string.

FieldNote
station_nameSite Name
vendor_idVendor ID
device_idDevice ID
order_idOrder Number
serial_numberSerial Number
hardware_revisionHardware Version
software_revisionSoftware Version
product_nameProduct Name
im_supportedEnabled I&M Record Sets
im14_supportedI&M1–4 Enabled (0 / 1)
im_noteIdentification note
project_order_numberEngineering Order Number
project_hardware_releaseEngineering Hardware Version
project_software_releaseEngineering Software Version
im1_tag_functionI&M1 Function Tab
im1_tag_locationI&M1 Installation Location
im2_dateI&M2 Date
im3_descriptorI&M3 Description
im4_signature_hexI&M4 Signature (hexadecimal)
pns_service_im_info_t im;
if (PnSServiceGetIm(session, &im) == PNS_OK)
printf("%s vendor=0x%04X device=0x%04X\n",
im.station_name, im.vendor_id, im.device_id);

Reading and Writing Process Data​

Structures are tightly packed in the order in which they are declared. Word and double-word types are big-endian.

The "Golden Path" involves a single mapping: when the source changes, the field changes accordingly. Multi-byte fields use big-endian byte order (online byte order), so the host values must use a typed accessor that performs "automatic conversion."

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

volatile uint8_t *q = NULL;
const uint8_t *i = NULL;
size_t ni = 0, nq = 0;
if (PnSProcessDataInputsMappingRO(session, &i, &ni) != PNS_OK ||
PnSProcessDataOutputsMapping(session, &q, &nq) != PNS_OK ||
i == NULL || q == NULL) /* On failure, *p = NULL */
{
/* Process image is not available */
}
const from_plc_t *inp = (const from_plc_t *)i; /* I Read-Only View */
from_plc_t *outp = (from_plc_t *)q;
uint8_t present = inp->a; /* It changes on its own after the bus is refreshed */
outp->a = 1; /* Lands directly in the Q process image */

/* Snapshot: It won't change on its own after you copy it out */
from_plc_t rx;
PnSProcessDataReadStruct(session, &rx, (uint16_t)sizeof(rx));

PnSProcessDataOutU8(session, 0, 0x11);
uint8_t v = 0;
PnSProcessDataInU8(session, 0, &v);

Diagnostics and Alarms​

Via PnSServiceGetDiag / PnSServiceGetAlarms Read Diagnostics (part of the device.Diagnostics same set of capabilities as C#).

pns_service_diag_t snap;
if (PnSServiceGetDiag(session, &snap) == PNS_OK && !snap.ok)
printf("%s\n", snap.message);

/* Two-step approach: First check the count, then use a heap to allocate and retrieve items (items cost approximately 0.9 KB/item; do not place them on the stack) */
size_t n = 0;
pns_service_alarm_item_t * items;
if (PnSServiceGetAlarms(session, NULL, 0, &n) == PNS_OK && n > 0)
items = (pns_service_alarm_item_t *)malloc(n * sizeof(*items));
else
items = NULL;
if (items != NULL)
{
size_t i;
if (PnSServiceGetAlarms(session, items, n, &n) == PNS_OK)
{
for (i = 0; i < n; i++)
printf("%s\n", items[i].message);
}
free(items);
}