InstrumentAPI
Bases: object
Super class of all instrument drivers for LabExT.
The methods in this class implement all the basic necessary instrument-related functionality, mainly communication via the VISA library, error checks, setup and teardown.
Important: every instrument tries to use the LabExT-global pyvisa resource manager instantiated on LabExT startup. If it cannot be found (e.g. on standalone driver usage w/o LabExT GUI) it will instantiate a resource manager ad-hoc.
Attributes:
Name | Type | Description |
---|---|---|
error_query_string |
str
|
String to query the instrument's error queue. By default |
ignored_SCPI_error_numbers |
list of int
|
include all error numbers of the SCPI error queue which should be ignored. This can be for example useful if your instrument reports warnings also in the error queue. |
channel |
int
|
channel number for multi-channel instruments (e.g. laser mainframe, most DSOs, etc.), None if a single channel instrument is used. |
instrument_config_descriptor |
dict
|
A verbatim copy of the instruments.config entry used for this instance of the driver. Set during driver initialization in InstrumentAPI. |
networked_instrument_properties |
list
|
Add to this list all object properties which should get freshly fetched and added to self.instrument_parameters on each get_instrument_parameter() call. |
Source code in LabExT/Instruments/InstrumentAPI/_Instrument.py
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 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 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 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 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 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 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 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 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 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 |
|
thread_lock
property
Thread-lock for exclusive instrument access.
Use this lock to acquire exclusive access to an instrument without any other thread meddling with it. Caution: A mainframe containing multiple instruments still counts as one connection and hence these instruments share this lock!
LabExT does not enforce any exclusivity of the instruments itself. You need to take care that you do not deadlock the instruments yourself.
Do NOT save the reference of this lock anywhere!
This lock can only be acquired if this instrument is open. Otherwise having a lock does not work.
Returns:
Type | Description |
---|---|
threading.Lock: a lock exclusive for this instrument's connection |
__init__(visa_address, channel=None, **kwargs)
Constructor of the Instrument class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
visa_address |
str
|
the VISA address of the requested device |
required |
channel |
int
|
if the instrument has multiple channels associated, fill its number in here |
None
|
**kwargs |
kwargs are saved in the |
{}
|
Source code in LabExT/Instruments/InstrumentAPI/_Instrument.py
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 |
|
check_instrument_errors()
Checks the internal error queue of the instrument.
This form of error checking should work for all instruments adhering to the SCPI standard (notably all Agilent / Keysight ones). If it does not work for your instrument, don't hesitate to implement a working version.
Raises:
Type | Description |
---|---|
InstrumentException
|
if the instrument reports an error |
Source code in LabExT/Instruments/InstrumentAPI/_Instrument.py
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
|
clear()
Clears all status registers.
Source code in LabExT/Instruments/InstrumentAPI/_Instrument.py
247 248 249 250 251 |
|
close()
Close the connection to the instrument.
Also clears all IO buffers.
Source code in LabExT/Instruments/InstrumentAPI/_Instrument.py
210 211 212 213 214 215 216 217 218 |
|
command(command_str)
High-level write call incl. ready-check and error check.
Sends a SCPI text command to the instrument, waits until its completion and checks that there was no error in communicating. Use this function to send standard, non timing critical SCPI commands.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
command_str |
str
|
the command string to send to the instrument. |
required |
Source code in LabExT/Instruments/InstrumentAPI/_Instrument.py
337 338 339 340 341 342 343 344 345 346 347 348 349 |
|
command_channel(subsystem_str, command_str)
High-level shortcut function to send a command to a channel in a multi-channeled instrument.
This function blocks until command completion and makes sure that there was no communication error.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
subsystem_str |
str
|
first part of the command string, before the channel number |
required |
command_str |
str
|
second part of the command string, after the channel number |
required |
Source code in LabExT/Instruments/InstrumentAPI/_Instrument.py
351 352 353 354 355 356 357 358 359 360 361 362 363 364 |
|
get_instrument_parameter()
Return the currently set instrument parameters.
Reads all properties directly from instrument if connection to instrument can be opened. This method is called before and after a measurement execution in LabExT to save the instrument state as meta data.
Include all property names you want to read in the self.networked_instrument_properties
list.
Source code in LabExT/Instruments/InstrumentAPI/_Instrument.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
|
idn()
Query the ID string of the lab instrument.
Source code in LabExT/Instruments/InstrumentAPI/_Instrument.py
253 254 255 256 257 258 |
|
open()
Open the connection to the instrument.
Automatically re-uses any old connection if it is already open with the reusing-resource manager.
Source code in LabExT/Instruments/InstrumentAPI/_Instrument.py
202 203 204 205 206 207 208 |
|
query(query_str)
Low-level query function.
Send the query_str to the instrument and read its response. No ready-check or error check is performed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query_str |
str
|
string to be sent to the instrument |
required |
Returns: str: the answer from the instrument
Source code in LabExT/Instruments/InstrumentAPI/_Instrument.py
403 404 405 406 407 408 409 410 411 412 413 414 415 |
|
query_ascii_values(query_str, converter='f', separator=',', container=list)
Send a query to the instruments and read the answer into a Python container type.
Send the query_str to the instrument and read data in ASCII format from the answer. The answer is then interpreted as multiple separated numerical values which are filled into a container class. This is essentially a wrapper for self._inst.queary_ascii_values(query_str)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query_str |
str
|
the string to query the instrument with |
required |
converter |
str
|
string format to convert each value. Default is "f" (float). |
'f'
|
separator |
str
|
character, which separates the individual data points. Default is ",". |
','
|
container |
type
|
container type to use for the output data. Possible values are: list, tuple, np.ndarray among others. |
list
|
Returns:
Name | Type | Description |
---|---|---|
container |
The container |
:return: list of numbers
Source code in LabExT/Instruments/InstrumentAPI/_Instrument.py
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 |
|
query_channel(subsystem_str, write_str)
Low-level query function for channelized instruments.
Shortcut function to query commands from a channel in a multi-channeled instrument.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
subsystem_str |
str
|
first part of the send string, before the channel number |
required |
write_str |
str
|
second part of the send string, after the channel number |
required |
Returns: str: the answer from the instrument
Source code in LabExT/Instruments/InstrumentAPI/_Instrument.py
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 |
|
query_raw_bytes(query_str, N_bytes, chunk_size=None, break_on_termchar=False)
Send a query to the instrument and read the answer in raw bytes.
Send the query_str to the instrument and read N_bytes from the answer and return the raw bytes object. This is essentially a wrapper for self._inst.read_bytes(N_bytes) with the difference, that there is no error checking after the writing, since we expect an answer. Unpack the answer from this query with the struct module.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query_str |
str
|
the string to query the instrument with (optional, to not send anything, set to None) |
required |
N_bytes |
int
|
the number of bytes to expect as the instrument's response |
required |
chunk_size |
int
|
The chunk size to perform the reading with. |
None
|
break_on_termchar |
bool
|
Should the reading stop when the termination character is encountered? |
False
|
Returns:
Name | Type | Description |
---|---|---|
bytes |
the raw bytes read |
Source code in LabExT/Instruments/InstrumentAPI/_Instrument.py
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 |
|
ready_check_async()
Query the ESR register in the instrument for a non-blocking ready-check.
Queries the operation complete (OPC) bit in the instrument's status register. This call is NON-BLOCKING. It will return immediately with the result: False if the instrument's operation is not complete, and True if it is.
Before using this function, tell the instrument that it should fill its status register by calling ready_check_async_setup()!
Returns:
Name | Type | Description |
---|---|---|
bool |
True if operation complete bit set, False otherwise |
Source code in LabExT/Instruments/InstrumentAPI/_Instrument.py
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
|
ready_check_async_setup()
Prepare asynchronous read-checks.
Signal the instrument to reset the event status register (ESR) and start listening to operation complete signals to store into the ESR.
Source code in LabExT/Instruments/InstrumentAPI/_Instrument.py
277 278 279 280 281 282 283 284 285 |
|
ready_check_sync()
Query the OPC register in the instrument for a blocking ready-check.
Queries the operation complete (OPC) bit in the instrument's status register. This call is BLOCKING until the instrument signals completion. If the instrument does not return an answer within the timeout, this call errors.
Source code in LabExT/Instruments/InstrumentAPI/_Instrument.py
266 267 268 269 270 271 272 273 274 275 |
|
request(request_str)
High-level query call incl. ready-check and error check.
Sends a SCPI text request to the instrument, waits until its completion and checks that there was no error in communicating. Then returns the answer. Use this function to execute standard, non timing critical SCPI queries.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
request_str |
string to be queried |
required |
Returns: str: the answer from the instrument
Source code in LabExT/Instruments/InstrumentAPI/_Instrument.py
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 |
|
request_channel(subsystem_str, request_str)
High-level shortcut function to send a request to a channel in a multi-channeled instrument.
This function blocks until command completion and makes sure that there was no communication error.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
subsystem_str |
str
|
first part of the request string, before the channel number |
required |
request_str |
str
|
second part of the request string, after the channel number |
required |
Returns: str: the answer from the instrument
Source code in LabExT/Instruments/InstrumentAPI/_Instrument.py
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 |
|
reset()
Reset the laboratory instrument.
Source code in LabExT/Instruments/InstrumentAPI/_Instrument.py
260 261 262 263 264 |
|
write(write_str)
Low-level write function.
Send the write_str to the instrument. This function does not check command completion nor error free-ness, you must do both manually if desired.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
write_str |
str
|
string to be written |
required |
Source code in LabExT/Instruments/InstrumentAPI/_Instrument.py
433 434 435 436 437 438 439 440 441 442 443 |
|
write_channel(subsystem_str, write_str)
Low-level write function for channelized instruments.
Shortcut function to write commands to a channel in a multi-channeled instrument. This function does not check command completion nor error free-ness, you must do both manually if desired.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
subsystem_str |
str
|
first part of the send string, before the channel number |
required |
write_str |
str
|
second part of the send string, after the channel number |
required |
Source code in LabExT/Instruments/InstrumentAPI/_Instrument.py
445 446 447 448 449 450 451 452 453 454 455 456 457 458 |
|