Driver Utils¶
-
class
instrumental.drivers.
VisaMixin
¶ -
query
(message, *args, **kwds)¶ Query the instrument’s VISA resource with
message
Flushes the message queue if called within a transaction.
-
transaction
(**kwds)¶ Transaction context manager to auto-chain VISA messages
Queues individual messages written with the
write()
method and sends them all at once, joined by ‘;’. Messages are actually sent (1) when a call toquery()
is made and (2) upon the end of transaction.This is especially useful when using higher-level functions that call
write()
, as it lets you combine multiple logical operations into a single message (if only using writes), which can be faster than sending lots of little messages.Be cognizant that a visa resource’s write and query methods are not transaction-aware, only VisaMixin’s are. If you need to call one of these methods (e.g. write_raw), make sure you flush the message queue manually with
_flush_message_queue()
.As an example:
>>> with myinst.transaction(): ... myinst.write('A') ... myinst.write('B') ... myinst.query('C?') # Query forces flush. Writes "A;B" and queries "C?" ... myinst.write('D') ... myinst.write('E') # End of transaction block, writes "D;E"
-
write
(message, *args, **kwds)¶ Write a string message to the instrument’s VISA resource
Calls
format(*args, **kwds)
to format the message. This allows for clean inclusion of parameters. For example:>>> inst.write('source{}:value {}', channel, value)
-
resource
¶ VISA resource
-
Helpful utilities for writing drivers.
-
instrumental.drivers.util.
check_units
(*pos, **named)¶ Decorator to enforce the dimensionality of input args and return values.
Allows strings and anything that can be passed as a single arg to
pint.Quantity
.@check_units(value='V') def set_voltage(value): pass # `value` will be a pint.Quantity with Volt-like units
-
instrumental.drivers.util.
unit_mag
(*pos, **named)¶ Decorator to extract the magnitudes of input args and return values.
Allows strings and anything that can be passed as a single arg to
pint.Quantity
.@unit_mag(value='V') def set_voltage(value): pass # The input must be in Volt-like units and `value` will be a raw number # expressing the magnitude in Volts
-
instrumental.drivers.util.
check_enums
(**kw_args)¶ Decorator to type-check input arguments as enums.
Allows strings and anything that can be passed to
as_enum
.@check_enums(mode=SampleMode) def set_mode(mode): pass # `mode` will be of type SampleMode
-
instrumental.drivers.util.
as_enum
(enum_type, arg)¶ Check if arg is an instance or key of enum_type, and return that enum
-
instrumental.drivers.util.
visa_timeout_context
(*args, **kwds)¶ Context manager for temporarily setting a visa resource’s timeout.
with visa_timeout_context(rsrc, 100): ... # `rsrc` will have a timeout of 100 ms within this block