Skip to main content

Initialization

Recommendation Methods

Parameter-free constructor PnSService; call it once Start(); write to Q and read from I in the loop.
First, install the Darra Profinet IO Device. Set the station name and network card in the configuration tool; there is no need to transmit the structure. Do not transmit the structure / in every cycle Close().

Constructor​

PnSService()​

PnSService();

Create a new IO Device instance. It can be created 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.

Example:

PnSService device;
if (!device.Start())
return 1;

while (running)
{
// Write "Q", read "I" — write it here
}

device.Stop();

Write the loop while the object is alive. Start Once is enough. Each cycle Close() will clear Q, so anything written in the next cycle will be discarded. The destructor will handle this automatically Close().

Start-Stop​

Start()​

bool Start();

Enabled IO. Returned successfully true. A successful return does not necessarily mean the controller IO is already updating data; that depends on the situation Connected(). If it has already been started but not yet STOP, calling it again will return immediately true.

Write the failure LastError(), return, falseand do not throw. Another instance is already RUN and returning the same result false; the reason is also noted in [... LastError() ].

Example:

if (!device.Start())
{
printf("%s\n", LastError().c_str());
return 1;
}

Stop()​

void Stop();

Disabled IO. The instance is still there; you can try again Start(). If it has never been started or has already been STOP, it's fine to call it again. If it fails LastError(), log it; do not throw an exception.

Completely liberalize the use of Close(), No Stop().

Example:

device.Stop();

Resource Release​

Close()​

void Close();

If it's still RUN Stop, release the instance first. Q will be cleared (only the data area); I will be retained for the next program. Idempotent. The destructor will be called automatically; usually, you don't need to call it manually. Once released, this instance can no longer be used.

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

Example:

device.Close();