From 335bc31dfdd1662c18691c5f12ad09eb73329b4b Mon Sep 17 00:00:00 2001 From: su530201 <olivier.kaufmann@umons.ac.be> Date: Thu, 27 Oct 2022 18:16:58 +0200 Subject: [PATCH] Fixes bug due to a remainig self.run in ohmpi --- mqtt_interface.py | 9 ++++++--- ohmpi.py | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/mqtt_interface.py b/mqtt_interface.py index 6968a295..1eaf661e 100644 --- a/mqtt_interface.py +++ b/mqtt_interface.py @@ -6,6 +6,7 @@ import zmq ctrl_queue = Queue() + def on_message(client, userdata, message): global socket @@ -17,6 +18,7 @@ def on_message(client, userdata, message): reply = socket.recv() print(f'Received reply {message.payload.decode("utf-8")}: {reply}') + mqtt_client = mqtt.Client(f'ohmpi_{OHMPI_CONFIG["id"]}_listener', clean_session=False) # create new instance print('connecting command listener to broker') trials = 0 @@ -24,14 +26,15 @@ trials_max = 10 broker_connected = False while trials < trials_max: try: - mqtt_client.username_pw_set(MQTT_CONTROL_CONFIG['auth'].get('username'),MQTT_CONTROL_CONFIG['auth']['password']) + mqtt_client.username_pw_set(MQTT_CONTROL_CONFIG['auth'].get('username'), + MQTT_CONTROL_CONFIG['auth']['password']) mqtt_client.connect(MQTT_CONTROL_CONFIG['hostname']) trials = trials_max broker_connected = True except: print('trying again...') time.sleep(2) - trials+=1 + trials += 1 if broker_connected: print('Subscribing to topic', MQTT_CONTROL_CONFIG['ctrl_topic']) mqtt_client.subscribe(MQTT_CONTROL_CONFIG['ctrl_topic'], MQTT_CONTROL_CONFIG['qos']) @@ -45,7 +48,7 @@ if broker_connected: socket.connect(f'tcp://localhost:{CONTROL_CONFIG["tcp_port"]}') while True: - time.sleep(.1) + time.sleep(.1) else: print("Unable to connect to broker") exit(1) diff --git a/ohmpi.py b/ohmpi.py index 82930952..4905f1c9 100644 --- a/ohmpi.py +++ b/ohmpi.py @@ -745,7 +745,7 @@ class OhmPi(object): # measure all quadrupole of the sequence for i in range(0, self.sequence.shape[0]): quad = self.sequence[i, :] # quadrupole - if self.run is False: + if self.status == 'stopping': break # call the switch_mux function to switch to the right electrodes -- GitLab