[][src]Struct rpos_drv::Channel

pub struct Channel<P, T: ?Sized> { /* fields omitted */ }

Channel encode and decode message with protocol, and send and receive bytes via stream

Examples

This example is not tested
let mut channel = Channel::new(
    RplidarProtocol::new(),
    serial_port
);
 
channel.write(&Message::new(1)).unwrap();

Methods

impl<P, T: ?Sized> Channel<P, T> where
    P: ProtocolDecoder + ProtocolEncoder,
    T: Read + Write
[src]

pub fn new(protocol: P, stream: Box<T>) -> Channel<P, T>[src]

Create a new Channel to read and write messages

Example

This example is not tested
let channel = Channel::new(
    RplidarProtocol::new(),
    serial_port
);

pub fn with_read_buffer_size(
    protocol: P,
    stream: Box<T>,
    read_buffer_size: usize
) -> Channel<P, T>
[src]

Create a new Channel with non-default ring buffer capacity

Example

This example is not tested
let channel = Channel::with_read_buffer_size(
    RplidarProtocol::new(),
    serial_port,
    100000 as usize
);

pub fn reset(&mut self)[src]

Reset the channel status This function is usually used to reset protocol encoder and decoder when meet communication error

Example

This example is not tested
match channel.invoke(&Message::new(1), Duration::from_secs(1)) {
    Ok(_) => {},
    Err(_) => { channel.reset(); }
}

pub fn read(&mut self) -> Result<Option<Message>>[src]

Read message from channel

Example

This example is not tested
if let Some(msg) = channel.read().unwrap() {
    println!("{:?}", msg);
}

pub fn read_until(&mut self, timeout: Duration) -> Result<Option<Message>>[src]

Read message until timeout

Example

This example is not tested
channel.read_until(Duration::from_secs(1));

pub fn write(&mut self, msg: &Message) -> Result<usize>[src]

Write message to channel

Example

This example is not tested
channel.write(&Message::new(1)).unwrap();

pub fn invoke(
    &mut self,
    request: &Message,
    timeout: Duration
) -> Result<Option<Message>>
[src]

Send a request to channel and wait for response

Example

This example is not tested
let resp = channel.invoke(&Message::new(1), Duration::from_secs(1));

Trait Implementations

impl<P: Debug, T: Debug + ?Sized> Debug for Channel<P, T>[src]

Auto Trait Implementations

impl<P, T: ?Sized> Send for Channel<P, T> where
    P: Send,
    T: Send

impl<P, T: ?Sized> Sync for Channel<P, T> where
    P: Sync,
    T: Sync

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]