Skip to main content

Rust SDK Overview

A crate for developing PROFINET IO Device applications. In the code use darra_pns::PnSService;.

Installation​

Install from crates.io io:

cargo add darra-profinet-slave

You can also access it fromDownload PageDownload the crate, or use the copy in SDK\SDK_Rust\ the installation directory.

Environment​

  • Windows 10 / 11 x64
  • Rust 1.70+ (edition 2021)
  • Darra Profinet Slave Installed

Quick Start​

After "Start", inputs_mappingmap onceoutputs_mapping with ** / **, then keep using this reference to read and write fields. Map it once — 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 returns ServiceError::OutputReadOnly.

Cycle switching occurs automatically; there is no need to write your own cycle loop, and any thread can use it simultaneously.

use darra_pns::{PnSService, ServiceResult};

#[repr(C, packed)]
struct FromPlc { present: u8, recipe: i16 } // I: Controller → Device
#[repr(C, packed)]
struct ToPlc { ready: u8, busy: u8 } // Q: Equipment → Controller

fn main() -> ServiceResult<()> {
let device = PnSService::new();
device.start()?;

// Map once
let inp = unsafe { device.process_data().inputs_mapping::<FromPlc>()? };
let outp = unsafe { device.process_data().outputs_mapping::<ToPlc>()? };

while running {
if !device.connected() {
continue;
}
let present = inp.present; // Read I: Changes on Its Own After Bus Refresh
outp.ready = 1; // Q: Write the process image directly
let _ = present;
}

device.stop()?;
Ok(())
}