Skip to main content

Diagnosis

By reading device.diagnostics() diagnostics and alarms (diag_snapshot() / alarms() still available).​

Use in conjunction with the event

We recommend using Event Handle driver exceptions rather than polling manually. Direct diagnostic reading is suitable for display on the interface.

Feature Overview​

FeaturesNote
Diagnostic SnapshotLinks, Frame Count, Watchdog, Jitter, Alarm Monitoring
On-Site Issue ComparisonSelect a field based on symptoms
IOPS / IOCSProcess Data Quality
Call the PoliceEvent List / History / Confirm
I&M IdentificationOrder Number, Serial Number, Station Name
User RecordsTrough Parameter Records
ResetCommunication Reset / Factory Reset

Diagnostic Snapshot​

CategoryMembersTypeNote
AvailabilityokboolCheck if diagnostics are available. false = Device is not running; reading... message
Availabilityshared_memory_mappedboolIs the process data ready?
AvailabilitymessageStringReason for unavailability; empty when available
AvailabilitytimestampStringSnapshot Time (ISO-8601 Original Text)
LinkstateStringOperational Status Copy
Linklink_upboolIs the network card link up?
LinkconnectedboolAre the cycle data normal?
Linkactive_iocr_countu32Number of active IO connections
Linkiocr_active / iocr_healthyu32IO Connection Activation / Health Bitmap
Countingheartbeat / cycle_counteru64Heartbeat / Cycle Count
Countinglast_erroru64Recent error codes (0 = None)
Countingrx_frames / tx_framesu64Total Number of Frames Received / Sent
Countingrx_rt_frames / tx_rt_framesu64Receive / Transmit RT Cyclic Frame
Countingdropped_frames / invalid_framesu64Discarded / Illegal Frame
Countingwatchdog_tripsu64Number of watchdog timeouts
Countinglast_rx_tsc / last_tx_tscu64Most Recent Received / Sent Frames TSC
Process Areainput_area_length / output_area_lengthu32Zone I / Zone Q length (bytes). The length is determined by a value negotiated by the IO controller and is automatically matched after connection.
Cyclestack_cyclesu64Cycle Counting
Cyclestack_frames_rx / stack_frames_txu64Receive / Transmit Frame
Cyclestack_missed_ticksu64A Missed Beat
Cyclestack_max_jitter_usu64Maximum Jitter (microseconds)
Alarm Monitoringstack_alarm_rx_countu64Total Number of Alarms Received from the Controller
Alarm Monitoringstack_alarm_tx_ack_ok / stack_alarm_tx_ack_failu64The alarm on this machine has been acknowledged / Acknowledgment failed
Alarm Monitoringstack_alarm_ack_pendingu64In-Transit Alerts (0/1)
Alarm Monitoringstack_alarm_maint_stateu64Maintain Request Status
Alarm Monitoringstack_alarm_last_*u32Recently, the controller has been issuing the following alarm: arep / slot / subslot / type / seq / usi / len
Errorerror_codei32Original error code value (0 = None)
Errorerror_code_enum()PnSRuntimeErrorCodeThe 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 SymptomsSee which fields
The Ethernet cable isn't plugged in properly.snap.link_up
Is the cycle data available?snap.connected
The watchdog keeps jumpingsnap.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?alarms() / alarm_count()
Process Data Qualityio_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")?;