Diagnosis
By reading device.diagnostics() diagnostics and alarms (diag_snapshot() / alarms() still available).
We recommend using Event Handle driver exceptions rather than polling manually. Direct diagnostic reading is suitable for display on the interface.
Feature Overview
| Features | Note |
|---|---|
| Diagnostic Snapshot | Links, Frame Count, Watchdog, Jitter, Alarm Monitoring |
| On-Site Issue Comparison | Select a field based on symptoms |
| IOPS / IOCS | Process Data Quality |
| Call the Police | Event List / History / Confirm |
| I&M Identification | Order Number, Serial Number, Station Name |
| User Records | Trough Parameter Records |
| Reset | Communication Reset / Factory Reset |
Diagnostic Snapshot
| Category | Members | Type | Note |
|---|---|---|---|
| Availability | ok | bool | Check if diagnostics are available. false = Device is not running; reading... message |
| Availability | shared_memory_mapped | bool | Is the process data ready? |
| Availability | message | String | Reason for unavailability; empty when available |
| Availability | timestamp | String | Snapshot Time (ISO-8601 Original Text) |
| Link | state | String | Operational Status Copy |
| Link | link_up | bool | Is the network card link up? |
| Link | connected | bool | Are the cycle data normal? |
| Link | active_iocr_count | u32 | Number of active IO connections |
| Link | iocr_active / iocr_healthy | u32 | IO Connection Activation / Health Bitmap |
| Counting | heartbeat / cycle_counter | u64 | Heartbeat / Cycle Count |
| Counting | last_error | u64 | Recent error codes (0 = None) |
| Counting | rx_frames / tx_frames | u64 | Total Number of Frames Received / Sent |
| Counting | rx_rt_frames / tx_rt_frames | u64 | Receive / Transmit RT Cyclic Frame |
| Counting | dropped_frames / invalid_frames | u64 | Discarded / Illegal Frame |
| Counting | watchdog_trips | u64 | Number of watchdog timeouts |
| Counting | last_rx_tsc / last_tx_tsc | u64 | Most Recent Received / Sent Frames TSC |
| Process Area | input_area_length / output_area_length | u32 | Zone I / Zone Q length (bytes). The length is determined by a value negotiated by the IO controller and is automatically matched after connection. |
| Cycle | stack_cycles | u64 | Cycle Counting |
| Cycle | stack_frames_rx / stack_frames_tx | u64 | Receive / Transmit Frame |
| Cycle | stack_missed_ticks | u64 | A Missed Beat |
| Cycle | stack_max_jitter_us | u64 | Maximum Jitter (microseconds) |
| Alarm Monitoring | stack_alarm_rx_count | u64 | Total Number of Alarms Received from the Controller |
| Alarm Monitoring | stack_alarm_tx_ack_ok / stack_alarm_tx_ack_fail | u64 | The alarm on this machine has been acknowledged / Acknowledgment failed |
| Alarm Monitoring | stack_alarm_ack_pending | u64 | In-Transit Alerts (0/1) |
| Alarm Monitoring | stack_alarm_maint_state | u64 | Maintain Request Status |
| Alarm Monitoring | stack_alarm_last_* | u32 | Recently, the controller has been issuing the following alarm: arep / slot / subslot / type / seq / usi / len |
| Error | error_code | i32 | Original error code value (0 = None) |
| Error | error_code_enum() | PnSRuntimeErrorCode | The enumeration form of the previous item. The unrecognized value is "Unknown." |
diag_snapshot()
pub fn diag_snapshot(&self) -> ServiceResult<DiagSnapshot>
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.
Example:
let snap = device.diag_snapshot()?;
if !snap.ok {
println!("{}", snap.message);
return Ok(());
}
println!("{}", if snap.link_up { "Up" } else { "Down" });
println!("{}", if snap.connected { "周期交换正常" } else { "未建立" });
println!("帧: {} / {}", snap.rx_frames, snap.tx_frames);
println!("看门狗: {}", snap.watchdog_trips);
On-Site Issue Comparison
| On-site Symptoms | See which fields |
|---|---|
| The Ethernet cable isn't plugged in properly. | snap.link_up |
| Is the cycle data available? | snap.connected |
| The watchdog keeps jumping | snap.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? | alarms() / alarm_count() |
| Process Data Quality | io_status() |
IOPS / IOCS
pub fn io_status(&self) -> IoStatus
Is the process data good? 0x80 = GOOD, 0x00 = BAD. If the connection is lost, mark it all as BAD. If it hasn't started or the request failed, return IoStatus::empty().
pub struct IoStatus {
pub input_iops: Vec<Ioxs>,
pub input_iocs: Vec<Ioxs>,
pub output_iops: Vec<Ioxs>,
pub output_iocs: Vec<Ioxs>,
pub input_valid: bool,
pub output_valid: bool,
}
impl IoStatus {
pub fn empty() -> Self;
pub fn is_good(ioxs: Ioxs) -> bool; // Ioxs::Good = 0x80
pub fn is_all_good_bytes(ioxs: &[Ioxs]) -> bool; // empty = false
pub fn input_data_good(&self) -> bool;
pub fn output_data_good(&self) -> bool;
pub fn output_consumed(&self) -> bool;
pub fn all_good(&self) -> bool;
}
Example:
if !device.io_status().all_good() {
println!("{:?}", device.io_status());
}
Call the Police
Empty list = No active alerts; this does not indicate a failure. If the response is not a list BadResponse, an alert is triggered; it is not treated as "no alerts."
pub struct AlarmItem {
pub id: String, // For example, PnS.LinkDown
pub severity: String, // Info / Warning / Error / Critical
pub message: String,
pub occurred_at: String, // ISO-8601 Original Text
pub count: u32, // ≥1
pub source: String,
}
alarms()
pub fn alarms(&self) -> ServiceResult<Vec<AlarmItem>>
Current activity alert. If there are no activity alerts, an empty list is returned; this does not indicate a failure.
Example:
for a in device.alarms()? {
println!("{} {} {}", a.id, a.severity, a.message);
}
alarm_history()
pub fn alarm_history(&self) -> ServiceResult<Vec<AlarmItem>>
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:
for a in device.alarm_history()? {
println!("{} {} {}", a.occurred_at, a.severity, a.message);
}
ack_alarm / acknowledge_alarm
pub fn ack_alarm(&self, id: &str) -> ServiceResult<()>
Confirm an active alert. The ID is retrieved from alarms(). If this active alert does not exist, an error will be returned. acknowledge_alarm This is the same function.
Example:
device.ack_alarm("PnS.LinkDown")?;
ack_all_alarms / acknowledge_all_alarms
pub fn ack_all_alarms(&self) -> ServiceResult<u32>
Acknowledges all activity alarms. Returns the number of alarms acknowledged (0 = no activity alarms). acknowledge_all_alarms This is the same function.
Example:
let n = device.ack_all_alarms()?;
I&M Identification
pub fn im_data(&self) -> ServiceResult<ImData>
Order number, serial number, station name. I&M1–I&M3 has been enabled by the native stack and read back accurately; I&M4 has not been enabled; if the IO controller has never been programmed, the value read from the stack is the factory default placeholder. Missing fields are left blank / 0 / false; what is read this time depends on im14_supported and im_note.
pub struct ImData {
pub vendor_id: u32,
pub device_id: u32,
pub order_id: String,
pub serial_number: String,
pub hardware_revision: String,
pub software_revision: String,
pub station_name: String,
pub product_name: String,
pub im_supported: String,
pub im14_supported: bool,
pub im1_tag_function: String,
pub im1_tag_location: String,
pub im2_date: String,
pub im3_descriptor: String,
pub im4_signature_hex: String,
pub im_note: String,
pub project_order_number: String,
pub project_hardware_release: String,
pub project_software_release: String,
pub timestamp: String,
}
Example:
let im = device.im_data()?;
println!("{} {:04X} {:04X}", im.station_name, im.vendor_id, im.device_id);
User Records
pub fn records(&self) -> ServiceResult<UserRecords>
Reads the user area record table (Index 0x0000 – 0x7FFF). Missing fields default to 0 or are left blank. count This is a server-side return value; it is not padded to match the array length.
pub struct UserRecords {
pub records: Vec<UserRecord>,
pub count: i32,
pub timestamp: String,
}
pub struct UserRecord {
pub slot: u16,
pub subslot: u16,
pub index: u16,
pub length: u16,
pub data_hex: String,
}
Reset
pub fn reset_device(&self, mode: &str) -> ServiceResult<()>
communication: Soft Stop and Restart (Records Retained)factory: Restart from scratch after deletion (clear history)
Illegal mode Return InvalidParam. This is a slow operation; it may take a few seconds.
Example:
device.reset_device("communication")?;