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