Commit bf072b26 authored by Tammo Jan Dijkema's avatar Tammo Jan Dijkema
Browse files

Factor out command function

parent 2cb072d0
......@@ -34,6 +34,12 @@ This checking can be disabled:
>>> non_checking_lo.frequency
<Quantity 1.1 GHz>
Other HPIB commands can be sent using the `command` function:
>>> lo.command("loc 28") # Set device to local mode
Also generic HPIB commands (without specific address) can be sent:
>>> lo.command("++eoi 1", prepend_address=False)
The CamrasHpibDevice class spawns one thread (shared with all instances) to perform the HPIB
commands. This is to make sure that instances living in separate threads do not interfere with
each other. The thread is a daemon, so it will be killed on program exit.
......@@ -67,6 +73,23 @@ class CamrasHpibDevice(object):
def command(self, command_string, prepend_address=True):
"""Send a command to the HPIB command thread
command_string (str): HPIB command
prepend_address (bool): first send the address of this device
str: output of the command (in case it was a query)
if prepend_address:
address = self.address
address = None
return CamrasHpibDevice.command_thread.protocol.command(command_string, address)
def frequency(self):
"""Frequency of the device as an astropy Quantity.
......@@ -77,8 +100,8 @@ class CamrasHpibDevice(object):
RuntimeError: If the device does not respond
freq_str = CamrasHpibDevice.command_thread.protocol.command("freq?",
freq_str = self.command("freq?")
if not freq_str or len(freq_str) == 0:
raise RuntimeError("Camras device at address {} is not responding".format(
......@@ -97,8 +120,8 @@ class CamrasHpibDevice(object):
if isinstance(freq, Quantity):
freq =
CamrasHpibDevice.command_thread.protocol.command("freq {:d} Hz".format(int(freq)),
self.command("freq {:d} Hz".format(int(freq)))
new_freq = self.frequency
if self._check_frequency and != int(freq):
raise RuntimeError("Setting frequency failed: tried to set to {}, it is now {}".format(
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment