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

Implement return_to_local (not tested)

parent c27e71f7
...@@ -58,14 +58,30 @@ import threading ...@@ -58,14 +58,30 @@ import threading
class CamrasHpibDevice(object): class CamrasHpibDevice(object):
"""Wrapper around HPIB commands""" """Wrapper around HPIB commands
Args:
address (int): GPIB address
check_frequency (bool): check the frequency after setting it, raise an error if setting
the frequency failed
return_to_local (bool): return the device to local mode after each HPIB command. Some
devices switch out of manual mode when a HPIB command is set; undo this.
Attributes:
hpib_address (int): GPIB address
check_frequency (bool): check the frequency after setting it, raise an error if setting
the frequency failed
return_to_local (bool): return the device to local mode after each HPIB command. Some
devices switch out of manual mode when a HPIB command is set; undo this.
"""
command_thread = None command_thread = None
_initialization_lock = threading.Lock() _initialization_lock = threading.Lock()
def __init__(self, address, check_frequency=True): def __init__(self, address, check_frequency=True, return_to_local=False):
self.hpib_address = address self.hpib_address = address
self._check_frequency = check_frequency self._check_frequency = check_frequency
self.return_to_local = return_to_local
with self._initialization_lock: with self._initialization_lock:
if not CamrasHpibDevice.command_thread: if not CamrasHpibDevice.command_thread:
...@@ -76,12 +92,13 @@ class CamrasHpibDevice(object): ...@@ -76,12 +92,13 @@ class CamrasHpibDevice(object):
CamrasHpibDevice.command_thread._connection_made.wait() CamrasHpibDevice.command_thread._connection_made.wait()
CamrasHpibDevice.command_thread.protocol.init_hpib() CamrasHpibDevice.command_thread.protocol.init_hpib()
def command(self, command_string, prepend_address=True): def command(self, command_string, prepend_address=True, return_to_local=False):
"""Send a command to the HPIB command thread """Send a command to the HPIB command thread
Args: Args:
command_string (str): HPIB command command_string (str): HPIB command
prepend_address (bool): first send the address of this device prepend_address (bool): first send the address of this device
return_to_local (bool): send a 'return to local' command after the command
Returns: Returns:
str: output of the command (in case it was a query) str: output of the command (in case it was a query)
...@@ -91,7 +108,8 @@ class CamrasHpibDevice(object): ...@@ -91,7 +108,8 @@ class CamrasHpibDevice(object):
else: else:
address = None address = None
return CamrasHpibDevice.command_thread.protocol.command(command_string, address) return CamrasHpibDevice.command_thread.protocol.command(command_string, address,
return_to_local=self.return_to_local)
@property @property
def frequency(self): def frequency(self):
...@@ -143,7 +161,7 @@ class LocalOscillator(CamrasHpibDevice): ...@@ -143,7 +161,7 @@ class LocalOscillator(CamrasHpibDevice):
"""Wrapper around HPIB commands for the local oscillator""" """Wrapper around HPIB commands for the local oscillator"""
def __init__(self, **kwargs): def __init__(self, **kwargs):
super(LocalOscillator, self).__init__(28) super(LocalOscillator, self).__init__(28, return_to_local=True)
class ClockGenerator(CamrasHpibDevice): class ClockGenerator(CamrasHpibDevice):
......
...@@ -34,13 +34,14 @@ class GPIBProtocol(serial.threaded.LineReader): ...@@ -34,13 +34,14 @@ class GPIBProtocol(serial.threaded.LineReader):
self.write_line("++eot_char 0") self.write_line("++eot_char 0")
self.write_line("++read_tmo_ms 500") self.write_line("++read_tmo_ms 500")
def command(self, command, timeout=0.2, address=None): def command(self, command, timeout=0.2, address=None, return_to_local=False):
"""Execute a HPIB command """Execute a HPIB command
Args: Args:
command (str): Command to execute (can be a query) command (str): Command to execute (can be a query)
timeout (float): How long to wait for a reply timeout (float): How long to wait for a reply
address (int): HPIB address to send the command to address (int): HPIB address to send the command to
return_to_local (bool): send a 'return to local' command after the command
Returns: Returns:
If the command contains '?', the value returned by If the command contains '?', the value returned by
...@@ -53,6 +54,9 @@ class GPIBProtocol(serial.threaded.LineReader): ...@@ -53,6 +54,9 @@ class GPIBProtocol(serial.threaded.LineReader):
if address: if address:
self.write_line("++addr {:d}".format(address)) self.write_line("++addr {:d}".format(address))
self.write_line(command) self.write_line(command)
if address and return_to_local:
self.write_line("loc {:d}".format(address))
if "?" in command: if "?" in command:
self.write_line("++read eoi") self.write_line("++read eoi")
# The command was a query, wait for response # The command was a query, wait for response
......
Markdown is supported
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