pub struct OutputPin<S> { /* private fields */ }
Expand description

A pin that can be written to by the component

Supported pin types are as follows

TypeStorageEquivalent linuxcnc_hal_sys function
OutputPin<f64>f64hal_pin_float_new
OutputPin<u32>u32hal_pin_u32_new
OutputPin<i32>i32hal_pin_s32_new
OutputPin<bool>boolhal_pin_bit_new

Examples

Create a pin

This example creates an OutputPin under demo-component.named-pin.

use linuxcnc_hal::{
   error::PinRegisterError,
   hal_pin::{OutputPin},
   prelude::*,
   HalComponent, RegisterResources, Resources,
};
use std::{
   error::Error,
   thread,
   time::{Duration, Instant},
};

struct Pins {
   pin: OutputPin<f64>,
}

impl Resources for Pins {
   type RegisterError = PinRegisterError;

   fn register_resources(comp: &RegisterResources) -> Result<Self, Self::RegisterError> {
       Ok(Pins {
           pin: comp.register_pin::<OutputPin<f64>>("named-pin")?,
       })
   }
}

fn main() -> Result<(), Box<dyn Error>> {
   let comp: HalComponent<Pins> = HalComponent::new("demo-component")?;

   let Pins { pin } = comp.resources();

   let start = Instant::now();

        // Main control loop
    while !comp.should_exit() {
        pin.set_value(123.45f64);
        thread::sleep(Duration::from_millis(1000));
    }

   Ok(())
}

Trait Implementations

Formats the value using the given formatter. Read more
Executes the destructor for this type. Read more
The underlying storage type for the given pin Read more
Get the pin’s name
Get a mutable pointer to underlying shared memory storing this pin’s value
Get a reference to the underlying shared memory storing the pin’s value
Register the pin with the LinuxCNC HAL Read more
Allocate memory using hal_malloc() for storing pin value in Read more
The underlying storage type for the given pin Read more
Get the pin’s name
Get a mutable pointer to underlying shared memory storing this pin’s value
Get a reference to the underlying shared memory storing the pin’s value
Register the pin with the LinuxCNC HAL Read more
Allocate memory using hal_malloc() for storing pin value in Read more
The underlying storage type for the given pin Read more
Get the pin’s name
Get a mutable pointer to underlying shared memory storing this pin’s value
Get a reference to the underlying shared memory storing the pin’s value
Register the pin with the LinuxCNC HAL Read more
Allocate memory using hal_malloc() for storing pin value in Read more
The underlying storage type for the given pin Read more
Get the pin’s name
Get a mutable pointer to underlying shared memory storing this pin’s value
Get a reference to the underlying shared memory storing the pin’s value
Register the pin with the LinuxCNC HAL Read more
Allocate memory using hal_malloc() for storing pin value in Read more
Set the value of the pin
Set the value of the pin
Set the value of the pin
Set the value of the pin

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.