[−][src]Struct rpos_drv::Channel
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]
P: ProtocolDecoder + ProtocolEncoder,
T: Read + Write,
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]
protocol: P,
stream: Box<T>,
read_buffer_size: usize
) -> Channel<P, T>
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]
&mut self,
request: &Message,
timeout: Duration
) -> Result<Option<Message>>
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
Auto Trait Implementations
impl<P, T: ?Sized> Send for Channel<P, T> where
P: Send,
T: Send,
P: Send,
T: Send,
impl<P, T: ?Sized> Sync for Channel<P, T> where
P: Sync,
T: Sync,
P: Sync,
T: Sync,
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,