Skip to main content

Initialization

Recommendation Methods

Use PnSService::new(), set 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 close.

Constructor​

PnSService::new()​

pub fn new() -> PnSService

Create a new slave instance. You can create a new instance even if the service hasn't started yet; it simply returns nothing Result. This just retrieves the object—it hasn't been activated yet IO,IO and the controller isn't connected either.

connect() This is an old name; it is equivalent new(). It is not "Controller Connected."

Example:

use darra_pns::PnSService;

let mut device = PnSService::new();
device.start()?;

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

device.stop()?;

Keep the instance within the scope of the entire program's lifetime. Place the loop within that scope. 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()​

pub fn start(&self) -> ServiceResult<()>

Enable IO, then return ServiceResult<()>. 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(()).

Failure last_error(): Return ServiceError. The service did not start ( / ConnectFailed ) ServiceUnreachable; another instance is already running RealtimeGate(corresponding to PnSErrorCode::Busy).

Example:

device.start()?;

stop()​

pub fn stop(&self) -> ServiceResult<()>

Disabled IO. The instance is still there; 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, log it last_error().

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

Example:

device.stop()?;

Resource Release​

PnSService Implemented Drop; automatically when it goes out of scope close().

close()​

pub fn close(&mut self)

If it is still running, clear Q first, then release the instance. Q is cleared (only the data area); I is left alone for the next program. Idempotent. Once released this instance can no longer be used; you must make a new one with PnSService::new().

To stop IO use stop(). After stop the instance is still there, so you can start again.

Example:

device.close();