Expand description
§profirust
- A PROFIBUS-DP compatible communication stack
profirust is structured according to the layered model of PROFIBUS:
- The
phy
module abstracts physical interfaces for RS-485 communication. - The
fdl
module implements the Fieldbus Data Link layer of basic bus communication and token passing between multiple master stations. - The
dp
module implements the PROFIBUS-DP (Decentralized Peripherals) application layer. This is where peripherals are managed and cyclic data exchange is facilitated.
§Example
To successfully communicate with a peripheral, you need to initialize and parameterize all layers. Here is an example:
use profirust::{Baudrate, fdl, dp, phy};
// Initialize the DP master:
// =========================
let buffer: [profirust::dp::PeripheralStorage; 4] = Default::default();
let mut dp_master = profirust::dp::DpMaster::new(buffer);
// or with `std`:
// let mut dp_master = dp::DpMaster::new(Vec::new());
// Let's add a peripheral:
// =======================
let remoteio_address = 7;
let remoteio_options = dp::PeripheralOptions {
// ...
// best generated using `gsdtool`
// ...
..Default::default()
};
let mut buffer_inputs = [0u8; 8];
let mut buffer_outputs = [0u8; 4];
let remoteio_handle = dp_master.add(dp::Peripheral::new(
remoteio_address, remoteio_options, &mut buffer_inputs[..], &mut buffer_outputs[..]
));
// Set up the FDL master and parameterize it:
// ==========================================
let master_address = 2;
let mut fdl = fdl::FdlActiveStation::new(
fdl::ParametersBuilder::new(master_address, Baudrate::B19200)
.slot_bits(300)
.build_verified(&dp_master)
);
// Initialize the PHY layer:
// =========================
let mut phy = phy::SerialPortPhy::new("/dev/ttyUSB0", fdl.parameters().baudrate);
// Now let's go live:
// ==================
fdl.set_online();
dp_master.enter_operate();
// Main Application Cycle
// ======================
loop {
let now = profirust::time::Instant::now();
fdl.poll(now, &mut phy, &mut dp_master);
let events = dp_master.take_last_events();
// Do something whenever new the DP cycle (for all peripherals) completes:
if events.cycle_completed {
let remoteio = dp_master.get_mut(remoteio_handle);
println!("Inputs: {:?}", remoteio.pi_i());
// Set some output bits
let pi_q = remoteio.pi_q_mut();
pi_q[0] = 0x80;
}
}
Modules§
- dp
- DP - Decentralized peripherals
- fdl
- FDL - Fieldbus data link
- phy
- PHY - Physical layer abstraction
- time
- Time structures.
Enums§
- Baudrate
- Baudrate for fieldbus communication