Instrument

Struct Instrument 

Source
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>

Source

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>

Source§

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

Get the current terminator of the interface. Read more
Source§

fn set_terminator(&mut self, terminator: &str)

Set the terminator of an interface from a &str. Read more
Source§

fn get_timeout(&self) -> Duration

Get the current timeout of the interface. Read more
Source§

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>

Check if an acknowledgment is received from the instrument. Read more
Source§

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>

Read until the terminator is found or the timeout is reached. Read more
Source§

fn sendcmd(&mut self, cmd: &str) -> Result<(), InstrumentError>

Send a command to the instrument. Read more
Source§

fn write(&mut self, data: &str) -> Result<(), InstrumentError>

Write a string to the instrument. 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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.