Skip to main content

Initialization

Recommendation Methods

Use PnSService(), wrap it in with, adjust it once start(), and write Q and read I in the loop.
First, install the Darra Profinet Slave. Set the station name and network card in the configuration tool; there is no need to specify the structure. Do not use PnSService() / in every cycle close().

Constructor​

PnSService()​

class PnSService:
def __init__(self, host: str = None, port: int = 18840) -> None

Create a new client instance. You can create a new instance even if the service hasn't started yet; no exception is thrown. This simply retrieves the object—it hasn't been activated yet IO,IO and the controller isn't connected either. No parameters are required for construction: host / port is the default Web API port (leaving it unspecified = real-time session IO ; recommended).

Example:

from darra_pns import PnSService, PnSErr

with PnSService() as svc:
rc = svc.start()
if rc != PnSErr.OK:
print(svc.last_service_error)
else:
while running:
# Write "Q", read "I" — write it here
pass
svc.stop()

with Enclose the entire program's lifetime; the loop is written in with Inside. start Once is enough. Q close is cleared at the end of each cycle, so anything written to it in the next cycle will be discarded.

Start-Stop​

start()​

def start(self) -> PnSErr

Enable IO, then return PnSErr. Success does not necessarily mean the IO controller is already switching data; that depends on connected. If it has already been started but not yet stopped, calling it again will simply return OK.

On failure, write last_service_error; normally no exception is thrown. If the service does not start, return the corresponding error code. The exception is when another instance is already running: return PnSErr.NOT_AVAILABLE without throwing.

Example:

rc = svc.start()
if rc != PnSErr.OK:
print(svc.last_service_error)

stop()​

def stop(self) -> None

Disabled IO. The instance is still running; you can try again start. If it has never been started or has already been stopped, it’s fine to call it again. If it fails last_service_error, log it; do not throw an exception.

Completely liberalize the use of close(), No stop().

Example:

svc.stop()

Resource Release​

close()​

def close(self) -> None

Release the instance. Q is cleared (only the data area is cleared); I is retained for the next program. Idempotent. with Exit the call and return to this method. Once released, this instance can no longer be used and must be re-created PnSService().

Disable IO stop(). stop The instance will still be there afterward, so you can start.

Example:

svc.close()