Struct linuxcnc_hal::hal_pin::BidirectionalPin
source · 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
Type | Storage | Equivalent linuxcnc_hal_sys function |
---|---|---|
BidirectionalPin<f64> | f64 | hal_pin_float_new |
BidirectionalPin<u32> | u32 | hal_pin_u32_new |
BidirectionalPin<i32> | i32 | hal_pin_s32_new |
BidirectionalPin<bool> | bool | hal_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
sourceimpl<S: Debug> Debug for BidirectionalPin<S>
impl<S: Debug> Debug for BidirectionalPin<S>
sourceimpl<S> Drop for BidirectionalPin<S>
impl<S> Drop for BidirectionalPin<S>
sourceimpl HalPin for BidirectionalPin<bool>
impl HalPin for BidirectionalPin<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 BidirectionalPin<f64>
impl HalPin for BidirectionalPin<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 BidirectionalPin<i32>
impl HalPin for BidirectionalPin<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 BidirectionalPin<u32>
impl HalPin for BidirectionalPin<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 moresourceimpl PinRead for BidirectionalPin<bool>
impl PinRead for BidirectionalPin<bool>
sourceimpl PinRead for BidirectionalPin<f64>
impl PinRead for BidirectionalPin<f64>
sourceimpl PinRead for BidirectionalPin<i32>
impl PinRead for BidirectionalPin<i32>
sourceimpl PinRead for BidirectionalPin<u32>
impl PinRead for BidirectionalPin<u32>
sourceimpl PinWrite for BidirectionalPin<bool>
impl PinWrite for BidirectionalPin<bool>
sourceimpl PinWrite for BidirectionalPin<f64>
impl PinWrite for BidirectionalPin<f64>
sourceimpl PinWrite for BidirectionalPin<i32>
impl PinWrite for BidirectionalPin<i32>
Auto Trait Implementations
impl<S> RefUnwindSafe for BidirectionalPin<S>where
S: RefUnwindSafe,
impl<S> !Send for BidirectionalPin<S>
impl<S> !Sync for BidirectionalPin<S>
impl<S> Unpin for BidirectionalPin<S>
impl<S> UnwindSafe for BidirectionalPin<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