Diagnosis
By reading device.Diagnostics diagnostics and alarms (DiagSnapshot / Alarms still available, same data).
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 .
This page covers only diagnostic snapshots,IOPS /IOCS , and alerts.
Feature Overview
| Features | Note |
|---|---|
| Diagnostic Snapshot | Links, Frame Count, Watchdog, Jitter, Alarm Monitoring |
| IOPS / IOCS | Process Data Quality: Is the Data GOOD or BAD? |
| On-Site Issue Comparison | Select a field based on symptoms |
| Call the Police | Event List / History / Confirm |
| User Records | User Area Record Table (Records) |
| Reset | Communication Reset / Factory Reset |
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 |
SharedMemoryMapped | bool | read-only | Whether the process data is ready | |
Message | string | read-only | Reason for unavailability; empty when available | |
Timestamp | DateTime | Read-only | Snapshot creation time | |
| Links | State | string | read-only | Operational ST description |
LinkUp | bool | read-only | Is the network interface link up? | |
Connected | bool | read-only | Whether the cycle data is normal | |
ActiveIocrCount | uint | read-only | Number of active IO connections | |
IocrActive | uint | read-only | IO link activation bitmap | |
IocrHealthy | uint | read-only | IO link health bitmap | |
| Counting | Heartbeat | ulong | read-only | Heartbeat count |
CycleCounter | ulong | read-only | Cycle counter | |
LastError | ulong | read-only | Last fault code (0 = none) | |
RxFrames / TxFrames | ulong | read-only | Total number of received / transmitted frames | |
RxRtFrames / TxRtFrames | ulong | read-only | Receive / transmit RT cycle frames | |
DroppedFrames | ulong | read-only | Dropped frames | |
InvalidFrames | ulong | read-only | Invalid frames | |
WatchdogTrips | ulong | read-only | Number of watchdog timeouts | |
LastRxTsc / LastTxTsc | ulong | read-only | Last received / transmitted frame TSC | |
| Process Area | InputAreaLength | uint | read-only | Input area length (bytes). The length is determined by a value negotiated with the IO controller and is automatically matched after link |
OutputAreaLength | uint | read-only | Output area length (bytes). The length is determined by a value negotiated with the IO controller and is automatically matched after link | |
| Cycle | StackCycles | ulong | read-only | Cycle count |
StackFramesRx / StackFramesTx | ulong | read-only | Receive / Transmit Frames | |
StackMissedTicks | ulong | read-only | Missed ticks | |
StackMaxJitterUs | ulong | read-only | Maximum jitter (microseconds) | |
| Alarm Monitoring | StackAlarmRxCount | ulong | read-only | Total number of alarms received from the controller |
StackAlarmTxAckOk | ulong | read-only | Number of times the local alarm has been acknowledged | |
StackAlarmTxAckFail | ulong | read-only | Number of local alarm acknowledgment failures | |
StackAlarmAckPending | ulong | read-only | Alarms in transit (0/1) | |
StackAlarmMaintState | ulong | read-only | Maintenance request ST | |
StackAlarmLastArep | uint | read-only | Latest controller alarm: Arep | |
StackAlarmLastSlot | uint | read-only | Last controller alarm: slot | |
StackAlarmLastSubslot | uint | read-only | Latest controller alarm: subslot | |
StackAlarmLastType | uint | read-only | Last controller alarm: type | |
StackAlarmLastSeq | uint | read-only | Last controller alarm: sequence number | |
StackAlarmLastUsi | uint | read-only | Last controller alarm:USI | |
StackAlarmLastLen | uint | read-only | Last controller alarm: load length | |
| fault | ErrorCode | int | read-only | Original fault code value (0 = none) |
ErrorCodeEnum | PnSRuntimeErrorCode | read-only | The enumeration form of the previous item. Unrecognized values are treated as 'Unknown' |
DiagSnapshot
public PnSDiagSnapshot DiagSnapshot { get; }
Retrieves the current diagnostic snapshot once; suitable for interface refreshes and logging. If the device has not yet booted Ok == false, a "read Message" operation is not considered an error.
Return value:
PnSDiagSnapshot— Diagnostic Data Snapshot
Stop-loss PnSServiceException.
Example:
PnSDiagSnapshot snap = device.DiagSnapshot;
if (!snap.Ok)
{
Console.WriteLine(snap.Message);
return;
}
Console.WriteLine(snap.LinkUp ? "Up" : "Down");
Console.WriteLine(snap.Connected ? "周期交换正常" : "未建立");
Console.WriteLine($"帧: {snap.RxFrames} / {snap.TxFrames}");
Console.WriteLine($"看门狗: {snap.WatchdogTrips}");
IOPS / IOCS
IoStatus
public PnSIoStatus IoStatus { get; }
Each process data byte corresponds to a ST byte: 0x80 = GOOD, 0x00 = BAD. If the link is lost, all ST bytes are set to BAD; GOOD is never reported. If the process has not started or cannot be read, the return value is PnSIoStatus.Empty(all criteria met false), and no exception is thrown. device.Diagnostics.IoStatus This data is the same as that of this property.
Return value:
PnSIoStatus— IOPS / IOCS Snapshot
| Category | Property | Type | Access | Description |
|---|---|---|---|---|
| ST Bytes | InputIops / InputIocs | byte[] | read-only | Zone I: Provided by the controller / Returned after consumption by this device. Returns a copy; modifications do not affect this object |
OutputIops / OutputIocs | byte[] | read-only | Q-zone: Provided by this device / Reported after consumption by the controller | |
| Criteria | InputValid / OutputValid | bool | read-only | In this round, a message was received from Zone I / a message was written to Q and delivered to the controller (cable break or failure to send = false) |
InputDataGood | bool | read-only | I has been received and all IOPS inputs are GOOD | |
OutputDataGood | bool | read-only | Q has been written and all IOPS outputs are GOOD | |
OutputConsumed | bool | read-only | Output: All IOCS GOOD (controller has consumed) | |
AllGood | bool | read-only | input variable (VAR_INPUT) valid + output variable (VAR_OUTPUT) valid + Output consumed | |
| Factory | PnSIoStatus.Empty | PnSIoStatus | Read-only | Empty ST (not powered on / cannot be read). All criteria are false |
Example:
PnSIoStatus io = device.IoStatus;
if (!io.AllGood)
{
Console.WriteLine(io);
if (!io.InputDataGood)
Console.WriteLine("控制器送来的数据不可用");
}
On-Site Issue Comparison
| On-site Symptoms | See which fields |
|---|---|
| The Ethernet cable isn't plugged in properly. | DiagSnapshot.LinkUp |
| Is the cycle data available? | DiagSnapshot.Connected |
| The watchdog keeps jumping | DiagSnapshot.WatchdogTrips |
| Frames are being dropped | DroppedFrames + InvalidFrames |
| Is the cycle stable? | StackMaxJitterUs + StackMissedTicks |
| Controller alarm not cleared | StackAlarmAckPending / StackAlarmTxAckFail |
| Does this machine have a motion alarm? | Alarms / AlarmCount |
Call the Police
| Category | Property | Type | Access | Description |
|---|---|---|---|---|
| Counting | AlarmCount | int | read-only | Total number of active alarms. Derived from Alarms |
CriticalAlarmCount | int | read-only | Number of critical alarms | |
| array | Alarms | List<PnSAlarmItem> | Read-only | Current active alerts. An empty array means there are no active alerts; this does not indicate a failure |
AlarmHistory | List<PnSAlarmItem> | Read-only | History (last 500 entries, sorted by time in ascending order). Empty array = no history |
The old fault-handling method has been removed and replaced with the Alarms / property AlarmHistory. A failure is thrown PnSServiceException.
Alarms
public List<PnSAlarmItem> Alarms { get; }
Current activity alert. If there are no activity alerts, an empty list is returned; this does not indicate a failure.
Return value:
List<PnSAlarmItem>— array of Event Alerts
Example:
foreach (PnSAlarmItem a in device.Alarms)
Console.WriteLine(a.ToString());
AlarmHistory
public List<PnSAlarmItem> AlarmHistory { get; }
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.
Return value:
List<PnSAlarmItem>— History array
Example:
foreach (PnSAlarmItem a in device.AlarmHistory)
Console.WriteLine($"{a.OccurredAt:s} {a.Severity} {a.Message}");
AcknowledgeAlarm
public void AcknowledgeAlarm(string id)
Confirm an active alert. The ID is taken from Alarms.
Parameters:
id(string) — Alert ID. Throws an exception if the string is emptyArgumentException; throws an exception if this ID does not exist.PnSServiceException
Example:
device.AcknowledgeAlarm("PnS.LinkDown");
AcknowledgeAllAlarms
public int AcknowledgeAllAlarms()
Confirm all activity alarms.
Return value:
int— Number of confirmed events (0 = no active alarms)
Example:
int n = device.AcknowledgeAllAlarms();
PnSAlarmItem
| Properties | Type | Note |
|---|---|---|
| Id | string | Alert ID (e.g., PnS.LinkDown) |
| Severity | string | Severity: Info / Warning / Error / Critical |
| Message | string | Alert Message |
| OccurredAt | DateTime | Time of the most recent occurrence |
| Count | int | Number of occurrences (≥1) |
| Source | string | Source |
User Records
Records
public PnSUserRecords Records { get; }
Retrieve the user area record table (Index 0x0000–0x7FFF). Missing fields substitution value to 0 or empty; no values are fabricated. If no records are found, an empty table is returned; this does not indicate a failure. device.Diagnostics.Records The data is the same as this property.
User Area Records (0x0000–0x7FFF) and I&M (0xAFF0–0xAFF4) areTwo Different Index Spaces, involving two different endpoints: This property read operation /api/recordsonly overwrites the user area; I&M in ImData (/api/im).
Don't treat the two endpoints as a single table—you won't find them by Records looking through the I&M index.
Failure Exception PnSServiceException: Service unreachable ServiceUnreachable(server response not 200) NativeError(includes server response errorCode).
Return value:
PnSUserRecords— Record Sheet
Example:
PnSUserRecords recs = device.Records;
foreach (PnSUserRecord r in recs.Records)
Console.WriteLine(
$"slot {r.Slot}/{r.Subslot} index 0x{r.Index:X4} len {r.Length} {r.DataHex}");
PnSUserRecords
| Properties | Type | Note |
|---|---|---|
| Records | PnSUserRecord[] | Number of records (empty = no records; this does not indicate a failure) |
| Count | int | Server-side count (missing fields are set to 0; values are not padded to match the array length) |
| Timestamp | DateTime | Snapshot creation time (field missing DateTime.MinValue) |
PnSUserRecord
| Properties | Type | Note |
|---|---|---|
| Slot | ushort | Bay |
| Subslot | ushort | subslot |
| Index | ushort | Records Index |
| Length | ushort | Number of data bytes |
| DataHex | string | Hexadecimal data (an empty string if the field is missing) |
Reset
ResetDevice()
public void ResetDevice(string mode)
Reset the IO Device. Use the server's existing start/stop state machine without terminating the server process.
mode | Behavior |
|---|---|
"communication" | Soft Stop and Restart, with Application Parameter Records Retained |
"factory" | After deletion, the system restarts from scratch, and application parameter records are cleared. |
This method is not responsible for IP resetting the communication parameters; this is still triggered DCP ResetToFactory by the controller.
Parameters:
mode(string) —"communication"or"factory". An empty string or any other value results in an exception.ArgumentException
Failure: Service Unreachable / Server Rejected PnSServiceException(with "server" in the message errorCode). This is a slow operation (internal shutdown/destruction followed by a restart, which can take several seconds); do not mistake it for a failure.
Example:
device.ResetDevice("communication");
If you reset while the controller is still exchanging data in a cycle, the controller will lose the station link and the diagnostic screen will flash. Wait until the link is disconnected before proceeding.