pub struct Instrument<P: Read + Write> { /* private fields */ }Expand description
A general instrument interface that can be built with any interface that implements
std::io::Read and std::io::Write.
This struct can be used to communicate with instruments over the various interfaces. Handy
shortcuts for creating various interfaces are provides as well. However, this general
implementation can also be used with any other types that are not provided by InstrumentRs.
§Example
The following shows a simple example on how to create an Instrument interface from your own
interface that implements std::io::Read and std::io::Write. Of course, to just use a
simple std::net::TcpStream as shown here, you can also use the
crate::TcpIpInterface interface.
use std::{net::TcpStream, time::Duration};
use instrumentrs::Instrument;
let my_interface = TcpStream::connect("192.168.10.1:8000").unwrap();
let inst_interface = Instrument::new(my_interface, Duration::from_secs(3));Implementations§
Source§impl<P: Read + Write> Instrument<P>
impl<P: Read + Write> Instrument<P>
Sourcepub fn new(port: P, timeout: Duration) -> Self
pub fn new(port: P, timeout: Duration) -> Self
Try to create a new instance of Instrument with a given interface.
Trait Implementations§
Source§impl<P: Read + Write> InstrumentInterface for Instrument<P>
impl<P: Read + Write> InstrumentInterface for Instrument<P>
Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), InstrumentError>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), InstrumentError>
Read an exact number of bytes from the instrument. Read more
Source§fn get_terminator(&self) -> &str
fn get_terminator(&self) -> &str
Get the current terminator of the interface. Read more
Source§fn set_terminator(&mut self, terminator: &str)
fn set_terminator(&mut self, terminator: &str)
Set the terminator of an interface from a
&str. Read moreSource§fn get_timeout(&self) -> Duration
fn get_timeout(&self) -> Duration
Get the current timeout of the interface. Read more
Source§fn write_raw(&mut self, data: &[u8]) -> Result<(), InstrumentError>
fn write_raw(&mut self, data: &[u8]) -> Result<(), InstrumentError>
Write a byte slice to the instrument and flush it after. Read more
Source§fn check_acknowledgment(&mut self, ack: &str) -> Result<(), InstrumentError>
fn check_acknowledgment(&mut self, ack: &str) -> Result<(), InstrumentError>
Check if an acknowledgment is received from the instrument. Read more
Source§fn query(&mut self, cmd: &str) -> Result<String, InstrumentError>
fn query(&mut self, cmd: &str) -> Result<String, InstrumentError>
Query the instrument with a command and return the response as a String. Read more
Source§fn read_until_terminator(&mut self) -> Result<String, InstrumentError>
fn read_until_terminator(&mut self) -> Result<String, InstrumentError>
Read until the terminator is found or the timeout is reached. Read more
Auto Trait Implementations§
impl<P> Freeze for Instrument<P>where
P: Freeze,
impl<P> RefUnwindSafe for Instrument<P>where
P: RefUnwindSafe,
impl<P> Send for Instrument<P>where
P: Send,
impl<P> Sync for Instrument<P>where
P: Sync,
impl<P> Unpin for Instrument<P>where
P: Unpin,
impl<P> UnwindSafe for Instrument<P>where
P: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more