PnSService
PROFINET IO Device The interface. Start the device, write to Q and read from I, view the operating status, and run diagnostics.
This product is designed SDK exclusively for this purpose PROFINET IO Deviceand does not provide interfaces for other fieldbus protocols.
Class Structure
PnSService # Device instance
│
├── process_data → ProcessData # Write Q / read I
│ ├── inputs_mapping / outputs_mapping # Map once
│ ├── read_struct / write_struct # Snapshot, value does not change by itself
│ ├── In # Read I (module input), read-only
│ └── Out # Write Q (module output), writable
├── events → PnSEvents # Operating state events
│ ├── add_connected_changed # Cyclic exchange on/off
│ ├── add_state_changed # Operating state change
│ ├── add_error_occurred # Runtime error
│ └── add_logged # Each event above also logs this
├── diagnostics → PnSDiagnostics # Diagnostics sub-object (snapshot / IOPS / alarms / records)
│ ├── snapshot # Diagnostics snapshot
│ ├── io_status # IOPS / IOCS
│ ├── alarms / alarm_history # Local alarms / history
│ └── records # User area records
│
├── connected / state / wait_reason # Cyclic exchange / operating state / wait reason
├── ever_connected / error_code # Ever connected / runtime error
└── im_data # I&M identifier
Write Q (module output, device → controller), read I (module input, controller → device). The "flat" attribute
diag_snapshot/ is stillalarmsavailable and corresponds todiagnosticsthe same data.
Usage
Start-Stop
from darra_pns import PnSService, PnSErr
with PnSService() as svc:
rc = svc.start()
if rc != PnSErr.OK:
return
while running:
if not svc.connected:
# svc.wait_reason
continue
svc.write_bool("Q0.0", True) # Write Q
from_plc = svc.read_bool("I0.0") # Read I
svc.stop()
You don't need an example to see the state: PnSService.is_service_ready / PnSService.service_connected / PnSService.service_wait_reason.
Process Data
| Method | Visit | Note |
|---|---|---|
| Process Data | svc.process_data.inputs_mapping(S) / outputs_mapping(S) | Map once |
| Process Data | svc.process_data | Snapshot read_struct / write_struct, In / Out bytes |
Identification
name = svc.im_data.station_name
vendor = svc.im_data.vendor_id
product = svc.im_data.device_id
Reading and Writing Process Data
Word and double-word types are big-endian.
The "Golden Path" involves a single mapping: when the source changes, the field changes accordingly (structures must be used _pack_ = 1).
import ctypes
class FromPlc(ctypes.BigEndianStructure):
_pack_ = 1
_fields_ = [("a", ctypes.c_uint8),
("b", ctypes.c_int16),
("flag", ctypes.c_uint8)]
# Map once
inp = svc.process_data.inputs_mapping(FromPlc)
outp = svc.process_data.outputs_mapping(FromPlc)
present = inp.a # It changes on its own after the bus is refreshed
outp.a = 1 # Video of the Direct Drop Process
# Snapshot: It won't change on its own after you copy it out
status, pos = svc.process_data.read_struct("Hi")
svc.process_data.write_struct("Hi", 1, -2)
svc.process_data.Out[0].content = 0x11
v = svc.process_data.In[0].content
Diagnostics and Alarms
Through diagnostic reading svc.diagnostics (read-only snapshots: links, frame count, watchdog, jitter, and alarm monitoring).
snap = svc.diagnostics.snapshot
if not snap.ok:
print(snap.message)
for a in svc.diagnostics.alarms:
print(a.message)