Diagnosis
By reading device.Diagnostics() diagnostics and alarms (DiagSnapshot() / GetAlarms() still available).
We recommend using Event Handle driver exceptions rather than polling on your own. Directly reading diagnostic properties is suitable for scenarios such as display UI .
Operating state (Connected() / Status() / ErrorCode()).
Feature Overview
| Features | Note |
|---|---|
| Diagnostic Snapshot | Links, Frame Count, Watchdog, Jitter, Alarm Monitoring |
| On-Site Issue Comparison | Select a field based on symptoms |
| Call the Police | Event List / History / Confirm |
Diagnostic Snapshot
| Category | Property | Type | Access | Description |
|---|---|---|---|---|
| Availability | ok | bool | read-only | Checks whether the device is available. false = Device is not RUN; read 'message' |
shared_memory_mapped | bool | read-only | Whether the procedure data is ready | |
message | string | read-only | Reason for unavailability; empty when available | |
| Links | state | string | read-only | Operational ST description |
link_up | bool | read-only | Is the network interface link up? | |
connected | bool | read-only | Whether the cycle data is normal | |
active_iocr_count | uint32_t | read-only | Number of active IO connections | |
iocr_active | uint32_t | read-only | IO link activation bitmap | |
iocr_healthy | uint32_t | read-only | IO link health bitmap | |
| Counting | heartbeat | uint64_t | read-only | heartbeat count |
cycle_counter | uint64_t | read-only | Cycle counter | |
last_error | uint64_t | read-only | Last fault code (0 = none) | |
rx_frames / tx_frames | uint64_t | read-only | Total number of received / transmitted frames | |
rx_rt_frames / tx_rt_frames | uint64_t | read-only | Receive / transmit RT cycle frames | |
dropped_frames | uint64_t | read-only | dropped frames | |
invalid_frames | uint64_t | read-only | invalid frames | |
watchdog_trips | uint64_t | read-only | Number of watchdog timeouts | |
last_rx_tsc / last_tx_tsc | uint64_t | read-only | Last received / transmitted frame TSC | |
| Process Area | input_area_length | uint32_t | read-only | Input area length (bytes; an area-length measure, not the true length of the available data). Renegotiated and rebuilt with the IO controller; do not hard-code this value |
output_area_length | uint32_t | read-only | Output area length (bytes; an area-length measure, not the true length of the available data). Renegotiated and rebuilt with the IO controller; do not hard-code this value | |
| Cycle | stack_cycles | uint64_t | read-only | Cycle count |
stack_frames_rx / stack_frames_tx | uint64_t | read-only | Received / Transmitted Frames | |
stack_missed_ticks | uint64_t | read-only | Missed ticks | |
stack_max_jitter_us | uint64_t | read-only | Maximum jitter (microseconds) | |
| Alarm Monitoring | stack_alarm_rx_count | uint64_t | read-only | Total number of controller alarms received |
stack_alarm_tx_ack_ok | uint64_t | read-only | Number of times the local alarm has been acknowledged | |
stack_alarm_tx_ack_fail | uint64_t | read-only | Number of failed alarm acknowledgments on this machine | |
stack_alarm_ack_pending | uint64_t | read-only | Alarm in transit (0/1) | |
stack_alarm_maint_state | uint64_t | read-only | Maintenance request ST | |
stack_alarm_last_arep | uint32_t | read-only | Latest controller alarm: Arep | |
stack_alarm_last_slot | uint32_t | read-only | Last controller alarm: slot | |
stack_alarm_last_subslot | uint32_t | read-only | Latest controller alarm: subslot | |
stack_alarm_last_type | uint32_t | read-only | Last controller alarm: type | |
stack_alarm_last_seq | uint32_t | read-only | Latest controller alarm: sequence number | |
stack_alarm_last_usi | uint32_t | read-only | Latest controller alarm:USI | |
stack_alarm_last_len | uint32_t | read-only | Last controller alarm: load length | |
| fault | error_code | int | read-only | Raw fault code value (0 = none) |
DiagSnapshot()
PnSServiceDiagSnapshot DiagSnapshot();
PnSServiceDiagSnapshot GetDiag(); // Same Implementation
Retrieves the current diagnostic snapshot once; suitable for interface refreshes and logging. If the device has not yet booted ok == false, a message"read" operation is not considered an fault. The sector length is indicated by input_area_length / output_area_length(the sector length value, not the actual length of usable data); do not hard-code this value. The length is determined by the value negotiated with the IO controller and is automatically matched after link.
Return value:
PnSServiceDiagSnapshot— Diagnostic Data Snapshot
Thrown when unable to connect to the service PnSException.
Example:
auto snap = device.DiagSnapshot();
if (!snap.ok)
{
printf("%s\n", snap.message.c_str());
return;
}
printf(snap.link_up ? "Up\n" : "Down\n");
printf(snap.connected ? "周期交换正常\n" : "未建立\n");
printf("帧: %llu / %llu\n",
static_cast<unsigned long long>(snap.rx_frames),
static_cast<unsigned long long>(snap.tx_frames));
printf("看门狗: %llu\n",
static_cast<unsigned long long>(snap.watchdog_trips));
On-Site Issue Comparison
| On-site Symptoms | See which fields |
|---|---|
| The Ethernet cable isn't plugged in properly. | DiagSnapshot().link_up |
| Is the cycle data available? | DiagSnapshot().connected |
| The watchdog keeps jumping | DiagSnapshot().watchdog_trips |
| Frames are being dropped | dropped_frames + invalid_frames |
| Is the cycle stable? | stack_max_jitter_us + stack_missed_ticks |
| Controller alarm not cleared | stack_alarm_ack_pending / stack_alarm_tx_ack_fail |
| Does this machine have a motion alarm? | GetAlarms() / AlarmCount() |
Call the Police
| Category | Property | Type | Access | Description |
|---|---|---|---|---|
| Counting | AlarmCount() | int | read-only | Total number of active alarms. Same GetAlarms as |
CriticalAlarmCount() | int | read-only | Number of critical alarms | |
| array | GetAlarms() | vector<PnSServiceAlarmItem> | Read-only | Current active alarms. An empty array indicates no active alarms; this does not mean a failure |
GetAlarmHistory() | vector<PnSServiceAlarmItem> | Read-only | History. An empty array = no history |
Stop-loss PnSException.
GetAlarms()
std::vector<PnSServiceAlarmItem> GetAlarms();
Current activity alert. If there are no activity alerts, an empty list is returned; this does not indicate a failure.
Example:
for (const auto& a : device.GetAlarms())
printf("%s %s %s\n", a.id.c_str(), a.severity.c_str(), a.message.c_str());
GetAlarmHistory()
std::vector<PnSServiceAlarmItem> GetAlarmHistory();
Alert History. If there is no history, an empty array is returned; this is not a failure.
Example:
for (const auto& a : device.GetAlarmHistory())
printf("%s %s %s\n", a.occurred_at.c_str(), a.severity.c_str(), a.message.c_str());
AcknowledgeAlarm()
void AcknowledgeAlarm(const std::string& id);
Confirm an active alert. The ID is taken from GetAlarms().
Parameters:
id(string) — Alert ID. Throws an empty stringPnSException; throws an exception if this ID does not exist.PnSException
Example:
device.AcknowledgeAlarm("PnS.LinkDown");
AcknowledgeAllAlarms()
int AcknowledgeAllAlarms();
Confirm all activity alarms.
Return value:
int— Number of confirmed events (0 = no active alarms)
Example:
int n = device.AcknowledgeAllAlarms();
PnSServiceAlarmItem
| Properties | Type | Note |
|---|---|---|
| id | string | Alert ID (e.g., PnS.LinkDown) |
| severity | string | Severity: Info / Warning / Error / Critical |
| message | string | Alert Message |
| occurred_at | string | Last occurrence (ISO-8601 text) |
| count | int | Number of occurrences (≥1) |
| source | string | Source |
I&M Identification
ImData() / GetIm()
PnSServiceImInfo ImData();
PnSServiceImInfo GetIm(); // Same Implementation
I&M1–I&M3 has been enabled by the native stack and read back correctly; I&M4 has not been enabled. Missing fields are empty / 0; no encoding. im14_supported A value of true indicates that the readback of I&M1–I&M4 was successful this time (if the IO Device is not RUN, the value is false, and the field is an empty string); if the IO controller has never written to it, the value read is the stack's factory placeholder value. See im_note for the description.
Example:
auto im = device.ImData();
printf("%s vendor=0x%04X device=0x%04X\n",
im.station_name.c_str(), im.vendor_id, im.device_id);
Application Records
GetRecords()
PnSUserRecords GetRecords();
An empty list is not a failure.
Example:
auto recs = device.GetRecords();
printf("count=%d\n", recs.count);
Reset
ResetDevice()
void ResetDevice(const std::string& mode);
mode | Behavior |
|---|---|
communication | Soft stop and restart, records retained |
factory | Restart from scratch after clearing everything |
Other: Discard mode PnSException. This call remains unchanged IP.
Example:
device.ResetDevice("communication");