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

Make initialization of CamrasHpibDevice thread safe

parent bf072b26
...@@ -54,24 +54,27 @@ from astropy.units import Quantity ...@@ -54,24 +54,27 @@ from astropy.units import Quantity
import hpib import hpib
import serial.threaded import serial.threaded
import threading
class CamrasHpibDevice(object): class CamrasHpibDevice(object):
"""Wrapper around HPIB commands""" """Wrapper around HPIB commands"""
command_thread = None command_thread = None
_initialization_lock = threading.Lock()
def __init__(self, address, check_frequency=True): def __init__(self, address, check_frequency=True):
self.hpib_address = address self.hpib_address = address
self._check_frequency = check_frequency self._check_frequency = check_frequency
if not CamrasHpibDevice.command_thread: with self._initialization_lock:
serial_port = serial.Serial("/dev/ttyUSB0") if not CamrasHpibDevice.command_thread:
CamrasHpibDevice.command_thread = serial.threaded.ReaderThread(serial_port, serial_port = serial.Serial("/dev/ttyUSB0")
hpib.GPIBProtocol) CamrasHpibDevice.command_thread = serial.threaded.ReaderThread(serial_port,
CamrasHpibDevice.command_thread.start() hpib.GPIBProtocol)
CamrasHpibDevice.command_thread._connection_made.wait() CamrasHpibDevice.command_thread.start()
CamrasHpibDevice.command_thread.protocol.init_hpib() CamrasHpibDevice.command_thread._connection_made.wait()
CamrasHpibDevice.command_thread.protocol.init_hpib()
def command(self, command_string, prepend_address=True): def command(self, command_string, prepend_address=True):
"""Send a command to the HPIB command thread """Send a command to the HPIB command thread
......
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