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>
impl<'d, D: Driver<'d>> UsbtmcClass<'d, D>
Sourcepub fn new(
builder: &mut Builder<'d, D>,
state: &'d mut State,
config: Config,
) -> Self
pub fn new( builder: &mut Builder<'d, D>, state: &'d mut State, config: Config, ) -> Self
Creates a new UsbtmcClass device instance.
Sourcepub async fn wait_connection(&mut self)
pub async fn wait_connection(&mut self)
Waits until the USB host configures and enables this interface.
Sourcepub async fn read_event<'a>(
&mut self,
buf: &'a mut [u8],
) -> Result<UsbtmcEvent<'a>, UsbtmcError>
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.
Sourcepub async fn read_message<'a>(
&mut self,
buf: &'a mut [u8],
) -> Result<ReceivedMessage<'a>, UsbtmcError>
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.
Sourcepub async fn wait_request_in(
&mut self,
) -> Result<RequestDevDepMsgInHeader, UsbtmcError>
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.
Sourcepub async fn write_message(
&mut self,
data: &[u8],
eom: bool,
) -> Result<(), UsbtmcError>
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.
Sourcepub async fn write_message_with_tag(
&mut self,
tag: u8,
data: &[u8],
eom: bool,
) -> Result<(), UsbtmcError>
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.
Sourcepub async fn send_srq(&mut self, status_byte: u8) -> Result<(), UsbtmcError>
pub async fn send_srq(&mut self, status_byte: u8) -> Result<(), UsbtmcError>
Transmits a USB488 Service Request (SRQ) notification on the Interrupt-IN endpoint.
Sourcepub fn set_status_byte(&self, stb: u8)
pub fn set_status_byte(&self, stb: u8)
Sets the IEEE 488.2 status byte (*STB).
Sourcepub fn status_byte(&self) -> u8
pub fn status_byte(&self) -> u8
Gets the current IEEE 488.2 status byte (*STB).
Sourcepub async fn check_clear(&mut self) -> bool
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.
Sourcepub async fn stall(&mut self)
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.
Sourcepub async fn clear_stall(&mut self)
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.
Sourcepub fn is_stalled(&self) -> bool
pub fn is_stalled(&self) -> bool
Returns whether a bulk endpoint is currently stalled.
Sourcepub fn indicator_pulse_count(&self) -> u32
pub fn indicator_pulse_count(&self) -> u32
Gets the count of indicator pulse requests received.
Sourcepub fn trigger_count(&self) -> u32
pub fn trigger_count(&self) -> u32
Gets the count of hardware trigger commands received.