Struct linuxcnc_hal::hal_pin::OutputPin
source · pub struct OutputPin<S> { /* private fields */ }
Expand description
A pin that can be written to by the component
Supported pin types are as follows
Type | Storage | Equivalent linuxcnc_hal_sys function |
---|---|---|
OutputPin<f64> | f64 | hal_pin_float_new |
OutputPin<u32> | u32 | hal_pin_u32_new |
OutputPin<i32> | i32 | hal_pin_s32_new |
OutputPin<bool> | bool | hal_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
sourceimpl HalPin for OutputPin<bool>
impl HalPin for OutputPin<bool>
sourcefn storage_mut(&self) -> Result<&mut Self::Storage, StorageError>
fn storage_mut(&self) -> Result<&mut Self::Storage, StorageError>
Get a mutable pointer to underlying shared memory storing this pin’s value
sourcefn storage(&self) -> Result<&Self::Storage, StorageError>
fn storage(&self) -> Result<&Self::Storage, StorageError>
Get a reference to the underlying shared memory storing the pin’s value
sourcefn register(
full_pin_name: &str,
component_id: i32
) -> Result<Self, PinRegisterError>
fn register(
full_pin_name: &str,
component_id: i32
) -> Result<Self, PinRegisterError>
Register the pin with the LinuxCNC HAL Read more
sourcefn allocate_storage() -> Result<*mut *mut Self::Storage, StorageError>
fn allocate_storage() -> Result<*mut *mut Self::Storage, StorageError>
Allocate memory using
hal_malloc()
for storing pin value in Read moresourceimpl HalPin for OutputPin<f64>
impl HalPin for OutputPin<f64>
sourcefn storage_mut(&self) -> Result<&mut Self::Storage, StorageError>
fn storage_mut(&self) -> Result<&mut Self::Storage, StorageError>
Get a mutable pointer to underlying shared memory storing this pin’s value
sourcefn storage(&self) -> Result<&Self::Storage, StorageError>
fn storage(&self) -> Result<&Self::Storage, StorageError>
Get a reference to the underlying shared memory storing the pin’s value
sourcefn register(
full_pin_name: &str,
component_id: i32
) -> Result<Self, PinRegisterError>
fn register(
full_pin_name: &str,
component_id: i32
) -> Result<Self, PinRegisterError>
Register the pin with the LinuxCNC HAL Read more
sourcefn allocate_storage() -> Result<*mut *mut Self::Storage, StorageError>
fn allocate_storage() -> Result<*mut *mut Self::Storage, StorageError>
Allocate memory using
hal_malloc()
for storing pin value in Read moresourceimpl HalPin for OutputPin<i32>
impl HalPin for OutputPin<i32>
sourcefn storage_mut(&self) -> Result<&mut Self::Storage, StorageError>
fn storage_mut(&self) -> Result<&mut Self::Storage, StorageError>
Get a mutable pointer to underlying shared memory storing this pin’s value
sourcefn storage(&self) -> Result<&Self::Storage, StorageError>
fn storage(&self) -> Result<&Self::Storage, StorageError>
Get a reference to the underlying shared memory storing the pin’s value
sourcefn register(
full_pin_name: &str,
component_id: i32
) -> Result<Self, PinRegisterError>
fn register(
full_pin_name: &str,
component_id: i32
) -> Result<Self, PinRegisterError>
Register the pin with the LinuxCNC HAL Read more
sourcefn allocate_storage() -> Result<*mut *mut Self::Storage, StorageError>
fn allocate_storage() -> Result<*mut *mut Self::Storage, StorageError>
Allocate memory using
hal_malloc()
for storing pin value in Read moresourceimpl HalPin for OutputPin<u32>
impl HalPin for OutputPin<u32>
sourcefn storage_mut(&self) -> Result<&mut Self::Storage, StorageError>
fn storage_mut(&self) -> Result<&mut Self::Storage, StorageError>
Get a mutable pointer to underlying shared memory storing this pin’s value
sourcefn storage(&self) -> Result<&Self::Storage, StorageError>
fn storage(&self) -> Result<&Self::Storage, StorageError>
Get a reference to the underlying shared memory storing the pin’s value
sourcefn register(
full_pin_name: &str,
component_id: i32
) -> Result<Self, PinRegisterError>
fn register(
full_pin_name: &str,
component_id: i32
) -> Result<Self, PinRegisterError>
Register the pin with the LinuxCNC HAL Read more
sourcefn allocate_storage() -> Result<*mut *mut Self::Storage, StorageError>
fn allocate_storage() -> Result<*mut *mut Self::Storage, StorageError>
Allocate memory using
hal_malloc()
for storing pin value in Read moreAuto Trait Implementations
impl<S> RefUnwindSafe for OutputPin<S>where
S: RefUnwindSafe,
impl<S> !Send for OutputPin<S>
impl<S> !Sync for OutputPin<S>
impl<S> Unpin for OutputPin<S>
impl<S> UnwindSafe for OutputPin<S>where
S: RefUnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more