Skip to main content

Diagnosis

By reading device.Diagnostics() diagnostics and alarms (DiagSnapshot() / GetAlarms() still available).​

Use in conjunction with the event

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​

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

Diagnostic Snapshot​

CategoryPropertyTypeAccessDescription
Availabilityokboolread-onlyChecks whether the device is available. false = Device is not RUN; read 'message'
shared_memory_mappedboolread-onlyWhether the procedure data is ready
messagestringread-onlyReason for unavailability; empty when available
Linksstatestringread-onlyOperational ST description
link_upboolread-onlyIs the network interface link up?
connectedboolread-onlyWhether the cycle data is normal
active_iocr_countuint32_tread-onlyNumber of active IO connections
iocr_activeuint32_tread-onlyIO link activation bitmap
iocr_healthyuint32_tread-onlyIO link health bitmap
Countingheartbeatuint64_tread-onlyheartbeat count
cycle_counteruint64_tread-onlyCycle counter
last_erroruint64_tread-onlyLast fault code (0 = none)
rx_frames / tx_framesuint64_tread-onlyTotal number of received / transmitted frames
rx_rt_frames / tx_rt_framesuint64_tread-onlyReceive / transmit RT cycle frames
dropped_framesuint64_tread-onlydropped frames
invalid_framesuint64_tread-onlyinvalid frames
watchdog_tripsuint64_tread-onlyNumber of watchdog timeouts
last_rx_tsc / last_tx_tscuint64_tread-onlyLast received / transmitted frame TSC
Process Areainput_area_lengthuint32_tread-onlyInput 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_lengthuint32_tread-onlyOutput 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
Cyclestack_cyclesuint64_tread-onlyCycle count
stack_frames_rx / stack_frames_txuint64_tread-onlyReceived / Transmitted Frames
stack_missed_ticksuint64_tread-onlyMissed ticks
stack_max_jitter_usuint64_tread-onlyMaximum jitter (microseconds)
Alarm Monitoringstack_alarm_rx_countuint64_tread-onlyTotal number of controller alarms received
stack_alarm_tx_ack_okuint64_tread-onlyNumber of times the local alarm has been acknowledged
stack_alarm_tx_ack_failuint64_tread-onlyNumber of failed alarm acknowledgments on this machine
stack_alarm_ack_pendinguint64_tread-onlyAlarm in transit (0/1)
stack_alarm_maint_stateuint64_tread-onlyMaintenance request ST
stack_alarm_last_arepuint32_tread-onlyLatest controller alarm: Arep
stack_alarm_last_slotuint32_tread-onlyLast controller alarm: slot
stack_alarm_last_subslotuint32_tread-onlyLatest controller alarm: subslot
stack_alarm_last_typeuint32_tread-onlyLast controller alarm: type
stack_alarm_last_sequint32_tread-onlyLatest controller alarm: sequence number
stack_alarm_last_usiuint32_tread-onlyLatest controller alarm:USI
stack_alarm_last_lenuint32_tread-onlyLast controller alarm: load length
faulterror_codeintread-onlyRaw 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 SymptomsSee which fields
The Ethernet cable isn't plugged in properly.DiagSnapshot().link_up
Is the cycle data available?DiagSnapshot().connected
The watchdog keeps jumpingDiagSnapshot().watchdog_trips
Frames are being droppeddropped_frames + invalid_frames
Is the cycle stable?stack_max_jitter_us + stack_missed_ticks
Controller alarm not clearedstack_alarm_ack_pending / stack_alarm_tx_ack_fail
Does this machine have a motion alarm?GetAlarms() / AlarmCount()

Call the Police​

CategoryPropertyTypeAccessDescription
CountingAlarmCount()intread-onlyTotal number of active alarms. Same GetAlarms as
CriticalAlarmCount()intread-onlyNumber of critical alarms
arrayGetAlarms()vector<PnSServiceAlarmItem>Read-onlyCurrent active alarms. An empty array indicates no active alarms; this does not mean a failure
GetAlarmHistory()vector<PnSServiceAlarmItem>Read-onlyHistory. 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 string PnSException; 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
PropertiesTypeNote
idstringAlert ID (e.g., PnS.LinkDown)
severitystringSeverity: Info / Warning / Error / Critical
messagestringAlert Message
occurred_atstringLast occurrence (ISO-8601 text)
countintNumber of occurrences (≥1)
sourcestringSource

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);
modeBehavior
communicationSoft stop and restart, records retained
factoryRestart from scratch after clearing everything

Other: Discard mode PnSException. This call remains unchanged IP.

Example:

device.ResetDevice("communication");