Skip to main content

Python SDK Overview

Python packages for developing PROFINET IO Device applications. In the code from darra_pns import PnSService.

Installation​

Install from PyPI:

pip install darra-profinet-slave

You can also access it fromDownload PageDownload the whl file, or use the copy located in SDK\SDK_Python\ the installation directory.

Distribution Name and Import Name

The PyPI distribution name is darra-profinet-slave(pip install use this name), and the import name in the code is darra_pns. The two are independent (PEP 427), so do not mix them.

Environment​

  • Windows 10 / 11 x64
  • Python 3.12+
  • Darra Profinet Slave Installed

Quick Start​

After "Start", map once I / Q into a struct, then keep reading and writing fields through that variable. The struct is mapped onto the process image, so when the source changes the fields change with it; read_struct / write_struct are snapshots, and the copied instance will not change on its own. Writing I is not supported.

Cycle switching occurs automatically; there is no need to write your own cycle loop. Reads can be performed concurrently; for writes, the caller must serialize them.

import ctypes
from darra_pns import PnSService, PnSErr

class FromPlc(ctypes.BigEndianStructure): # I: Controller → Device
_pack_ = 1
_fields_ = [("present", ctypes.c_uint8),
("recipe", ctypes.c_int16)]

class ToPlc(ctypes.BigEndianStructure): # Q: Equipment → Controller
_pack_ = 1
_fields_ = [("ready", ctypes.c_uint8),
("busy", ctypes.c_uint8)]

with PnSService() as svc:
rc = svc.start()
if rc != PnSErr.OK:
print(svc.last_service_error)
else:
# Map once
inp = svc.process_data.inputs_mapping(FromPlc)
outp = svc.process_data.outputs_mapping(ToPlc)

while running:
if not svc.connected:
continue
present = inp.present # Read I: Changes on Its Own After Bus Refresh
outp.ready = 1 # Q: Impression of the straight-run process
svc.stop()

Structure Requirements _pack_ = 1: Multi-byte fields must use ctypes.BigEndianStructure(PROFINET network order).