Commit c99ede29 authored by Olivier Kaufmann's avatar Olivier Kaufmann
Browse files

Removes self.run and use self.status instead. Initialize sequence to None if...

Removes self.run and use self.status instead. Initialize sequence to None if not specified. Fixes slow execution due to non blocking TCP server.
Showing with 22 additions and 19 deletions
+22 -19
File added
...@@ -62,7 +62,7 @@ class OhmPi(object): ...@@ -62,7 +62,7 @@ class OhmPi(object):
self.sequence = sequence self.sequence = sequence
self.on_pi = on_pi # True if run from the RaspberryPi with the hardware, otherwise False for random data self.on_pi = on_pi # True if run from the RaspberryPi with the hardware, otherwise False for random data
self.status = 'idle' # either running or idle self.status = 'idle' # either running or idle
self.run = False # flag is True when measuring # self.run = False # flag is True when measuring
self.thread = None # contains the handle for the thread taking the measurement self.thread = None # contains the handle for the thread taking the measurement
# self.path = 'data/' # where to save the .csv # self.path = 'data/' # where to save the .csv
...@@ -96,9 +96,9 @@ class OhmPi(object): ...@@ -96,9 +96,9 @@ class OhmPi(object):
self.exec_logger.debug('Initialized with settings:' + str(self.settings)) self.exec_logger.debug('Initialized with settings:' + str(self.settings))
# read quadrupole sequence # read quadrupole sequence
if sequence is None: if sequence is not None:
self.sequence = np.array([[1, 2, 3, 4]], dtype=np.int32) # self.sequence = np.array([[1, 2, 3, 4]], dtype=np.int32)
else: # else:
self.read_quad(sequence) self.read_quad(sequence)
# connect to components on the OhmPi board # connect to components on the OhmPi board
...@@ -274,7 +274,7 @@ class OhmPi(object): ...@@ -274,7 +274,7 @@ class OhmPi(object):
role : str role : str
Either 'A', 'B', 'M' or 'N', so we can assign it to a MUX board. Either 'A', 'B', 'M' or 'N', so we can assign it to a MUX board.
""" """
if self.sequence.max() <= 4: # only 4 electrodes so no MUX if self.sequence is None: # only 4 electrodes so no MUX
pass pass
else: else:
# choose with MUX board # choose with MUX board
...@@ -374,7 +374,7 @@ class OhmPi(object): ...@@ -374,7 +374,7 @@ class OhmPi(object):
self.exec_logger.debug(f'Setting gain to {gain}') self.exec_logger.debug(f'Setting gain to {gain}')
return gain return gain
def run_measurement(self, quad, nb_stack=None, injection_duration=None): def run_measurement(self, quad=[0,0,0,0], nb_stack=None, injection_duration=None):
""" Do a 4 electrode measurement and measure transfer resistance obtained. """ Do a 4 electrode measurement and measure transfer resistance obtained.
Parameters Parameters
...@@ -527,20 +527,23 @@ class OhmPi(object): ...@@ -527,20 +527,23 @@ class OhmPi(object):
""" """
# create custom sequence where MN == AB # create custom sequence where MN == AB
# we only check the electrodes which are in the sequence (not all might be connected) # we only check the electrodes which are in the sequence (not all might be connected)
elec = np.sort(np.unique(self.sequence.flatten())) # assumed order if self.sequence is None:
quads = np.vstack([ quads = np.array([[1,2,1,2]])
elec[:-1], else:
elec[1:], elec = np.sort(np.unique(self.sequence.flatten())) # assumed order
elec[:-1], quads = np.vstack([
elec[1:], elec[:-1],
]).T elec[1:],
elec[:-1],
elec[1:],
]).T
# create filename to store RS # create filename to store RS
export_path_rs = self.settings['export_path'].replace('.csv', '') \ export_path_rs = self.settings['export_path'].replace('.csv', '') \
+ '_' + datetime.now().strftime('%Y%m%dT%H%M%S') + '_rs.csv' + '_' + datetime.now().strftime('%Y%m%dT%H%M%S') + '_rs.csv'
# perform RS check # perform RS check
self.run = True # self.run = True
self.status = 'running' self.status = 'running'
if self.on_pi: if self.on_pi:
...@@ -611,7 +614,7 @@ class OhmPi(object): ...@@ -611,7 +614,7 @@ class OhmPi(object):
else: else:
pass pass
self.status = 'idle' self.status = 'idle'
self.run = False # self.run = False
# #
# # TODO if interrupted, we would need to restore the values # # TODO if interrupted, we would need to restore the values
...@@ -654,7 +657,7 @@ class OhmPi(object): ...@@ -654,7 +657,7 @@ class OhmPi(object):
self.exec_logger.debug(f'Start listening for commands on port {tcp_port}') self.exec_logger.debug(f'Start listening for commands on port {tcp_port}')
while self.cmd_listen: while self.cmd_listen:
try: try:
message = socket.recv(flags=zmq.NOBLOCK) message = socket.recv() # flags=zmq.NOBLOCK)
self.exec_logger.debug(f'Received command: {message}') self.exec_logger.debug(f'Received command: {message}')
e = None e = None
try: try:
...@@ -720,13 +723,13 @@ class OhmPi(object): ...@@ -720,13 +723,13 @@ class OhmPi(object):
def measure(self, cmd_id=None): def measure(self, cmd_id=None):
"""Run the sequence in a separate thread. Can be stopped by 'OhmPi.stop()'. """Run the sequence in a separate thread. Can be stopped by 'OhmPi.stop()'.
""" """
self.run = True # self.run = True
self.status = 'running' self.status = 'running'
self.exec_logger.debug(f'Status: {self.status}') self.exec_logger.debug(f'Status: {self.status}')
def func(): def func():
for g in range(0, self.settings["nbr_meas"]): # for time-lapse monitoring for g in range(0, self.settings["nbr_meas"]): # for time-lapse monitoring
if self.run is False: if self.status != 'running':
self.exec_logger.warning('Data acquisition interrupted') self.exec_logger.warning('Data acquisition interrupted')
break break
t0 = time.time() t0 = time.time()
...@@ -786,7 +789,7 @@ class OhmPi(object): ...@@ -786,7 +789,7 @@ class OhmPi(object):
def stop(self): def stop(self):
"""Stop the acquisition. """Stop the acquisition.
""" """
self.run = False self.status = 'stopping'
if self.thread is not None: if self.thread is not None:
self.thread.join() self.thread.join()
self.exec_logger.debug(f'Status: {self.status}') self.exec_logger.debug(f'Status: {self.status}')
......
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