USBTMC¤
Prerequisites¤
Before communicating with equipment that use the USB Test & Measurement Class (USBTMC) protocol, a libusb-compatible driver must be installed and the directory to the libusb library must be available on the PATH environment variable. See here for more details.
Capabilities
¤
USBTMC device capabilities.
Note
Do not instantiate this class. The device capabilities are automatically determined when the connection is established. You can access these attributes via the capabilities property.
A manufacturer may not strictly follow the rules defined in the USBTMC standard when
specifying the relationships between the capability bitmap values. You may change
the value of an attribute if you get an error when calling one of the capability
methods, such as trigger(), with
an error message that states the capability is not supported. For example, if
calling trigger() raises an error
that states a trigger request is not supported (and you are certain that the device
does support a trigger request) you may set tmc.capabilities.accepts_trigger = True,
where tmc is the USBTMC instance, to bypass
the error.
Attributes:
| Name | Type | Description |
|---|---|---|
data |
array[int]
|
The |
accepts_indicator_pulse |
bool
|
Whether the interface accepts the |
accepts_remote_local |
bool
|
Whether the interface accepts |
accepts_service_request |
bool
|
Whether the device accepts a service request. |
accepts_term_char |
bool
|
Whether the device supports ending a Bulk-IN transfer when a byte matches the read_termination character. |
accepts_trigger |
bool
|
Whether the device accepts the |
is_488_interface |
bool
|
Whether the device understands all mandatory SCPI commands, accepts a service request and is a 488.2 interface. See Appendix 2: IEEE 488.2 compatibility in USBTMC_usb488_subclass_1_00.pdf for more details. |
is_listen_only |
bool
|
Whether the interface is listen-only. |
is_talk_only |
bool
|
Whether the interface is talk-only. |
Source code in src/msl/equipment/interfaces/usbtmc.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
USBTMC
(USB)
¤
USBTMC(equipment: Equipment)
Base class for the USBTMC communication protocol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
equipment
|
Equipment
|
An Equipment instance. |
required |
A Connection instance supports the same properties as those specified in USB.
Source code in src/msl/equipment/interfaces/usbtmc.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
device_version
property
¤
device_version: int
Returns the device version (release) number.
Corresponds to the bcdDevice field in the Device Descriptor.
intr_in_endpoint
property
¤
intr_in_endpoint: Endpoint | None
Information about the Interrupt-IN endpoint.
intr_out_endpoint
property
¤
intr_out_endpoint: Endpoint | None
Information about the Interrupt-OUT endpoint.
build_request_type
staticmethod
¤
build_request_type(
direction: CtrlDirection, type: CtrlType, recipient: CtrlRecipient
) -> int
Build a bmRequestType field for a control request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
direction
|
CtrlDirection
|
Transfer direction. |
required |
type
|
CtrlType
|
Transfer type. |
required |
recipient
|
CtrlRecipient
|
Recipient of the transfer. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The |
Source code in src/msl/equipment/interfaces/usb.py
471 472 473 474 475 476 477 478 479 480 481 482 483 484 | |
clear_device_buffers
¤
clear_device_buffers() -> None
Clear all input and output buffers associated with the USBTMC device.
Source code in src/msl/equipment/interfaces/usbtmc.py
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 | |
clear_halt
¤
clear_halt(endpoint: Endpoint) -> None
Clear the halt/stall condition for an endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
endpoint
|
Endpoint
|
The endpoint to clear. |
required |
Source code in src/msl/equipment/interfaces/usb.py
496 497 498 499 500 501 502 503 504 505 506 | |
control_ren
¤
Controls the state of the GPIB Remote Enable (REN) line.
Optionally the remote/local state of the device is also controlled.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
RENMode | str | int
|
The mode of the REN line and optionally the device remote/local state. Can be an enum member name (case insensitive) or value. |
required |
Source code in src/msl/equipment/interfaces/usbtmc.py
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 | |
ctrl_transfer
¤
ctrl_transfer(
request_type: int,
request: int,
value: int = ...,
index: int = ...,
data_or_length: None = None,
) -> int | array[int]
ctrl_transfer(
request_type: int,
request: int,
value: int = 0,
index: int = 0,
data_or_length: int | array[int] | bytes | bytearray | str | None = None,
) -> int | array[int]
Perform a control transfer on Endpoint 0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request_type
|
int
|
The bmRequestType field of the request. The bitmap value defines the direction (OUT or IN) of the request, the type of request and the designated recipient. See build_request_type. |
required |
request
|
int
|
The bRequest field of the request. |
required |
value
|
int
|
The wValue field of the request. |
0
|
index
|
int
|
The wIndex field of the request. |
0
|
data_or_length
|
int | array[int] | bytes | bytearray | str | None
|
Either the data payload for an OUT request, an array buffer to receive data for an IN request, or the number of bytes to read for an IN request. |
None
|
Returns:
| Type | Description |
|---|---|
int | array[int]
|
Source code in src/msl/equipment/interfaces/usb.py
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 | |
disconnect
¤
disconnect() -> None
Disconnect from the USB device.
Source code in src/msl/equipment/interfaces/usb.py
600 601 602 603 604 605 606 607 608 609 610 611 612 613 | |
indicator_pulse
¤
indicator_pulse() -> None
Request to turn on an activity indicator for identification purposes.
If the device supports the request, the device turns on an implementation-dependent activity indicator for a duration between 0.5 and 1 second. The activity indicator then automatically turns off.
Source code in src/msl/equipment/interfaces/usbtmc.py
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 | |
query
¤
query(
message: bytes | str,
*,
delay: float = 0.0,
decode: Literal[True] = True,
dtype: None = None,
fmt: MessageFormat = ...,
size: int | None = ...
) -> str
query(
message: bytes | str,
*,
delay: float = 0.0,
decode: Literal[False] = False,
dtype: None = None,
fmt: MessageFormat = ...,
size: int | None = ...
) -> bytes
query(
message: bytes | str,
*,
delay: float = 0.0,
decode: bool = ...,
dtype: MessageDataType = ...,
fmt: MessageFormat = ...,
size: int | None = ...
) -> NumpyArray1D
query(
message: bytes | str,
*,
delay: float = 0.0,
decode: bool = True,
dtype: MessageDataType | None = None,
fmt: MessageFormat = None,
size: int | None = None
) -> bytes | str | NumpyArray1D
Convenience method for performing a write followed by a read.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
bytes | str
|
The message to write to the equipment. |
required |
delay
|
float
|
Time delay, in seconds, to wait between the write and read operations. |
0.0
|
decode
|
bool
|
True
|
|
dtype
|
MessageDataType | None
|
The data type of the elements in the returned message. Can be any object that numpy
dtype supports. For messages that are of scalar type (i.e., a single number)
it is more efficient to not specify |
None
|
fmt
|
MessageFormat
|
The format that the returned message data is in. Ignored if |
None
|
size
|
int | None
|
The number of bytes to read. Ignored if the value is |
None
|
Returns:
| Type | Description |
|---|---|
bytes | str | NumpyArray1D
|
Source code in src/msl/equipment/interfaces/message_based.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | |
read
¤
read(
*,
decode: Literal[True] = True,
dtype: None = None,
fmt: MessageFormat = ...,
size: int | None = ...
) -> str
read(
*,
decode: Literal[False] = False,
dtype: None = None,
fmt: MessageFormat = ...,
size: int | None = ...
) -> bytes
read(
*,
decode: bool = ...,
dtype: MessageDataType = ...,
fmt: MessageFormat = ...,
size: int | None = ...
) -> NumpyArray1D
read(
*,
decode: bool = True,
dtype: MessageDataType | None = None,
fmt: MessageFormat = None,
size: int | None = None
) -> bytes | str | NumpyArray1D
Read a message from the equipment.
This method will block until one of the following conditions is fulfilled:
sizebytes have been received — only ifsizeis notNone.- the read_termination
byte(s) is(are) received — only if
read_termination
is not
None. - a timeout occurs — only if timeout
is not
None. If a timeout occurs, an MSLTimeoutError is raised. - max_read_size bytes have been received. If the maximum number of bytes have been read, an MSLConnectionError is raised.
Tip
You may also want to set the rstrip value for the class instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
decode
|
bool
|
True
|
|
dtype
|
MessageDataType | None
|
The data type of the elements in the returned message. Can be any object that numpy
dtype supports. For messages that are of scalar type (i.e., a single number)
it is more efficient to not specify |
None
|
fmt
|
MessageFormat
|
The format that the returned message data is in. Ignored if |
None
|
size
|
int | None
|
The number of bytes to read. Ignored if the value is |
None
|
Returns:
| Type | Description |
|---|---|
bytes | str | NumpyArray1D
|
Source code in src/msl/equipment/interfaces/message_based.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | |
reset_device
¤
reset_device() -> None
Perform a USB port reset for the device.
If your program has to call this method, the reset will cause the device state to change (e.g., register values may be reset).
Source code in src/msl/equipment/interfaces/usb.py
625 626 627 628 629 630 631 632 | |
serial_poll
¤
serial_poll() -> int
Read status byte / serial poll.
Returns:
| Type | Description |
|---|---|
int
|
The status byte. See the table from here for the meaning of each bit in the status byte. |
Source code in src/msl/equipment/interfaces/usbtmc.py
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 | |
trigger
¤
trigger() -> None
Trigger device.
Source code in src/msl/equipment/interfaces/usbtmc.py
541 542 543 544 545 546 547 | |
write
¤
write(
message: bytes | str,
*,
data: Sequence1D | None = None,
dtype: MessageDataType = "<f",
fmt: MessageFormat = "ieee"
) -> int
Write a message to the equipment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
bytes | str
|
The message to write to the equipment. |
required |
data
|
Sequence1D | None
|
The data to append to |
None
|
dtype
|
MessageDataType
|
The data type to use to convert each element in |
'<f'
|
fmt
|
MessageFormat
|
The format to use to convert |
'ieee'
|
Returns:
| Type | Description |
|---|---|
int
|
The number of bytes written. |
Source code in src/msl/equipment/interfaces/message_based.py
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 | |