Struct rpos_drv::Channel

source ·
pub struct Channel<P, T: ?Sized> { /* private fields */ }
Expand description

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

Examples

let mut channel = Channel::new(
    RplidarProtocol::new(),
    serial_port
);
 
channel.write(&Message::new(1)).unwrap();

Implementations§

Create a new Channel to read and write messages

Example
let channel = Channel::new(
    RplidarProtocol::new(),
    serial_port
);

Create a new Channel with non-default ring buffer capacity

Example
let channel = Channel::with_read_buffer_size(
    RplidarProtocol::new(),
    serial_port,
    100000 as usize
);

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

Example
match channel.invoke(&Message::new(1), Duration::from_secs(1)) {
    Ok(_) => {},
    Err(_) => { channel.reset(); }
}

Read message from channel

Example
if let Some(msg) = channel.read().unwrap() {
    println!("{:?}", msg);
}

Read message until timeout

Example
channel.read_until(Duration::from_secs(1));

Write message to channel

Example
channel.write(&Message::new(1)).unwrap();

Send a request to channel and wait for response

Example
let resp = channel.invoke(&Message::new(1), Duration::from_secs(1));

Trait Implementations§

Formats the value using the given formatter. Read more

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.