Commit 335bc31d authored by Olivier Kaufmann's avatar Olivier Kaufmann
Browse files

Fixes bug due to a remainig self.run in ohmpi

Showing with 7 additions and 4 deletions
+7 -4
...@@ -6,6 +6,7 @@ import zmq ...@@ -6,6 +6,7 @@ import zmq
ctrl_queue = Queue() ctrl_queue = Queue()
def on_message(client, userdata, message): def on_message(client, userdata, message):
global socket global socket
...@@ -17,6 +18,7 @@ def on_message(client, userdata, message): ...@@ -17,6 +18,7 @@ def on_message(client, userdata, message):
reply = socket.recv() reply = socket.recv()
print(f'Received reply {message.payload.decode("utf-8")}: {reply}') 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 mqtt_client = mqtt.Client(f'ohmpi_{OHMPI_CONFIG["id"]}_listener', clean_session=False) # create new instance
print('connecting command listener to broker') print('connecting command listener to broker')
trials = 0 trials = 0
...@@ -24,14 +26,15 @@ trials_max = 10 ...@@ -24,14 +26,15 @@ trials_max = 10
broker_connected = False broker_connected = False
while trials < trials_max: while trials < trials_max:
try: 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']) mqtt_client.connect(MQTT_CONTROL_CONFIG['hostname'])
trials = trials_max trials = trials_max
broker_connected = True broker_connected = True
except: except:
print('trying again...') print('trying again...')
time.sleep(2) time.sleep(2)
trials+=1 trials += 1
if broker_connected: if broker_connected:
print('Subscribing to topic', MQTT_CONTROL_CONFIG['ctrl_topic']) print('Subscribing to topic', MQTT_CONTROL_CONFIG['ctrl_topic'])
mqtt_client.subscribe(MQTT_CONTROL_CONFIG['ctrl_topic'], MQTT_CONTROL_CONFIG['qos']) mqtt_client.subscribe(MQTT_CONTROL_CONFIG['ctrl_topic'], MQTT_CONTROL_CONFIG['qos'])
...@@ -45,7 +48,7 @@ if broker_connected: ...@@ -45,7 +48,7 @@ if broker_connected:
socket.connect(f'tcp://localhost:{CONTROL_CONFIG["tcp_port"]}') socket.connect(f'tcp://localhost:{CONTROL_CONFIG["tcp_port"]}')
while True: while True:
time.sleep(.1) time.sleep(.1)
else: else:
print("Unable to connect to broker") print("Unable to connect to broker")
exit(1) exit(1)
...@@ -745,7 +745,7 @@ class OhmPi(object): ...@@ -745,7 +745,7 @@ class OhmPi(object):
# measure all quadrupole of the sequence # measure all quadrupole of the sequence
for i in range(0, self.sequence.shape[0]): for i in range(0, self.sequence.shape[0]):
quad = self.sequence[i, :] # quadrupole quad = self.sequence[i, :] # quadrupole
if self.run is False: if self.status == 'stopping':
break break
# call the switch_mux function to switch to the right electrodes # call the switch_mux function to switch to the right electrodes
......
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