Diagnosis
Read diagnostics and alarms via PnSServiceGetDiag / PnSServiceGetAlarms (the same set of capabilities as C# device.Diagnostics).
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
| Features | Note |
|---|---|
| Diagnostic Snapshot | Links, Frame Count, Watchdog, Jitter, Alarm Monitoring |
| IOPS | Process Data Quality |
| On-Site Issue Comparison | Select a field based on symptoms |
| Call the Police | Event List / History / Confirm |
Diagnostic Snapshot
| Category | Field | Type | Note |
|---|---|---|---|
| Availability | ok | int | Check if available. 0 = Device not started, read message |
| Availability | shared_memory_mapped | int | Is the process data ready? |
| Availability | message | char[256] | Reason for unavailability; empty when available |
| Link | state | char[32] | Operational Status Copy |
| Link | link_up | int | Is the network card link up? |
| Link | connected | int | Are the cycle data normal? |
| Link | active_iocr_count | uint32_t | Number of active IO connections |
| Link | iocr_active / iocr_healthy | uint32_t | IO Connection Activation / Health Bitmap |
| Counting | heartbeat / cycle_counter | uint64_t | Heartbeat / Cycle Count |
| Counting | last_error | uint64_t | Recent error codes (0 = None) |
| Counting | rx_frames / tx_frames | uint64_t | Total Number of Frames Received / Sent |
| Counting | rx_rt_frames / tx_rt_frames | uint64_t | Receive / Transmit RT Cyclic Frame |
| Counting | dropped_frames / invalid_frames | uint64_t | Discarded / Illegal Frame |
| Counting | watchdog_trips | uint64_t | Number of watchdog timeouts |
| Counting | last_rx_tsc / last_tx_tsc | uint64_t | Most Recent Received / Sent Frames TSC |
| Process area | input_area_length / output_area_length | uint32_t | Length 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 |
| Cycle | stack_cycles | uint64_t | Cycle Counting |
| Cycle | stack_frames_rx / stack_frames_tx | uint64_t | Receive / Transmit Frame |
| Cycle | stack_missed_ticks | uint64_t | A Missed Beat |
| Cycle | stack_max_jitter_us | uint64_t | Maximum Jitter (microseconds) |
| Alarm Monitoring | stack_alarm_rx_count | uint64_t | Total Number of Alarms Received from the Controller |
| Alarm Monitoring | stack_alarm_tx_ack_ok | uint64_t | Number of times the unit's alarm has been acknowledged |
| Alarm Monitoring | stack_alarm_tx_ack_fail | uint64_t | Number of failed alarm acknowledgments on this unit |
| Alarm Monitoring | stack_alarm_ack_pending | uint64_t | In-Transit Alerts (0/1) |
| Alarm Monitoring | stack_alarm_maint_state | uint64_t | Maintain Request Status |
| Alarm Monitoring | stack_alarm_last_arep | uint32_t | Recently, the controller issued an alarm: Arep |
| Alarm Monitoring | stack_alarm_last_slot | uint32_t | Recently, the controller issued an alarm: Bay |
| Alarm Monitoring | stack_alarm_last_subslot | uint32_t | Recently, the controller issued an alarm: sub-bay |
| Alarm Monitoring | stack_alarm_last_type | uint32_t | The controller recently issued an alarm: Type |
| Alarm Monitoring | stack_alarm_last_seq | uint32_t | The controller recently issued an alarm: Serial Number |
| Alarm Monitoring | stack_alarm_last_usi | uint32_t | Recently, the controller has been issuing an alarm:USI |
| Alarm Monitoring | stack_alarm_last_len | uint32_t | The controller recently issued an alarm: load length |
| Error | error_code | int | Original 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.
| Field | Type | Note |
|---|---|---|
input_valid / output_valid | int | Whether I has received input data / whether Q has been written and delivered to the controller (disconnected or not sent = 0) |
input_data_good | int | Input: All IOPS GOOD |
output_data_good | int | Output: All IOPS GOOD |
output_consumed | int | Output: All IOCS GOOD |
all_good | int | All three of the above conditions are met |
iops_bad_count | int | IOPS 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 Symptoms | See 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 jumping | watchdog_trips |
| Frames are being dropped | dropped_frames + invalid_frames |
| Is the cycle stable? | stack_max_jitter_us + stack_missed_ticks |
| Data Quality | GetIoStatus 's all_good / iops_bad_count |
| Controller alarm not cleared | stack_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_itemstoNULLwithitems_cap=0to query the count only. - If the actual number of entries exceeds the capacity, the filled entries stay valid,
*p_countis written back with the actual number, andPNS_ERR_INVALID_PARAMis 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.
| Members | Note |
|---|---|
PnSServiceGetAlarms | Current Activity Alerts |
PnSServiceGetAlarmHistory | History (Last 500 entries, sorted by date in ascending order) |
PnSServiceGetAlarmCount | Total number of event alerts. From the same source GetAlarms as |
PnSServiceGetCriticalAlarmCount | Number of Critical Alarms |
PnSServiceAlarmAck | Confirm one. ID not found → PNS_ERR_NOT_FOUND |
PnSServiceAlarmAckAll | Confirm 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_countNumber of confirmed events (0 = no active alarms)
Example:
int n = 0;
PnSServiceAlarmAckAll(session, &n);
pns_service_alarm_item_t
| Field | Type | Note |
|---|---|---|
| id | char[128] | Alert ID (e.g., PnS.LinkDown) |
| severity | char[32] | Severity: Info / Warning / Error / Critical |
| message | char[512] | Alert Message |
| occurred_at | char[64] | Last occurrence (ISO-8601 text) |
| count | int | Number of occurrences (≥1) |
| source | char[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.