qmi.core.transport_usbtmc_pyusb
Extension of the QMI_UsbTmcTransport class utilizing usb.core and qmi.core.usbtmc packages.
Classes
|
- class qmi.core.transport_usbtmc_pyusb.QMI_PyUsbTmcTransport(vendorid: int, productid: int, serialnr: str)
- close() None
Close the transport and release associated resources.
This transport instance can never be used again after it has been closed.
Subclasses must override this method to close specific resources. When overriding this method, the subclass should make a call to this method before all resources are closed.
- write(data: bytes) None
Send the specified data to the instrument as a single USBTMC message. A fixed timeout of 5 seconds is applied. If timeout occurs, the transfer is aborted and an exception is raised.
- Parameters:
data – The data to write in a byte string.
- static list_resources()
List available resources from USB connections. This should be implemented in deriving classes.
- Returns:
List of available resources in QMI’s USBTMC transport string format.
- Return type:
resources
- discard_read() None
Discard all bytes that are immediately available for reading.
- open() None
Open the transport and claim associated resources.
- read(nbytes: int, timeout: float | None) bytes
Read a specified number of bytes from the transport.
All bytes must belong to the same USBTMC message.
This method blocks until the specified number of bytes are available, then returns the received bytes. If timeout occurs, any partial read data is discarded and QMI_TimeoutException is raised.
- Parameters:
nbytes – Expected number of bytes to read.
timeout – Maximum time to wait in seconds (default: 60 seconds).
- Returns:
Received bytes.
- Raises:
QMI_TimeoutException – If the timeout expires before the requested number of bytes are available.
QMI_EndOfInputException – If an end-of-message indicator is received before the requested number of bytes is reached.
- read_until(message_terminator: bytes, timeout: float | None) bytes
The specified message_terminator is ignored. Instead, the instrument must autonomously indicate the end of the message according to the USBTMC protocol.
As the message_terminator is not used, we forward simply the call to the read_until_timeout call.
- Parameters:
message_terminator – This input is ignored.
timeout – Maximum time to wait (in seconds).
- Returns:
Received bytes.
- read_until_timeout(nbytes: int, timeout: float | None) bytes
Read a single USBTMC message from the instrument.
If the timeout expires before the message is received, the read is aborted and any data already received are discarded. In this case an empty bytes string is returned.
- Parameters:
nbytes – This input is ignored.
timeout – Maximum time to wait (in seconds).
- Returns:
Received bytes.