embassy-usb

Crates

git

Versions

default

Flavors

Skip to main content

UsbtmcClass

Struct UsbtmcClass 

Source
pub struct UsbtmcClass<'d, D: Driver<'d>> { /* private fields */ }
Expand description

USB device class for USB Test & Measurement Class (USBTMC).

Implementations§

Source§

impl<'d, D: Driver<'d>> UsbtmcClass<'d, D>

Source

pub fn new( builder: &mut Builder<'d, D>, state: &'d mut State, config: Config, ) -> Self

Creates a new UsbtmcClass device instance.

Source

pub async fn wait_connection(&mut self)

Waits until the USB host configures and enables this interface.

Source

pub async fn read_event<'a>( &mut self, buf: &'a mut [u8], ) -> Result<UsbtmcEvent<'a>, UsbtmcError>

Reads the next event from the Bulk-OUT endpoint.

Source

pub async fn read_message<'a>( &mut self, buf: &'a mut [u8], ) -> Result<ReceivedMessage<'a>, UsbtmcError>

Reads the next command message from the host.

If an incoming REQUEST_DEV_DEP_MSG_IN or TRIGGER event is encountered, it is recorded in the internal state before continuing to wait for a command message.

Source

pub async fn wait_request_in( &mut self, ) -> Result<RequestDevDepMsgInHeader, UsbtmcError>

Waits for the host to send a REQUEST_DEV_DEP_MSG_IN request on Bulk-OUT.

Source

pub async fn write_message( &mut self, data: &[u8], eom: bool, ) -> Result<(), UsbtmcError>

Sends a response message to the host, automatically awaiting the matching REQUEST_DEV_DEP_MSG_IN and using its tag.

Source

pub async fn write_message_with_tag( &mut self, tag: u8, data: &[u8], eom: bool, ) -> Result<(), UsbtmcError>

Writes a response message with an explicit b_tag.

Source

pub async fn send_srq(&mut self, status_byte: u8) -> Result<(), UsbtmcError>

Transmits a USB488 Service Request (SRQ) notification on the Interrupt-IN endpoint.

Source

pub fn set_status_byte(&self, stb: u8)

Sets the IEEE 488.2 status byte (*STB).

Source

pub fn status_byte(&self) -> u8

Gets the current IEEE 488.2 status byte (*STB).

Source

pub async fn check_clear(&mut self) -> bool

Checks if a clear operation was requested by the host (viClear()).

A clear also clears any STALL condition left by an unparseable message, so the instrument can be used again without the application calling Self::clear_stall itself.

Source

pub async fn stall(&mut self)

Stalls both bulk endpoints.

The class does this itself when a Bulk-OUT message cannot be parsed; see UsbtmcError. Call it to reject a transfer deliberately, for example for a command the instrument does not support: the host sees the failed transfer instead of an empty reply, and can abort it with Self::clear_stall, CLEAR_FEATURE(ENDPOINT_HALT) or viClear().

Host software sees this as an I/O error rather than a reply: VISA raises a VisaIOError, libusb-based stacks an EPIPE/USBError. There is no way to report a protocol failure other than failing the transfer, so host code has to handle the error and clear the halt.

While the endpoints are stalled, reads and writes do not complete, so the application has to call Self::clear_stall (or wait for the host to clear the halt) before using the class again.

Source

pub async fn clear_stall(&mut self)

Clears the STALL condition on the bulk endpoints that are actually stalled.

Bulk-OUT is stalled when the class cannot parse a message from the host; see UsbtmcError. The host normally clears it with CLEAR_FEATURE(ENDPOINT_HALT), and Self::check_clear clears it when the host issues viClear().

Clearing a halt resets the endpoint’s data toggle to DATA0 (USB 2.0 §9.4.5). The host does not see that, so clearing a stall the host itself did not clear leaves the two sides out of step and the next transfer gets discarded as a retransmission. Only call this when the host is going to clear the halt as well, or after a bus reset, which resets both sides.

Source

pub fn is_stalled(&self) -> bool

Returns whether a bulk endpoint is currently stalled.

Source

pub fn indicator_pulse_count(&self) -> u32

Gets the count of indicator pulse requests received.

Source

pub fn trigger_count(&self) -> u32

Gets the count of hardware trigger commands received.

Auto Trait Implementations§

§

impl<'d, D> !RefUnwindSafe for UsbtmcClass<'d, D>

§

impl<'d, D> !UnwindSafe for UsbtmcClass<'d, D>

§

impl<'d, D> Forget for UsbtmcClass<'d, D>

§

impl<'d, D> Freeze for UsbtmcClass<'d, D>
where <D as Driver<'d>>::EndpointOut: Freeze, <D as Driver<'d>>::EndpointIn: Freeze, Option<<D as Driver<'d>>::EndpointIn>: Freeze,

§

impl<'d, D> Move for UsbtmcClass<'d, D>

§

impl<'d, D> Send for UsbtmcClass<'d, D>
where <D as Driver<'d>>::EndpointOut: Send, <D as Driver<'d>>::EndpointIn: Send, Option<<D as Driver<'d>>::EndpointIn>: Send,

§

impl<'d, D> Sync for UsbtmcClass<'d, D>
where <D as Driver<'d>>::EndpointOut: Sync, <D as Driver<'d>>::EndpointIn: Sync, Option<<D as Driver<'d>>::EndpointIn>: Sync,

§

impl<'d, D> Unpin for UsbtmcClass<'d, D>
where <D as Driver<'d>>::EndpointOut: Unpin, <D as Driver<'d>>::EndpointIn: Unpin, Option<<D as Driver<'d>>::EndpointIn>: Unpin,

§

impl<'d, D> UnsafeUnpin for UsbtmcClass<'d, D>

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.