Skip to main content

Initialization

Recommendation Methods

Use new DarraPnS(), wrap it in using, 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 new / in every cycle Dispose.

Constructor​

DarraPnS()​

public DarraPnS()

Create a new IO Device instance. You can still 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 yet.

Example:

using (var device = new DarraPnS())
{
PnSErrorCode rc = device.Start();
if (rc != PnSErrorCode.Success)
return;

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

device.Stop();
}

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

Connect()​

public static DarraPnS Connect()

"Parameterless" is Connect() an old alias new DarraPnS() for the code — the same construct, the same instance, doesn't take up a link gate, and alsoDoes not indicate that the IO controller is connected. If you see it in existing code, leave it as is; just write it new DarraPnS() this way in new code.

Note that it isStaticMethod: Write it as DarraPnS.Connect(), not device.Connect().

Example:

using (var device = DarraPnS.Connect())   // Equivalent to new DarraPnS()
{
device.Start();
}

Don't confuse it with Connect(host, port): that overload is the Web API entry point; it probes GET /api/info, does not use a real-time link port, and does not handle real-time process data. For real-time read/write operations, use new DarraPnS().

Start-Stop​

Start()​

public PnSErrorCode Start()

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

In case of failure LastError, do not throw an exception. If the resource has been released, return; InvalidHandle if the service fails to start, return; ServiceUnreachable if startup fails, return NativeError. If another instance is already RUN, throw an exception InvalidOperationExceptionand record PnSErrorCode.Busy as the most recent fault code.

Example:

PnSErrorCode rc = device.Start();
if (rc != PnSErrorCode.Success)
{
Console.WriteLine(DarraPnS.LastError);
return;
}

Stop()​

public 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 Dispose(), No Stop().

Example:

device.Stop();

Resource Release​

Dispose()​

public void Dispose()

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—implemented IDisposable. Once released, this instance can no longer be used and must be re-created new DarraPnS().

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

Example:

device.Dispose();