interfaces¤
Interface classes for computer control.
Generic interface classes
- Interface — Base class for all interfaces
- MessageBased — Base class for all message-based interfaces
Specific interfaces
- GPIB — Base class for GPIB communication
- HiSLIP — Base class for the HiSLIP communication protocol
- Prologix — Use Prologix hardware to establish a connection
- SDK — Base class for equipment that use the manufacturer's Software Development Kit
- Serial — Base class for equipment that is connected through a serial port
- Socket — Base class for equipment that is connected through a socket
- VXI11 — Base class for the VXI-11 communication protocol
- ZeroMQ — Base class for equipment that use the ZeroMQ communication protocol
Backend (external package) interfaces
- NIDAQ — Use NI-DAQmx as the backend to communicate with the equipment
- PyVISA — Use PyVISA as the backend to communicate with the equipment
Interface
¤
Interface(equipment: Equipment)
Base class for all interfaces.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
equipment
|
Equipment
|
An Equipment instance. |
required |
Source code in src/msl/equipment/schema.py
2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 |
|
disconnect
¤
disconnect() -> None
Disconnect from the equipment.
This method can be overridden in the subclass if the subclass must implement tasks that need to be performed in order to safely disconnect from the equipment.
For example,
- to clean up system resources from memory (e.g., if using a manufacturer's SDK)
- to configure the equipment to be in a state that is safe for people working in the lab when the equipment is not in use
Tip
This method gets called automatically when the Interface instance gets garbage collected, which happens when the reference count is 0.
Source code in src/msl/equipment/schema.py
3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 |
|
MessageBased
¤
MessageBased(equipment: Equipment)
Bases: Interface
Base class for equipment that use message-based communication.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
equipment
|
Equipment
|
An Equipment instance. |
required |
A Connection instance supports the following properties for message-based communication.
Connection Properties:
Name | Type | Description |
---|---|---|
encoding |
str
|
|
max_read_size |
int
|
Maximum number of bytes that can be
read.
Default: |
read_termination |
bytes | str
|
Termination character(s) to use for
read messages.
Default: |
rstrip |
bool
|
Whether to remove trailing whitespace from
read messages.
Default: |
termination |
bytes | str
|
Sets both |
timeout |
float | None
|
|
write_termination |
bytes | str
|
Termination character(s) to use for
write messages.
Default: |
Source code in src/msl/equipment/interfaces/message_based.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
disconnect
¤
disconnect() -> None
Disconnect from the equipment.
This method can be overridden in the subclass if the subclass must implement tasks that need to be performed in order to safely disconnect from the equipment.
For example,
- to clean up system resources from memory (e.g., if using a manufacturer's SDK)
- to configure the equipment to be in a state that is safe for people working in the lab when the equipment is not in use
Tip
This method gets called automatically when the Interface instance gets garbage collected, which happens when the reference count is 0.
Source code in src/msl/equipment/schema.py
3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 |
|
query
¤
query(
message: bytes | str,
*,
delay: float = 0.0,
decode: Literal[True] = True,
dtype: None = None,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> str
query(
message: bytes | str,
*,
delay: float = 0.0,
decode: Literal[False] = False,
dtype: None = None,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> bytes
query(
message: bytes | str,
*,
delay: float = 0.0,
decode: bool = ...,
dtype: MessageDataType = ...,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> NumpyArray1D
query(
message: bytes | str,
*,
delay: float = 0.0,
decode: bool = True,
dtype: MessageDataType | None = None,
fmt: MessageFormat | None = 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. See from_bytes
for more details. For messages that are of scalar type (i.e., a single number)
it is more efficient to not specify |
None
|
fmt
|
MessageFormat | None
|
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
170 171 172 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 |
|
read
¤
read(
*,
decode: Literal[True] = True,
dtype: None = None,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> str
read(
*,
decode: Literal[False] = False,
dtype: None = None,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> bytes
read(
*,
decode: bool = ...,
dtype: MessageDataType = ...,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> NumpyArray1D
read(
*,
decode: bool = True,
dtype: MessageDataType | None = None,
fmt: MessageFormat | None = 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:
size
bytes have been received — only ifsize
is 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 message. Can be any object
that numpy dtype supports. See from_bytes
for more details. For messages that are of scalar type (i.e., a single number)
it is more efficient to not specify |
None
|
fmt
|
MessageFormat | None
|
The format that the 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
239 240 241 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 |
|
write
¤
write(
message: bytes | str,
*,
data: Sequence1D | None = None,
dtype: MessageDataType = "<f",
fmt: MessageFormat | None = "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 | None
|
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
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 399 400 |
|
GPIB
¤
GPIB(equipment: Equipment)
Bases: MessageBased
Base class for GPIB communication.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
equipment
|
Equipment
|
An Equipment instance. |
required |
A Connection instance supports the following properties for the GPIB communication protocol, as well as the properties defined in MessageBased.
Connection Properties:
Name | Type | Description |
---|---|---|
eos_mode |
int
|
The end-of-string mode. Default: |
send_eoi |
bool
|
Whether to enable ( |
Source code in src/msl/equipment/interfaces/gpib.py
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 463 464 465 466 467 468 469 |
|
read_termination
property
writable
¤
read_termination: bytes | None
The termination character sequence that is used for the read method.
By default, reading stops when the EOI line is asserted.
ask
¤
Get a configuration setting (board or device).
This method is the ibask function, it should not be confused with the query method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
option
|
int
|
A configuration setting to get the value of. |
required |
handle
|
int | None
|
Board or device descriptor. Default is the handle of the instantiated class. |
None
|
Returns:
Type | Description |
---|---|
int
|
The value of the configuration setting. |
Source code in src/msl/equipment/interfaces/gpib.py
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 |
|
clear
¤
Send the clear command (device).
This method is the ibclr function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
handle
|
int | None
|
Board or device descriptor. Default is the handle of the instantiated class. |
None
|
Returns:
Type | Description |
---|---|
int
|
The status value ( |
Source code in src/msl/equipment/interfaces/gpib.py
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 |
|
command
¤
Write command bytes (board).
This method is the ibcmd function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
bytes
|
The commands to write to the bus. |
required |
handle
|
int | None
|
Board or device descriptor. Default is the handle of the instantiated class. |
None
|
Returns:
Type | Description |
---|---|
int
|
The status value ( |
Source code in src/msl/equipment/interfaces/gpib.py
562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 |
|
config
¤
Change configuration settings (board or device).
This method is the ibconfig function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
option
|
int
|
A configuration setting to change the value of. |
required |
value
|
int
|
The new configuration setting value. |
required |
handle
|
int | None
|
Board or device descriptor. Default is the handle of the instantiated class. |
None
|
Returns:
Type | Description |
---|---|
int
|
The status value ( |
Source code in src/msl/equipment/interfaces/gpib.py
580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 |
|
control_atn
¤
Set the state of the ATN line (board).
This method mimics the PyVISA-py implementation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state
|
int
|
The state of the ATN line or the active controller. Allowed values are:
|
required |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
handle
|
int | None
|
Board or device descriptor. Default is the handle of the instantiated class. |
None
|
Returns:
Type | Description |
---|---|
int
|
The status value ( |
Source code in src/msl/equipment/interfaces/gpib.py
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 |
|
control_ren
¤
Controls the state of the GPIB Remote Enable (REN) interface line.
Optionally the remote/local state of the device is also controlled.
This method mimics the PyVISA-py implementation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state
|
int
|
Specifies the state of the REN line and optionally the device remote/local state. Allowed values are:
|
required |
handle
|
int | None
|
Board or device descriptor. Default is the handle of the instantiated class. |
None
|
Returns:
Type | Description |
---|---|
int
|
The status value ( |
Source code in src/msl/equipment/interfaces/gpib.py
637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 |
|
count
¤
count() -> int
Get the number of bytes sent or received.
This method is the ibcntl function.
Source code in src/msl/equipment/interfaces/gpib.py
689 690 691 692 693 694 |
|
disconnect
¤
disconnect() -> None
Close the GPIB connection.
Source code in src/msl/equipment/interfaces/gpib.py
696 697 698 699 700 701 702 |
|
interface_clear
¤
Perform interface clear (board).
Resets the GPIB bus by asserting the interface clear (IFC) bus line for a duration of at least 100 microseconds.
This method is the ibsic function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
handle
|
int | None
|
Board or device descriptor. Default is the handle of the instantiated class. |
None
|
Returns:
Type | Description |
---|---|
int
|
The status value ( |
Source code in src/msl/equipment/interfaces/gpib.py
709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 |
|
lines
¤
Returns the status of the control and handshaking bus lines (board).
This method is the iblines function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
handle
|
int | None
|
Board or device descriptor. Default is the handle of the instantiated class. |
None
|
Source code in src/msl/equipment/interfaces/gpib.py
735 736 737 738 739 740 741 742 743 744 745 746 747 748 |
|
listener
¤
Check if a listener is present (board or device).
This method is the ibln function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pad
|
int
|
Primary address of the GPIB device. |
required |
sad
|
int
|
Secondary address of the GPIB device. |
0
|
handle
|
int | None
|
Board or device descriptor. Default is the handle of the instantiated class. |
None
|
Returns:
Type | Description |
---|---|
bool
|
Whether a listener is present. |
Source code in src/msl/equipment/interfaces/gpib.py
750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 |
|
local
¤
Go to local mode (board or device).
This method is the ibloc function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
handle
|
int | None
|
Board or device descriptor. Default is the handle of the instantiated class. |
None
|
Return
The status value (ibsta
).
Source code in src/msl/equipment/interfaces/gpib.py
770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 |
|
online
¤
Close or reinitialize descriptor (board or device).
This method is the ibonl function.
If you want to close the connection for the GPIB board or device that was instantiated, use disconnect.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state
|
bool
|
If |
required |
handle
|
int | None
|
Board or device descriptor. Default is the handle of the instantiated class. |
None
|
Returns:
Type | Description |
---|---|
int
|
The status value ( |
Source code in src/msl/equipment/interfaces/gpib.py
787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 |
|
pass_control
¤
pass_control(
*,
handle: int | None = None,
name: str | None = None,
board: int | None = None,
pad: int = 0,
sad: int = NO_SEC_ADDR
) -> int
Set a GPIB board or device to become the controller-in-charge (CIC).
This method is the ibpct function.
If no arguments are specified, the instantiated class becomes the CIC.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
handle
|
int | None
|
Board or device descriptor. If specified, |
None
|
name
|
str | None
|
The name of a GPIB board or device. If specified, |
None
|
board
|
int | None
|
Index of the GPIB interface board. |
None
|
pad
|
int
|
Primary address of the GPIB device. |
0
|
sad
|
int
|
Secondary address of the GPIB device. |
NO_SEC_ADDR
|
Returns:
Type | Description |
---|---|
int
|
The handle of the board or device that became CIC. |
Source code in src/msl/equipment/interfaces/gpib.py
810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 |
|
query
¤
query(
message: bytes | str,
*,
delay: float = 0.0,
decode: Literal[True] = True,
dtype: None = None,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> str
query(
message: bytes | str,
*,
delay: float = 0.0,
decode: Literal[False] = False,
dtype: None = None,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> bytes
query(
message: bytes | str,
*,
delay: float = 0.0,
decode: bool = ...,
dtype: MessageDataType = ...,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> NumpyArray1D
query(
message: bytes | str,
*,
delay: float = 0.0,
decode: bool = True,
dtype: MessageDataType | None = None,
fmt: MessageFormat | None = 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. See from_bytes
for more details. For messages that are of scalar type (i.e., a single number)
it is more efficient to not specify |
None
|
fmt
|
MessageFormat | None
|
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
170 171 172 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 |
|
read
¤
read(
*,
decode: Literal[True] = True,
dtype: None = None,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> str
read(
*,
decode: Literal[False] = False,
dtype: None = None,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> bytes
read(
*,
decode: bool = ...,
dtype: MessageDataType = ...,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> NumpyArray1D
read(
*,
decode: bool = True,
dtype: MessageDataType | None = None,
fmt: MessageFormat | None = 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:
size
bytes have been received — only ifsize
is 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 message. Can be any object
that numpy dtype supports. See from_bytes
for more details. For messages that are of scalar type (i.e., a single number)
it is more efficient to not specify |
None
|
fmt
|
MessageFormat | None
|
The format that the 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
239 240 241 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 |
|
remote_enable
¤
Set remote enable (board).
This method is the ibsre function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state
|
bool
|
If |
required |
handle
|
int | None
|
Board or device descriptor. Default is the handle of the instantiated class. |
None
|
Returns: The status value (ibsta
).
Source code in src/msl/equipment/interfaces/gpib.py
869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 |
|
serial_poll
¤
Read status byte / serial poll (device).
This method is the ibrsp function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
handle
|
int | None
|
Board or device descriptor. Default is the handle of the instantiated class. |
None
|
Returns:
Type | Description |
---|---|
int
|
The status byte. |
Source code in src/msl/equipment/interfaces/gpib.py
886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 |
|
spoll_bytes
¤
Get the length of the serial poll bytes queue (device).
This method is the ibspb function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
handle
|
int | None
|
Board or device descriptor. Default is the handle of the instantiated class. |
None
|
Source code in src/msl/equipment/interfaces/gpib.py
904 905 906 907 908 909 910 911 912 913 914 915 916 917 |
|
status
¤
status() -> int
Returns the status value ibsta.
Source code in src/msl/equipment/interfaces/gpib.py
919 920 921 |
|
trigger
¤
Trigger device.
This method is the ibtrg function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
handle
|
int | None
|
Board or device descriptor. Default is the handle of the instantiated class. |
None
|
Returns:
Type | Description |
---|---|
int
|
The status value ( |
Source code in src/msl/equipment/interfaces/gpib.py
923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 |
|
version
¤
version() -> str
Returns the version of the GPIB library (linux only).
Source code in src/msl/equipment/interfaces/gpib.py
940 941 942 943 944 945 946 947 948 |
|
wait
¤
Wait for an event (board or device).
This method is the ibwait function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mask
|
int
|
Wait until one of the conditions specified in |
required |
handle
|
int | None
|
Board or device descriptor. Default is the handle of the instantiated class. |
None
|
Returns:
Type | Description |
---|---|
int
|
The status value ( |
Source code in src/msl/equipment/interfaces/gpib.py
950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 |
|
wait_for_srq
¤
Wait for the SRQ line to be asserted (board or device).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
handle
|
int | None
|
Board or device descriptor. Default is the handle of the instantiated class. |
None
|
Returns:
Type | Description |
---|---|
int
|
The status value ( |
Source code in src/msl/equipment/interfaces/gpib.py
968 969 970 971 972 973 974 975 976 977 |
|
write
¤
write(
message: bytes | str,
*,
data: Sequence1D | None = None,
dtype: MessageDataType = "<f",
fmt: MessageFormat | None = "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 | None
|
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
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 399 400 |
|
write_async
¤
Write a message asynchronously (board or device).
This method is the ibwrta function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message
|
bytes
|
The data to send. |
required |
handle
|
int | None
|
Board or device descriptor. Default is the handle of the instantiated class. |
None
|
Returns:
Type | Description |
---|---|
int
|
The status value ( |
Source code in src/msl/equipment/interfaces/gpib.py
979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 |
|
HiSLIP
¤
HiSLIP(equipment: Equipment)
Bases: MessageBased
Base class for the HiSLIP communication protocol.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
equipment
|
Equipment
|
An Equipment instance. |
required |
A Connection instance supports the following properties for the HiSLIP communication protocol, as well as the properties defined in MessageBased.
Connection Properties:
Name | Type | Description |
---|---|---|
buffer_size |
int
|
The maximum number of bytes to read at a time. Default: |
lock_timeout |
float
|
The timeout (in seconds) to wait for a lock (0 means wait forever). Default: |
Source code in src/msl/equipment/interfaces/hislip.py
1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 |
|
lock_timeout
property
writable
¤
lock_timeout: float
The time, in seconds, to wait to acquire a lock.
Setting the value to ≤0 (or None
) means wait forever.
clear
¤
clear() -> None
Send the clear
command to the device.
Source code in src/msl/equipment/interfaces/hislip.py
1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 |
|
disconnect
¤
disconnect() -> None
Close the connection to the HiSLIP server.
Source code in src/msl/equipment/interfaces/hislip.py
1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 |
|
lock
¤
Acquire the device's lock.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lock_string
|
str
|
An ASCII string that identifies this lock. If not specified, then an exclusive lock is requested, otherwise the string indicates an identification of a shared-lock request. |
''
|
Returns:
Type | Description |
---|---|
bool
|
Whether acquiring the lock was successful. |
Source code in src/msl/equipment/interfaces/hislip.py
1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 |
|
lock_status
¤
Request the lock status from the HiSLIP server.
Returns:
Type | Description |
---|---|
tuple[bool, int]
|
Whether the HiSLIP server has an exclusive lock with a client and the number of HiSLIP clients that have a lock with the HiSLIP server. |
Source code in src/msl/equipment/interfaces/hislip.py
1510 1511 1512 1513 1514 1515 1516 1517 1518 |
|
query
¤
query(
message: bytes | str,
*,
delay: float = 0.0,
decode: Literal[True] = True,
dtype: None = None,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> str
query(
message: bytes | str,
*,
delay: float = 0.0,
decode: Literal[False] = False,
dtype: None = None,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> bytes
query(
message: bytes | str,
*,
delay: float = 0.0,
decode: bool = ...,
dtype: MessageDataType = ...,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> NumpyArray1D
query(
message: bytes | str,
*,
delay: float = 0.0,
decode: bool = True,
dtype: MessageDataType | None = None,
fmt: MessageFormat | None = 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. See from_bytes
for more details. For messages that are of scalar type (i.e., a single number)
it is more efficient to not specify |
None
|
fmt
|
MessageFormat | None
|
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
170 171 172 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 |
|
read
¤
read(
*,
decode: Literal[True] = True,
dtype: None = None,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> str
read(
*,
decode: Literal[False] = False,
dtype: None = None,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> bytes
read(
*,
decode: bool = ...,
dtype: MessageDataType = ...,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> NumpyArray1D
read(
*,
decode: bool = True,
dtype: MessageDataType | None = None,
fmt: MessageFormat | None = 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:
size
bytes have been received — only ifsize
is 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 message. Can be any object
that numpy dtype supports. See from_bytes
for more details. For messages that are of scalar type (i.e., a single number)
it is more efficient to not specify |
None
|
fmt
|
MessageFormat | None
|
The format that the 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
239 240 241 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 |
|
read_stb
¤
read_stb() -> int
Read the status byte from the device.
Returns:
Type | Description |
---|---|
int
|
The status byte. |
Source code in src/msl/equipment/interfaces/hislip.py
1462 1463 1464 1465 1466 1467 1468 1469 |
|
reconnect
¤
reconnect(max_attempts: int = 1) -> None
Reconnect to the equipment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
max_attempts
|
int
|
The maximum number of attempts to try to reconnect with the equipment. If <1, keep trying until a connection is successful. If the maximum number of attempts has been reached then an exception is raise. |
1
|
Source code in src/msl/equipment/interfaces/hislip.py
1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 |
|
remote_local_control
¤
remote_local_control(request: int) -> None
Send a GPIB-like remote/local control request.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
request
|
int
|
The request to perform.
|
required |
Source code in src/msl/equipment/interfaces/hislip.py
1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 |
|
trigger
¤
trigger() -> None
Send the trigger message (emulates a GPIB Group Execute Trigger event).
Source code in src/msl/equipment/interfaces/hislip.py
1471 1472 1473 |
|
unlock
¤
unlock() -> bool
Release the lock acquired by lock.
Returns:
Type | Description |
---|---|
bool
|
Whether releasing the lock was successful. |
Source code in src/msl/equipment/interfaces/hislip.py
1501 1502 1503 1504 1505 1506 1507 1508 |
|
write
¤
write(
message: bytes | str,
*,
data: Sequence1D | None = None,
dtype: MessageDataType = "<f",
fmt: MessageFormat | None = "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 | None
|
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
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 399 400 |
|
NIDAQ
¤
NIDAQ(equipment: Equipment)
Bases: Interface
Use NI-DAQmx as the backend to communicate with the equipment.
The backend value must be equal
to NIDAQ
to use this class for the communication backend.
The returned object from calling the connect method is equivalent to importing the NI-DAQmx package, e.g.,
from msl.equipment import Backend, Connection
connection = Connection(address="Dev1", backend=Backend.NIDAQ)
nidaqmx = connection.connect()
with nidaqmx.Task() as task:
task.ai_channels.add_ai_voltage_chan(f"{nidaqmx.address}/ai0")
voltage = task.read()
is equivalent to
import nidaqmx
with nidaqmx.Task() as task:
task.ai_channels.add_ai_voltage_chan("Dev1/ai0")
voltage = task.read()
You can also combine the packages, use msl-equipment
for managing information
about the equipment and directly use nidaqmx
for the connection. If you use this
combination, the editor you use to develop your code may have better support for
features like code completion and type checking.
import nidaqmx
from msl.equipment import Config
# config.xml contains <equipment eid="MSLE.0.142" name="daq" manufacturer="NI"/>
# and specifies where the equipment registers are and the connections file.
cfg = Config("config.xml")
equipment = cfg.equipment["daq"]
address = equipment.connection.address
with nidaqmx.Task() as task:
task.ai_channels.add_ai_voltage_chan(f"{address}/ai0")
voltage = task.read()
# You could now use the `equipment` instance to apply a correction to the `voltage`
See the examples
on the NI-DAQmx repository to learn
how to use the nidaqmx
package.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
equipment
|
Equipment
|
An Equipment instance. |
required |
Source code in src/msl/equipment/interfaces/nidaq.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
|
disconnect
¤
disconnect() -> None
Disconnect from the equipment.
This method can be overridden in the subclass if the subclass must implement tasks that need to be performed in order to safely disconnect from the equipment.
For example,
- to clean up system resources from memory (e.g., if using a manufacturer's SDK)
- to configure the equipment to be in a state that is safe for people working in the lab when the equipment is not in use
Tip
This method gets called automatically when the Interface instance gets garbage collected, which happens when the reference count is 0.
Source code in src/msl/equipment/schema.py
3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 |
|
Prologix
¤
Prologix(equipment: Equipment)
Bases: Interface
Use Prologix hardware to establish a connection.
For the GPIB-ETHERNET Controller, the format of the address
string is Prologix::HOST::1234::PAD[::SAD]
, where HOST
is the hostname or IP address of the Prologix
hardware, 1234
is the ethernet port that is open on the Prologix hardware, PAD (Primary GPIB Address)
is an integer value between 0 and 30, and SAD (Secondary GPIB Address) is an integer value between
96 and 126 (SAD is optional). For example,
Prologix::192.168.1.110::1234::6
Prologix::192.168.1.110::1234::6::96
Prologix::prologix-00-21-69-01-31-04::1234::6
(typically, the hostname isprologix-<MAC Address>
)
For the GPIB-USB Controller, the format of the address
string is Prologix::PORT::PAD[::SAD]
, where PORT
is the name of the serial port of the Prologix
hardware, PAD
(Primary GPIB Address) is an integer value between 0 and 30, and SAD (Secondary
GPIB Address) is an integer value between 96 and 126 (SAD is optional). For example,
Prologix::COM3::6
Prologix::/dev/ttyUSB0::6::112
Alternatively, to clearly separate the Prologix hardware address from the GPIB address you may include
GPIB::
in the address, for example,
Prologix::192.168.1.110::1234::GPIB::6
Prologix::COM3::GPIB::22::96
Parameters:
Name | Type | Description | Default |
---|---|---|---|
equipment
|
Equipment
|
An Equipment instance. |
required |
A Connection instance supports the following properties for using Prologix hardware, as well as the properties defined in, Serial (for a GPIB-USB Controller) and in Socket (for a GPIB-ETHERNET Controller).
Connection Properties:
Name | Type | Description |
---|---|---|
eoi |
int
|
Whether to use the End or Identify line, either |
eos |
int
|
GPIB termination character(s): 0 (CR+LF), 1 (CR), 2 (LF) or 3 (no termination). |
eot_char |
int
|
A user-specified character to append to network output when |
eot_enable |
int
|
Enables (1) or disables (0) the appending of a user-specified character, |
mode |
int
|
Configure the Prologix hardware to be a CONTROLLER (1) or DEVICE (0). Default: |
read_tmo_ms |
int
|
The inter-character timeout value, in milliseconds, to be used in the read
command and the spoll command, i.e., the delay since the last character was read. The
|
Source code in src/msl/equipment/interfaces/prologix.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 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 |
|
controller
property
¤
The connection to the Prologix Controller for this equipment.
The returned type depends on whether a GPIB-USB or a GPIB-ETHERNET Controller is used to communicate with the equipment.
query_auto
property
writable
¤
query_auto: bool
Whether to send ++auto 1
before and ++auto 0
after a
query to the Prologix Controller.
timeout
property
writable
¤
timeout: float | None
The timeout, in seconds, to use for the connection to the Prologix hardware.
This timeout value is not to be confused with the read_tmo_ms
command that Prologix Controllers
accept. To set the inter-character delay, i.e., the delay since the last character was read or
for the spoll command, write the
++read_tmo_ms <time>
message to the Controller.
disconnect
¤
disconnect() -> None
Disconnect from the equipment.
Calling this method does not close the underlying Serial or Socket connection to the Prologix Controller since the connection to the Prologix Controller may still be required to send messages to other GPIB devices that are attached to the Controller.
Source code in src/msl/equipment/interfaces/prologix.py
170 171 172 173 174 175 176 177 178 179 180 |
|
group_execute_trigger
¤
Send the Group Execute Trigger command to equipment at the specified addresses.
Up to 15 addresses may be specified. If no address is specified then the Group Execute Trigger command is issued to the currently-addressed equipment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
addresses
|
int
|
The primary (and optional secondary) GPIB addresses. If a secondary address is specified then it must follow its corresponding primary address, for example,
|
()
|
Returns:
Type | Description |
---|---|
int
|
The number of bytes written. |
Source code in src/msl/equipment/interfaces/prologix.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
|
query
¤
query(
message: bytes | str,
*,
delay: float = 0.0,
decode: Literal[True] = True,
dtype: None = None,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> str
query(
message: bytes | str,
*,
delay: float = 0.0,
decode: Literal[False] = False,
dtype: None = None,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> bytes
query(
message: bytes | str,
*,
delay: float = 0.0,
decode: bool = ...,
dtype: MessageDataType = ...,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> NumpyArray1D
query(
message: bytes | str,
*,
delay: float = 0.0,
decode: bool = True,
dtype: MessageDataType | None = None,
fmt: MessageFormat | None = 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. See from_bytes
for more details. For messages that are of scalar type (i.e., a single number)
it is more efficient to not specify |
None
|
fmt
|
MessageFormat | None
|
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
|
The message from the equipment. If |
Source code in src/msl/equipment/interfaces/prologix.py
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 |
|
read
¤
read(
*,
decode: Literal[True] = True,
dtype: None = None,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> str
read(
*,
decode: Literal[False] = False,
dtype: None = None,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> bytes
read(
*,
decode: bool = ...,
dtype: MessageDataType = ...,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> NumpyArray1D
read(
*,
decode: bool = True,
dtype: MessageDataType | None = None,
fmt: MessageFormat | None = None,
size: int | None = None
) -> bytes | str | NumpyArray1D
Read a message from the equipment.
See MessageBased.read() for more details.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
decode
|
bool
|
True
|
|
dtype
|
MessageDataType | None
|
The data type of the elements in the message. Can be any object
that numpy dtype supports. See from_bytes
for more details. For messages that are of scalar type (i.e., a single number)
it is more efficient to not specify |
None
|
fmt
|
MessageFormat | None
|
The format that the 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/prologix.py
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 |
|
write
¤
write(
message: bytes | str,
*,
data: Sequence1D | None = None,
dtype: MessageDataType = "<f",
fmt: MessageFormat | None = "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 | None
|
The format to use to convert |
'ieee'
|
Returns:
Type | Description |
---|---|
int
|
The number of bytes written. |
Source code in src/msl/equipment/interfaces/prologix.py
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 |
|
PyVISA
¤
PyVISA(equipment: Equipment)
Bases: Interface
Use PyVISA as the backend to communicate with the equipment.
The backend value must be equal to
PyVISA
to use this class for the communication backend.
The PYVISA_LIBRARY
environment variable is used (if it exists) to create the
ResourceManager. This environment variable
can be defined in a configuration file or by defining the
environment variable in your code before connecting to the equipment using
PyVISA for the first time. The default
value is @ivi
if this environment variable is not defined.
The returned object using msl-equipment
to connect to the equipment is equivalent
to calling open_resource, e.g.,
from msl.equipment import Backend, Connection
connection = Connection("GPIB::12", backend=Backend.PyVISA)
inst = connection.connect()
print(inst.query("*IDN?"))
is equivalent to
import pyvisa
rm = pyvisa.ResourceManager()
inst = rm.open_resource("GPIB::12")
print(inst.query("*IDN?"))
You can also combine the packages, use msl-equipment
for managing information
about the equipment and directly use pyvisa
for the connection. If you use this
combination, the editor you use to develop your code may have better support for
features like code completion and type checking.
import pyvisa
from msl.equipment import Config
# config.xml contains <equipment eid="MSLE.0.063" name="dmm"/>
# and specifies where the equipment registers are and the connections file.
cfg = Config("config.xml")
equipment = cfg.equipment["dmm"]
rm = pyvisa.ResourceManager()
inst = rm.open_resource(equipment.connection.address)
data = inst.query("READ?")
# You could now use the `equipment` instance to apply a correction to the `data`
Parameters:
Name | Type | Description | Default |
---|---|---|---|
equipment
|
Equipment
|
An Equipment instance. |
required |
Source code in src/msl/equipment/interfaces/pyvisa.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
disconnect
¤
disconnect() -> None
Calls pyvisa.resources.Resource.close.
Source code in src/msl/equipment/interfaces/pyvisa.py
126 127 128 129 130 131 132 |
|
SDK
¤
Bases: Interface
Base class for equipment that use the manufacturer's Software Development Kit (SDK).
You can use the configuration file to add the directory that the SDK
is located at to the PATH
environment variable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
equipment
|
Equipment
|
An Equipment instance. |
required |
libtype
|
LibType | None
|
The library type. See LoadLibrary for more details. |
None
|
path
|
PathLike | None
|
The path to the SDK. Specifying this value will take precedence over the address value. |
None
|
Source code in src/msl/equipment/interfaces/sdk.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
|
disconnect
¤
disconnect() -> None
Cleanup references to the SDK library.
Source code in src/msl/equipment/interfaces/sdk.py
57 58 59 60 61 62 |
|
log_errcheck
¤
Convenience method for logging an errcheck from ctypes.
Source code in src/msl/equipment/interfaces/sdk.py
69 70 71 72 |
|
Serial
¤
Serial(equipment: Equipment)
Bases: MessageBased
Base class for equipment that is connected through a serial port.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
equipment
|
Equipment
|
An Equipment instance. |
required |
A Connection instance supports the following properties for the serial communication protocol, as well as the properties defined in MessageBased. The DataBits, Parity and StopBits enumeration names and values may also be used. For properties that specify an alias, you may also use the alternative name as the property name. See serial.Serial for more details.
Connection Properties:
Name | Type | Description |
---|---|---|
baud_rate |
int
|
The baud rate (alias: baudrate). Default: |
data_bits |
int
|
The number of data bits, e.g. 5, 6, 7, 8 (alias: bytesize). Default: |
dsr_dtr |
bool
|
Whether to enable hardware (DSR/DTR) flow control (alias: dsrdtr). Default: |
inter_byte_timeout |
float | None
|
The inter-character timeout. Default: |
parity |
str
|
Parity checking, e.g. 'even', 'odd'. Default: |
rts_cts |
bool
|
Whether to enable hardware (RTS/CTS) flow control (alias: rtscts). Default: |
stop_bits |
int | float
|
The number of stop bits, e.g. 1, 1.5, 2 (alias: stopbits). Default: |
xon_xoff |
bool
|
Whether to enable software flow control (alias: xonxoff). Default: |
Source code in src/msl/equipment/interfaces/serial.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
|
disconnect
¤
disconnect() -> None
Close the serial port.
Source code in src/msl/equipment/interfaces/serial.py
136 137 138 139 140 |
|
query
¤
query(
message: bytes | str,
*,
delay: float = 0.0,
decode: Literal[True] = True,
dtype: None = None,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> str
query(
message: bytes | str,
*,
delay: float = 0.0,
decode: Literal[False] = False,
dtype: None = None,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> bytes
query(
message: bytes | str,
*,
delay: float = 0.0,
decode: bool = ...,
dtype: MessageDataType = ...,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> NumpyArray1D
query(
message: bytes | str,
*,
delay: float = 0.0,
decode: bool = True,
dtype: MessageDataType | None = None,
fmt: MessageFormat | None = 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. See from_bytes
for more details. For messages that are of scalar type (i.e., a single number)
it is more efficient to not specify |
None
|
fmt
|
MessageFormat | None
|
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
170 171 172 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 |
|
read
¤
read(
*,
decode: Literal[True] = True,
dtype: None = None,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> str
read(
*,
decode: Literal[False] = False,
dtype: None = None,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> bytes
read(
*,
decode: bool = ...,
dtype: MessageDataType = ...,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> NumpyArray1D
read(
*,
decode: bool = True,
dtype: MessageDataType | None = None,
fmt: MessageFormat | None = 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:
size
bytes have been received — only ifsize
is 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 message. Can be any object
that numpy dtype supports. See from_bytes
for more details. For messages that are of scalar type (i.e., a single number)
it is more efficient to not specify |
None
|
fmt
|
MessageFormat | None
|
The format that the 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
239 240 241 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 |
|
write
¤
write(
message: bytes | str,
*,
data: Sequence1D | None = None,
dtype: MessageDataType = "<f",
fmt: MessageFormat | None = "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 | None
|
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
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 399 400 |
|
Socket
¤
Socket(equipment: Equipment)
Bases: MessageBased
Base class for equipment that is connected through a socket.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
equipment
|
Equipment
|
An Equipment instance. |
required |
A Connection instance supports the following properties for the socket communication protocol, as well as the properties defined in MessageBased.
Connection Properties:
Name | Type | Description |
---|---|---|
buffer_size |
int
|
The maximum number of bytes to read at a time. Default: |
Source code in src/msl/equipment/interfaces/socket.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
|
disconnect
¤
disconnect() -> None
Close the socket.
Source code in src/msl/equipment/interfaces/socket.py
131 132 133 134 135 |
|
query
¤
query(
message: bytes | str,
*,
delay: float = 0.0,
decode: Literal[True] = True,
dtype: None = None,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> str
query(
message: bytes | str,
*,
delay: float = 0.0,
decode: Literal[False] = False,
dtype: None = None,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> bytes
query(
message: bytes | str,
*,
delay: float = 0.0,
decode: bool = ...,
dtype: MessageDataType = ...,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> NumpyArray1D
query(
message: bytes | str,
*,
delay: float = 0.0,
decode: bool = True,
dtype: MessageDataType | None = None,
fmt: MessageFormat | None = 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. See from_bytes
for more details. For messages that are of scalar type (i.e., a single number)
it is more efficient to not specify |
None
|
fmt
|
MessageFormat | None
|
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
170 171 172 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 |
|
read
¤
read(
*,
decode: Literal[True] = True,
dtype: None = None,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> str
read(
*,
decode: Literal[False] = False,
dtype: None = None,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> bytes
read(
*,
decode: bool = ...,
dtype: MessageDataType = ...,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> NumpyArray1D
read(
*,
decode: bool = True,
dtype: MessageDataType | None = None,
fmt: MessageFormat | None = 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:
size
bytes have been received — only ifsize
is 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 message. Can be any object
that numpy dtype supports. See from_bytes
for more details. For messages that are of scalar type (i.e., a single number)
it is more efficient to not specify |
None
|
fmt
|
MessageFormat | None
|
The format that the 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
239 240 241 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 |
|
reconnect
¤
reconnect(max_attempts: int = 1) -> None
Reconnect to the equipment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
max_attempts
|
int
|
The maximum number of attempts to try to reconnect with the equipment. If <1, keep trying until a connection is successful. If the maximum number of attempts has been reached then an exception is raise. |
1
|
Source code in src/msl/equipment/interfaces/socket.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
|
write
¤
write(
message: bytes | str,
*,
data: Sequence1D | None = None,
dtype: MessageDataType = "<f",
fmt: MessageFormat | None = "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 | None
|
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
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 399 400 |
|
VXI11
¤
VXI11(equipment: Equipment)
Bases: MessageBased
Base class for the VXI-11 communication protocol.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
equipment
|
Equipment
|
An Equipment instance. |
required |
A Connection instance supports the following properties for the VXI-11 communication protocol, as well as the properties defined in MessageBased.
Connection Properties:
Name | Type | Description |
---|---|---|
buffer_size |
int
|
The maximum number of bytes to read at a time. Default: |
lock_timeout |
float
|
The timeout (in seconds) to wait for a lock (0 means wait forever). Default: |
port |
int
|
The port to use instead of calling the RPC Port Mapper function. |
Source code in src/msl/equipment/interfaces/vxi11.py
796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 |
|
lock_timeout
property
writable
¤
lock_timeout: float
The time, in seconds, to wait to acquire a lock.
Setting the value to ≤0 (or None
) means wait forever.
abort
¤
abort() -> None
Stop an in-progress request.
Source code in src/msl/equipment/interfaces/vxi11.py
985 986 987 988 989 990 |
|
clear
¤
clear() -> None
Send the clear
command to the device.
Source code in src/msl/equipment/interfaces/vxi11.py
992 993 994 995 996 997 998 999 1000 1001 1002 |
|
create_intr_chan
¤
create_intr_chan(
host_addr: int,
host_port: int,
prog_num: int,
prog_vers: int,
prog_family: int,
) -> None
Inform the network instrument server to establish an interrupt channel.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
host_addr
|
int
|
Address of the host servicing the interrupt. |
required |
host_port
|
int
|
Valid port number on the client. |
required |
prog_num
|
int
|
Program number. |
required |
prog_vers
|
int
|
Program version number. |
required |
prog_family
|
int
|
The underlying socket protocol family type ( |
required |
Source code in src/msl/equipment/interfaces/vxi11.py
1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 |
|
destroy_intr_chan
¤
destroy_intr_chan() -> None
Inform the network instrument server to close its interrupt channel.
Source code in src/msl/equipment/interfaces/vxi11.py
1021 1022 1023 1024 1025 1026 |
|
destroy_link
¤
destroy_link() -> None
Destroy the link with the device.
Source code in src/msl/equipment/interfaces/vxi11.py
1028 1029 1030 1031 1032 1033 |
|
disconnect
¤
disconnect() -> None
Unlink and close the sockets.
Source code in src/msl/equipment/interfaces/vxi11.py
1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 |
|
docmd
¤
Allows for a variety of commands to be executed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cmd
|
int
|
An IEEE 488 command messages. For example, to send the Group Execute Trigger
command, GET, the value of |
required |
value
|
float
|
required | |
fmt
|
str
|
How to format |
required |
Returns:
Type | Description |
---|---|
bytes
|
The results defined by |
Source code in src/msl/equipment/interfaces/vxi11.py
1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 |
|
enable_sqr
¤
Enable or disable the sending of device_intr_srq
RPCs by the network instrument server.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state
|
bool
|
Whether to enable or disable interrupts. |
required |
handle
|
bytes
|
Host specific data (maximum length is 40 characters). |
required |
Source code in src/msl/equipment/interfaces/vxi11.py
1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 |
|
local
¤
local() -> None
Place the device in a local state wherein all programmable local controls are enabled.
Source code in src/msl/equipment/interfaces/vxi11.py
1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 |
|
lock
¤
lock() -> None
Acquire the device's lock.
Source code in src/msl/equipment/interfaces/vxi11.py
1108 1109 1110 1111 1112 1113 |
|
query
¤
query(
message: bytes | str,
*,
delay: float = 0.0,
decode: Literal[True] = True,
dtype: None = None,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> str
query(
message: bytes | str,
*,
delay: float = 0.0,
decode: Literal[False] = False,
dtype: None = None,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> bytes
query(
message: bytes | str,
*,
delay: float = 0.0,
decode: bool = ...,
dtype: MessageDataType = ...,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> NumpyArray1D
query(
message: bytes | str,
*,
delay: float = 0.0,
decode: bool = True,
dtype: MessageDataType | None = None,
fmt: MessageFormat | None = 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. See from_bytes
for more details. For messages that are of scalar type (i.e., a single number)
it is more efficient to not specify |
None
|
fmt
|
MessageFormat | None
|
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
170 171 172 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 |
|
read
¤
read(
*,
decode: Literal[True] = True,
dtype: None = None,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> str
read(
*,
decode: Literal[False] = False,
dtype: None = None,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> bytes
read(
*,
decode: bool = ...,
dtype: MessageDataType = ...,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> NumpyArray1D
read(
*,
decode: bool = True,
dtype: MessageDataType | None = None,
fmt: MessageFormat | None = 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:
size
bytes have been received — only ifsize
is 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 message. Can be any object
that numpy dtype supports. See from_bytes
for more details. For messages that are of scalar type (i.e., a single number)
it is more efficient to not specify |
None
|
fmt
|
MessageFormat | None
|
The format that the 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
239 240 241 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 |
|
read_stb
¤
read_stb() -> int
Read the status byte from the device.
Returns:
Type | Description |
---|---|
int
|
The status byte. |
Source code in src/msl/equipment/interfaces/vxi11.py
1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 |
|
reconnect
¤
reconnect(max_attempts: int = 1) -> None
Reconnect to the equipment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
max_attempts
|
int
|
The maximum number of attempts to try to reconnect with the equipment. If <1, keep trying until a connection is successful. If the maximum number of attempts has been reached then an exception is raise. |
1
|
Source code in src/msl/equipment/interfaces/vxi11.py
1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 |
|
remote
¤
remote() -> None
Place the device in a remote state wherein all programmable local controls are disabled.
Source code in src/msl/equipment/interfaces/vxi11.py
1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 |
|
trigger
¤
trigger() -> None
Send a trigger to the device.
Source code in src/msl/equipment/interfaces/vxi11.py
1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 |
|
unlock
¤
unlock() -> None
Release the lock acquired by lock.
Source code in src/msl/equipment/interfaces/vxi11.py
1198 1199 1200 1201 1202 1203 |
|
write
¤
write(
message: bytes | str,
*,
data: Sequence1D | None = None,
dtype: MessageDataType = "<f",
fmt: MessageFormat | None = "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 | None
|
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
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 399 400 |
|
ZeroMQ
¤
ZeroMQ(equipment: Equipment)
Bases: MessageBased
Base class for equipment that use the ZeroMQ communication protocol.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
equipment
|
Equipment
|
An Equipment instance. |
required |
A Connection instance supports the following properties
for the ZeroMQ communication protocol, as well as the properties
defined in MessageBased.
The ZeroMQ protocol does not use termination characters, so if
termination characters are specified the value is ignored and is set to None
.
Connection Properties:
Name | Type | Description |
---|---|---|
protocol |
str
|
ZeroMQ protocol ( |
socket_type |
int | str
|
ZeroMQ socket type. Default: |
Source code in src/msl/equipment/interfaces/zeromq.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
|
disconnect
¤
disconnect() -> None
Close the socket connection and terminate the context.
Source code in src/msl/equipment/interfaces/zeromq.py
100 101 102 103 104 105 106 107 |
|
query
¤
query(
message: bytes | str,
*,
delay: float = 0.0,
decode: Literal[True] = True,
dtype: None = None,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> str
query(
message: bytes | str,
*,
delay: float = 0.0,
decode: Literal[False] = False,
dtype: None = None,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> bytes
query(
message: bytes | str,
*,
delay: float = 0.0,
decode: bool = ...,
dtype: MessageDataType = ...,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> NumpyArray1D
query(
message: bytes | str,
*,
delay: float = 0.0,
decode: bool = True,
dtype: MessageDataType | None = None,
fmt: MessageFormat | None = 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. See from_bytes
for more details. For messages that are of scalar type (i.e., a single number)
it is more efficient to not specify |
None
|
fmt
|
MessageFormat | None
|
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
170 171 172 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 |
|
read
¤
read(
*,
decode: Literal[True] = True,
dtype: None = None,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> str
read(
*,
decode: Literal[False] = False,
dtype: None = None,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> bytes
read(
*,
decode: bool = ...,
dtype: MessageDataType = ...,
fmt: MessageFormat | None = ...,
size: int | None = ...
) -> NumpyArray1D
read(
*,
decode: bool = True,
dtype: MessageDataType | None = None,
fmt: MessageFormat | None = 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:
size
bytes have been received — only ifsize
is 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 message. Can be any object
that numpy dtype supports. See from_bytes
for more details. For messages that are of scalar type (i.e., a single number)
it is more efficient to not specify |
None
|
fmt
|
MessageFormat | None
|
The format that the 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
239 240 241 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 |
|
write
¤
write(
message: bytes | str,
*,
data: Sequence1D | None = None,
dtype: MessageDataType = "<f",
fmt: MessageFormat | None = "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 | None
|
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
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 399 400 |
|