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

A pin that can be both read from and written to

Supported pin types are as follows

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

Examples

Create a pin

This example creates a BidirectionalPin under demo-component.named-pin.

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

struct Pins {
   pin: BidirectionalPin<f64>,
}

impl Resources for Pins {
   type RegisterError = PinRegisterError;

   fn register_resources(comp: &RegisterResources) -> Result<Self, Self::RegisterError> {
       Ok(Pins {
           pin: comp.register_pin::<BidirectionalPin<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() {
            println!("Input: {:?}", pin.value());

            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
Get the value of the pin
Get the value of the pin
Get the value of the pin
Get the value of the pin
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.