Skip to main content

Diagnosis

Read diagnostics and alarms via PnSServiceGetDiag / PnSServiceGetAlarms (the same set of capabilities as C# device.Diagnostics).​

Use together with events

We recommend driving exception handling through events rather than polling yourself. Direct diagnostic reading is suitable for scenarios such as interface display.

Operating state (PnSServiceIsConnected / PnSServiceGetState / PnSServiceGetErrorCode).

Feature Overview​

FeaturesNote
Diagnostic SnapshotLinks, Frame Count, Watchdog, Jitter, Alarm Monitoring
IOPSProcess Data Quality
On-Site Issue ComparisonSelect a field based on symptoms
Call the PoliceEvent List / History / Confirm

Diagnostic Snapshot​

CategoryFieldTypeNote
AvailabilityokintCheck if available. 0 = Device not started, read message
Availabilityshared_memory_mappedintIs the process data ready?
Availabilitymessagechar[256]Reason for unavailability; empty when available
Linkstatechar[32]Operational Status Copy
Linklink_upintIs the network card link up?
LinkconnectedintAre the cycle data normal?
Linkactive_iocr_countuint32_tNumber of active IO connections
Linkiocr_active / iocr_healthyuint32_tIO Connection Activation / Health Bitmap
Countingheartbeat / cycle_counteruint64_tHeartbeat / Cycle Count
Countinglast_erroruint64_tRecent error codes (0 = None)
Countingrx_frames / tx_framesuint64_tTotal Number of Frames Received / Sent
Countingrx_rt_frames / tx_rt_framesuint64_tReceive / Transmit RT Cyclic Frame
Countingdropped_frames / invalid_framesuint64_tDiscarded / Illegal Frame
Countingwatchdog_tripsuint64_tNumber of watchdog timeouts
Countinglast_rx_tsc / last_tx_tscuint64_tMost Recent Received / Sent Frames TSC
Process areainput_area_length / output_area_lengthuint32_tLength of the input / output area (bytes — an area length). Not the real usable data length; to get the usable data length use the PnSServiceRead / PnSServiceGetIo query mode
Cyclestack_cyclesuint64_tCycle Counting
Cyclestack_frames_rx / stack_frames_txuint64_tReceive / Transmit Frame
Cyclestack_missed_ticksuint64_tA Missed Beat
Cyclestack_max_jitter_usuint64_tMaximum Jitter (microseconds)
Alarm Monitoringstack_alarm_rx_countuint64_tTotal Number of Alarms Received from the Controller
Alarm Monitoringstack_alarm_tx_ack_okuint64_tNumber of times the unit's alarm has been acknowledged
Alarm Monitoringstack_alarm_tx_ack_failuint64_tNumber of failed alarm acknowledgments on this unit
Alarm Monitoringstack_alarm_ack_pendinguint64_tIn-Transit Alerts (0/1)
Alarm Monitoringstack_alarm_maint_stateuint64_tMaintain Request Status
Alarm Monitoringstack_alarm_last_arepuint32_tRecently, the controller issued an alarm: Arep
Alarm Monitoringstack_alarm_last_slotuint32_tRecently, the controller issued an alarm: Bay
Alarm Monitoringstack_alarm_last_subslotuint32_tRecently, the controller issued an alarm: sub-bay
Alarm Monitoringstack_alarm_last_typeuint32_tThe controller recently issued an alarm: Type
Alarm Monitoringstack_alarm_last_sequint32_tThe controller recently issued an alarm: Serial Number
Alarm Monitoringstack_alarm_last_usiuint32_tRecently, the controller has been issuing an alarm:USI
Alarm Monitoringstack_alarm_last_lenuint32_tThe controller recently issued an alarm: load length
Errorerror_codeintOriginal error code value (0 = None)

PnSServiceGetDiag​

pns_result_t PnSServiceGetDiag(
pns_service_handle_t session,
pns_service_diag_t * p_diag);

Retrieves the current diagnostic snapshot in one call; suitable for interface refreshes and logging. When the device has not yet booted, ok == 0 and message should be read instead; this is not treated as an error. The available data length is determined by the value negotiated with the IO controller and is matched automatically after connection—do not hard-code it. If you need the length, use the query mode of PnSServiceRead / PnSServiceGetIo, not this snapshot's input_area_length / output_area_length (those are the area lengths).

Example:

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

printf("%s\n", snap.link_up ? "Up" : "Down");
printf("%s\n", snap.connected ? "周期交换正常" : "未建立");
printf("帧: %llu / %llu\n",
(unsigned long long)snap.rx_frames,
(unsigned long long)snap.tx_frames);
printf("看门狗: %llu\n", (unsigned long long)snap.watchdog_trips);

IOPS​

PnSServiceGetIoStatus​

pns_result_t PnSServiceGetIoStatus(
pns_service_handle_t session,
pns_service_io_status_t * p_status,
uint16_t * p_input_iops_len, uint8_t * p_input_iops,
uint16_t * p_input_iocs_len, uint8_t * p_input_iocs,
uint16_t * p_output_iops_len, uint8_t * p_output_iops,
uint16_t * p_output_iocs_len, uint8_t * p_output_iocs);

IOPS / IOCS Snapshot. 0x80 = GOOD, 0x00 = BAD. If disconnected, all values are set to BAD. If not yet started, the length is 0, all_good = 0 and the value is returned as is PNS_OK. The buffer may NULL only use derived criteria.

FieldTypeNote
input_valid / output_validintWhether I has received input data / whether Q has been written and delivered to the controller (disconnected or not sent = 0)
input_data_goodintInput: All IOPS GOOD
output_data_goodintOutput: All IOPS GOOD
output_consumedintOutput: All IOCS GOOD
all_goodintAll three of the above conditions are met
iops_bad_countintIOPS Number of bytes that are not "GOOD" (input + output)

Example:

pns_service_io_status_t st;
if (PnSServiceGetIoStatus(session, &st,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL) == PNS_OK
&& !st.all_good)
printf("IOPS BAD %d\n", st.iops_bad_count);

On-Site Issue Comparison​

On-site SymptomsSee which fields
The Ethernet cable isn't plugged in properly.GetDiag 's link_up
Is the cycle data available?GetDiag 's connected
The watchdog keeps jumpingwatchdog_trips
Frames are being droppeddropped_frames + invalid_frames
Is the cycle stable?stack_max_jitter_us + stack_missed_ticks
Data QualityGetIoStatus 's all_good / iops_bad_count
Controller alarm not clearedstack_alarm_ack_pending / stack_alarm_tx_ack_fail
Does this machine have a motion alarm?GetAlarms / GetAlarmCount

Call the Police​

Upper limit: PNS_SERVICE_MAX_ALARMS = 500 (aligned with the server-side PnSAlarmService.MaxAlarmCount = 500).

  • Two-phase: set p_items to NULL with items_cap=0 to query the count only.
  • If the actual number of entries exceeds the capacity, the filled entries stay valid, *p_count is written back with the actual number, and PNS_ERR_INVALID_PARAM is returned.
  • Entries are about 0.9 KB each, so 500 entries come to roughly 430 KB—check the count first, then allocate on the heap; do not create items[PNS_SERVICE_MAX_ALARMS] on the stack.
  • An empty list is not a failure.
MembersNote
PnSServiceGetAlarmsCurrent Activity Alerts
PnSServiceGetAlarmHistoryHistory (Last 500 entries, sorted by date in ascending order)
PnSServiceGetAlarmCountTotal number of event alerts. From the same source GetAlarms as
PnSServiceGetCriticalAlarmCountNumber of Critical Alarms
PnSServiceAlarmAckConfirm one. ID not found → PNS_ERR_NOT_FOUND
PnSServiceAlarmAckAllConfirm all. Even 0 items is considered successful.

PnSServiceGetAlarms​

pns_result_t PnSServiceGetAlarms(
pns_service_handle_t session,
pns_service_alarm_item_t * p_items,
size_t items_cap,
size_t * p_count);

Current activity alert. If there are no activity alerts, an empty list is returned; this does not indicate a failure.

Example (two-step approach: first check the count, then allocate and retrieve entries using a heap):

size_t n = 0;
pns_service_alarm_item_t * items;
if (PnSServiceGetAlarms(session, NULL, 0, &n) != PNS_OK)
return 1; /* Step 1: Check the quantity only */
items = (pns_service_alarm_item_t *)malloc(n * sizeof(*items));
if (items == NULL && n != 0)
return 1; /* The entry is large, so I can only use heap allocation. */
if (PnSServiceGetAlarms(session, items, n, &n) == PNS_OK) /* Step 2: Retrieve an entry */
{
size_t i;
for (i = 0; i < n; i++)
printf("%s\n", items[i].message);
}
free(items);

PnSServiceGetAlarmHistory​

pns_result_t PnSServiceGetAlarmHistory(
pns_service_handle_t session,
pns_service_alarm_item_t * p_items,
size_t items_cap,
size_t * p_count);

Alert History (last 500 entries, sorted by time in ascending order). If no history is found, an empty list is returned; this is not a failure.

Example (two-part, same heap allocation as above GetAlarms):

size_t n = 0;
pns_service_alarm_item_t * items;
if (PnSServiceGetAlarmHistory(session, NULL, 0, &n) != PNS_OK)
return 1;
items = (pns_service_alarm_item_t *)malloc(n * sizeof(*items));
if (items == NULL && n != 0)
return 1;
PnSServiceGetAlarmHistory(session, items, n, &n);
free(items);

PnSServiceAlarmAck​

pns_result_t PnSServiceAlarmAck(
pns_service_handle_t session,
const char * id);

Confirm an event alert. The ID is taken from GetAlarms. An empty string returns PNS_ERR_INVALID_PARAM; if this ID does not exist, returns PNS_ERR_NOT_FOUND.

Example:

PnSServiceAlarmAck(session, "PnS.LinkDown");

PnSServiceAlarmAckAll​

pns_result_t PnSServiceAlarmAckAll(
pns_service_handle_t session,
int * p_acked_count);

Confirm all activity alarms. p_acked_count Can be NULL.

Return value:

  • PNS_OK — *p_acked_count Number of confirmed events (0 = no active alarms)

Example:

int n = 0;
PnSServiceAlarmAckAll(session, &n);
pns_service_alarm_item_t
FieldTypeNote
idchar[128]Alert ID (e.g., PnS.LinkDown)
severitychar[32]Severity: Info / Warning / Error / Critical
messagechar[512]Alert Message
occurred_atchar[64]Last occurrence (ISO-8601 text)
countintNumber of occurrences (≥1)
sourcechar[128]Source

I&M Identification​

PnSServiceGetIm()​

pns_result_t PnSServiceGetIm(
pns_service_handle_t session,
pns_service_im_info_t * p_im);

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; no values are fabricated.IO If the controller has not written to a field, the value read from the stack is the factory default placeholder value, not an empty string.

Example:

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);

Application Records​

PnSServiceGetRecords()​

pns_result_t PnSServiceGetRecords(
pns_service_handle_t session,
pns_service_user_record_t * p_items,
size_t items_cap,
size_t * p_count);

The two segments have the same diameter GetAlarms. An empty list does not indicate a failure.

Reset​

PnSServiceReset()​

pns_result_t PnSServiceReset(
pns_service_handle_t session,
pns_service_reset_mode_t mode);
typedef enum pns_service_reset_mode
{
PNS_SERVICE_RESET_COMMUNICATION = 0, /* Soft stop and restart, with records retained */
PNS_SERVICE_RESET_FACTORY = 1 /* A fresh start after destruction; records cleared */
} pns_service_reset_mode_t;

Slow operation; timed out after 15 seconds. The session remains available after a reset.