Commit 2c6e5683 authored by Tammo Jan Dijkema's avatar Tammo Jan Dijkema
Browse files

Fix initialization

parent c59cc9b0
......@@ -4,27 +4,26 @@ from astropy.units import Quantity
import hpib
import serial.threaded
command_thread = None
class CamrasHpibDevice(object):
"""Wrapper around HPIB commands"""
command_thread = None
def __init__(self, address):
if not command_thread.is_alive():
self.hpib_address = address
if not command_thread:
if not CamrasHpibDevice.command_thread:
serial_port = serial.Serial("/dev/ttyUSB0")
command_thread = serial.threaded.ReaderThread(serial_port, hpib.GPIBProtocol)
CamrasHpibDevice.command_thread = serial.threaded.ReaderThread(serial_port, hpib.GPIBProtocol)
def frequency(self):
"""Returns the frequency of the device as an astropy Quantity.
Throws a RuntimeError if no response"""
freq_str = command_thread.protocol.command("freq?", address=self.hpib_address)
freq_str = CamrasHpibDevice.command_thread.protocol.command("freq?", address=self.hpib_address)
if len(freq_str)==0:
raise RuntimeError("Camras device at address {} is not responding".format(self._hpib_address))
return int(float(freq_str)) * u.Hz
......@@ -38,7 +37,7 @@ class CamrasHpibDevice(object):
if isinstance(freq, Quantity):
freq =
command_thread.protocol.command("freq {:d} Hz".format(int(freq)), address=self.hpib_address)
CamrasHpibDevice.command_thread.protocol.command("freq {:d} Hz".format(int(freq)), address=self.hpib_address)
new_freq = self.frequency
if != int(freq):
raise RuntimeError("Setting frequency failed: tried to set to {}, it is now {}".format(
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