Event
svc.events Subscribe to operational status events.
Each event is logged again when it is triggered add_logged(with the severity level matching the source event), regardless of whether a corresponding event has been subscribed to. Subscribe add_logged to receive messages in Chinese.
Network Card Link Not Active Event: add_link_changed Can be subscribed to, no errors are reported, but it does not trigger. Requires a link read. diag_snapshot.link_up.
IO Quality First add_io_status_changed. The first time a read occurs, IOPS only the baseline is recorded; no callback is triggered. inputIopsHex If both conditions are met outputIopsHex , no fiction is generated and no callback is triggered. A callback is triggered only when the byte count changes and the result is not "GOOD." The same rule applies across all six languages; a callback is not triggered on every read.
Feature Overview
| Category | Event | Note | Automatic Logging |
|---|---|---|---|
| Connect | svc.events.add_connected_changed | Alternate between on and off in sync with the IO controller's cycle | ✓ |
| Operating State | svc.events.add_state_changed | Changes in Operating State | ✓ |
| Runtime Error | svc.events.add_error_occurred | Runtime Error | ✓ |
| IO Quality | svc.events.add_io_status_changed | Changes in the "non-GOOD" byte count | ✓ |
| Link | svc.events.add_link_changed | If you can't receive it, don't subscribe. | — |
| Log | svc.events.add_logged | Each event listed above will trigger this one again. | — |
add_link_changed It won't work even after subscribingadd_link_changed Registration is successful and no fault messages are displayed, but the callback is not invoked. If there is no response after subscribing, you cannot assume that the network adapter is functioning properly. Please read diag_snapshot.link_up.
Unsubscribe
svc.events.remove_connected_changed(callback) -> int
svc.events.remove_state_changed(callback) -> int
svc.events.remove_error_occurred(callback) -> int
svc.events.remove_io_status_changed(callback) -> int
svc.events.remove_link_changed(callback) -> int
svc.events.remove_logged(callback) -> int
Removes all registered instances of this callback and returns the number of instances removed; returns 0 if none are registered; idempotent and does not throw exceptions. add_* Append only, no deduplication: If the same callback is subscribed to N times, it is triggered N times, remove_* and all instances are cleared at once. Callbacks execute synchronously on the thread that triggered the event; exceptions in a single callback are isolated and logged darra_pns , while subsequent callbacks continue to execute as normal.
Connect
add_connected_changed
svc.events.add_connected_changed(callback)
Triggered when the periodic data exchange connection is lost (connected == False where ever_connected == True = disconnection; ever_connected == False = never connected).
Callback parameters:
class PnSConnectedChangedEvent:
connected: bool # Is the data currently being updated for a new cycle?
ever_connected: bool # Have you ever connected to it?
level: PnSEventLevel # Connected = Info; Disconnected / Never Connected = Warn
Example:
def on_connected(e):
if not e.connected and e.ever_connected:
print("掉线")
svc.events.add_connected_changed(on_connected)
Operating State
add_state_changed
svc.events.add_state_changed(callback)
Triggered when the operating state changes (SDK observation only; does not actively switch states).
Callback parameters:
class PnSStateChangedEvent:
old_state: Any # Before the change, see [PnSState](./api#pnsstate)
new_state: Any # After the change
level: PnSEventLevel # Info
Example:
svc.events.add_state_changed(lambda e: print(f"{e.old_state} → {e.new_state}"))
add_error_occurred
svc.events.add_error_occurred(callback)
Triggered when a runtime error occurs; e.error_code it is an int primitive value; for enumeration types, use svc.error_code.
Callback parameters:
class PnSErrorOccurredEvent:
error_code: int # Original value of a runtime error (not an enumeration)
message: str # News in Chinese
level: PnSEventLevel # Warn
Example:
svc.events.add_error_occurred(lambda e: print(f"{e.error_code}: {e.message}"))
IO Quality
add_io_status_changed
svc.events.add_io_status_changed(callback)
The first time I read it, I IOPS only recorded the baseline and did not trigger a callback. inputIopsHex If both conditions are met outputIopsHex , no fiction is generated and no callback is triggered. A callback is triggered only when the number of non-GOOD bytes changes. A callback is not triggered on every read.
Callback parameters:
class PnSIoStatusChangedEvent:
iops_bad: int # IOPS Number of bytes GOOD where the value is not (ST != 0x80)
level: PnSEventLevel # BAD > 0 = Warn; otherwise, Info
Link
add_link_changed
svc.events.add_link_changed(callback)
It registers successfully, but does not trigger. For network interface connectivity, please read diag_snapshot.link_up.
Callback parameters:
class PnSLinkChangedEvent:
link_up: bool # Is the physical link up?
level: PnSEventLevel # Up = Info; Down = Warn
Log
add_logged
svc.events.add_logged(callback)
This message is sent again each time an event is triggered, and its severity level follows that of the source event.
Callback parameters:
level(PnSEventLevel) — Log Levelmessage(str) — Log Body
PnSEventLevel
Events and Log Levels.
class PnSEventLevel(IntEnum):
Info = 0 # Information
Warn = 1 # Warning
Error = 2 # Error
Connection = Info, Disconnected / Run error = Warn.
Example:
svc.events.add_logged(lambda level, message: print(f"[{level.name}] {message}"))