async def handle(self, msg, type=None): # print(f'%%%%%Instrument.handle: {msg.to_json()}') # handle messages from multiple sources. What ID to use? if (type == 'FromChild' and msg.type == Interface.class_type): id = msg.sender_id dt = self.parse(msg) print(f'dt = {dt}') # print(f'last_entry: {self.last_entry}') # if ( # 'DATETIME' in self.last_entry and # self.last_entry['DATETIME'] == entry['DATA']['DATETIME'] # ): # print(f'88888888888 skipped entry') # return # self.last_entry['DATETIME'] = entry['DATA']['DATETIME'] # print('entry = \n{}'.format(entry)) # TODO: how to deal with record that crosses second bound? if self.current_read_cnt == len(self.current_poll_cmds): # entry['METADATA'] = self.get_metadata() entry = self.get_data_entry(dt, add_meta=False) # print(f'entry: {entry}') data = Message( sender_id=self.get_id(), msgtype=Instrument.class_type, ) # send data to next step(s) # to controller # data.update(subject='DATA', body=entry['DATA']) data.update(subject='DATA', body=entry) # reset read count self.current_read_cnt = 0 # await self.msg_buffer.put(data) # await self.to_parent_buf.put(data) # print(f'instrument data: {data.to_json()}') # await asyncio.sleep(.1) await self.message_to_ui(data) # await PlotManager.update_data(self.plot_name, data.to_json()) # print(f'data_json: {data.to_json()}\n') # await asyncio.sleep(0.01) elif type == 'FromUI': if msg.subject == 'STATUS' and msg.body['purpose'] == 'REQUEST': print(f'msg: {msg.body}') self.send_status() elif msg.subject == 'CONTROLS' and msg.body['purpose'] == 'REQUEST': print(f'msg: {msg.body}') await self.set_control(msg.body['control'], msg.body['value']) elif msg.subject == 'RUNCONTROLS' and msg.body[ 'purpose'] == 'REQUEST': print(f'msg: {msg.body}') await self.handle_control_action(msg.body['control'], msg.body['value'])
async def handle(self, msg, type=None): # print(f'%%%%%Instrument.handle: {msg.to_json()}') # handle messages from multiple sources. What ID to use? if (type == 'FromChild' and msg.type == Interface.class_type): # print(f'aps scan: {msg.to_json()}') # id = msg.sender_id dt = self.parse(msg) if dt: entry = self.get_data_entry(dt) # print(f'entry: {entry}') data = Message( sender_id=self.get_id(), msgtype=Instrument.class_type, ) # send data to next step(s) # to controller data.update(subject='DATA', body=entry) # send data to user interface await self.message_to_ui(data) # send data to controller await self.to_parent_buf.put(data) # save data if self.datafile: await self.datafile.write_message(data) # print(f'data_json: {data.to_json()}\n') # await asyncio.sleep(0.01) # elif type == 'FromUI': # if msg.subject == 'STATUS' and msg.body['purpose'] == 'REQUEST': # # print(f'msg: {msg.body}') # self.send_status() # elif ( # msg.subject == 'CONTROLS' and # msg.body['purpose'] == 'REQUEST' # ): # # print(f'msg: {msg.body}') # await self.set_control(msg.body['control'], msg.body['value']) # elif ( # msg.subject == 'RUNCONTROLS' and # msg.body['purpose'] == 'REQUEST' # ): # # print(f'msg: {msg.body}') # await self.handle_control_action( # msg.body['control'], msg.body['value'] # ) await super().handle(msg, type)
async def handle(self, msg, type=None): # print(f'%%%%%Instrument.handle: {msg.to_json()}') # handle messages from multiple sources. What ID to use? if type == "FromChild" and msg.type == Instrument.class_type: # id = msg.sender_id # entry = self.parse(msg) # self.last_entry = entry # print('entry = \n{}'.format(entry)) entry = self.calculate_data(msg) if entry: data = Message( sender_id=self.get_id(), msgtype=Controller.class_type, ) # send data to next step(s) # to controller # data.update(subject='DATA', body=entry['DATA']) data.update(subject="DATA", body=entry) # print(f'instrument data: {data.to_json()}') await self.message_to_ui(data) if self.datafile: await self.datafile.write_message(data) # await asyncio.sleep(.1) # await PlotManager.update_data(self.plot_name, data.to_json()) # print(f'data_json: {data.to_json()}\n') # elif type == "FromUI": # if msg.subject == "STATUS" and msg.body["purpose"] == "REQUEST": # # print(f"msg: {msg.body}") # self.send_status() # elif msg.subject == "CONTROLS" and msg.body["purpose"] == "REQUEST": # # print(f"msg: {msg.body}") # await self.set_control(msg.body["control"], msg.body["value"]) # elif msg.subject == "RUNCONTROLS" and msg.body["purpose"] == "REQUEST": # # print(f"msg: {msg.body}") # await self.handle_control_action(msg.body["control"], msg.body["value"]) # # await self.set_control(msg.body['control'], msg.body['value']) # elif msg.subject == "REGISTRATION": # print(f"reg: {msg.subject}") # if msg.body["purpose"] == "SUCCESS": # self.registration_key = msg.body["regkey"] # # if content["BODY"]["config"]: # # self.config = content["BODY"]["config"] # # self.save_current_config(json.loads(content["BODY"]["config"])) # self.status2.set_registration_status(Status.REGISTERED) # # if content["BODY"]["ui_reconfig_request"]: # # await self.resend_config_to_ui() await super().handle(msg, type)
async def handle(self, msg, type=None): # print(f'%%%%%Instrument.handle: {msg.to_json()}') # handle messages from multiple sources. What ID to use? if (type == 'FromChild' and msg.type == Interface.class_type): id = msg.sender_id entry = self.parse(msg) # print(f'last_entry: {self.last_entry}') # if ( # 'DATETIME' in self.last_entry and # self.last_entry['DATETIME'] == entry['DATA']['DATETIME'] # ): # print(f'88888888888 skipped entry') # return # self.last_entry['DATETIME'] = entry['DATA']['DATETIME'] # print('entry = \n{}'.format(entry)) data = Message( sender_id=self.get_id(), msgtype=Instrument.class_type, ) # send data to next step(s) # to controller # data.update(subject='DATA', body=entry['DATA']) data.update(subject='DATA', body=entry) # await self.msg_buffer.put(data) # await self.to_parent_buf.put(data) # print(f'instrument data: {data.to_json()}') await self.message_to_ui(data) # await PlotManager.update_data(self.plot_name, data.to_json()) # print(f'data_json: {data.to_json()}\n') # await asyncio.sleep(0.01) elif type == 'FromUI': if msg.subject == 'STATUS' and msg.body['purpose'] == 'REQUEST': print(f'msg: {msg.body}') self.send_status() elif msg.subject == 'CONTROLS' and msg.body['purpose'] == 'REQUEST': print(f'msg: {msg.body}') await self.set_control(msg.body['control'], msg.body['value']) elif msg.subject == 'RUNCONTROLS' and msg.body[ 'purpose'] == 'REQUEST': print(f'msg: {msg.body}') await self.handle_control_action(msg.body['control'], msg.body['value'])
async def handle(self, msg, type=None): # print(f'%%%%% MAGIC210.handle: {msg.to_json()}') if type == "FromChild" and msg.type == Interface.class_type: dt = self.parse(msg) # print(f'dt = {dt}') if dt: entry = self.get_data_entry(dt) data = Message( sender_id=self.get_id(), msgtype=Instrument.class_type, ) data.update(subject="DATA", body=entry) await self.message_to_ui(data) await super().handle(msg, type)
async def handle(self, msg, type=None): # print(f'%%%%%Instrument.handle: {msg.to_json()}') # handle messages from multiple sources. What ID to use? if type == "FromChild" and msg.type == Instrument.class_type: # id = msg.sender_id # entry = self.parse(msg) # self.last_entry = entry # print('entry = \n{}'.format(entry)) entry = self.calculate_data(msg) if entry: data = Message( sender_id=self.get_id(), msgtype=Controller.class_type, ) # send data to next step(s) # to controller # data.update(subject='DATA', body=entry['DATA']) data.update(subject="DATA", body=entry) # print(f'instrument data: {data.to_json()}') await self.message_to_ui(data) if self.datafile: await self.datafile.write_message(data) # await PlotManager.update_data(self.plot_name, data.to_json()) # print(f'data_json: {data.to_json()}\n') elif type == "FromUI": if msg.subject == "STATUS" and msg.body["purpose"] == "REQUEST": print(f"msg: {msg.body}") self.send_status() elif msg.subject == "CONTROLS" and msg.body["purpose"] == "REQUEST": print(f"msg: {msg.body}") await self.set_control(msg.body["control"], msg.body["value"]) elif msg.subject == "RUNCONTROLS" and msg.body[ "purpose"] == "REQUEST": print(f"msg: {msg.body}") await self.handle_control_action(msg.body["control"], msg.body["value"])
async def handle(self, msg, type=None): # print(f'%%%%%Instrument.handle: {msg.to_json()}') # handle messages from multiple sources. What ID to use? if type == "FromChild" and msg.type == Interface.class_type: # id = msg.sender_id dt = self.parse(msg) if dt and self.poll_data_ready: for control, value in self.current_run_settings.items(): # try: # pl = self.controls[control]["parse_label"] # if pl in self.data_record_template: self.update_data_record(dt, {control: value}, value) # except KeyError: # pass entry = self.get_data_entry(dt) # print(f'entry: {entry}') data = Message( sender_id=self.get_id(), msgtype=Instrument.class_type, ) # send data to next step(s) # to controller # data.update(subject='DATA', body=entry['DATA']) data.update(subject="DATA", body=entry) # # reset read count # self.current_read_cnt = 0 # self.scan_first_found = False # self.scan_ready = False # await self.msg_buffer.put(data) # await self.to_parent_buf.put(data) # print(f'999999999999msems data: {data.to_json()}') # await asyncio.sleep(.1) await self.message_to_ui(data) await self.to_parent_buf.put(data) # await PlotManager.update_data(self.plot_name, data.to_json()) if self.datafile: await self.datafile.write_message(data) # elif self.msems_mode == "off": # # monitoring the data # # print(f"monitor: {dt}") # pass # print(f'data_json: {data.to_json()}\n') # await asyncio.sleep(0.01) # elif type == "FromUI": # if msg.subject == "STATUS" and msg.body["purpose"] == "REQUEST": # print(f"msg: {msg.body}") # self.send_status() # elif msg.subject == "CONTROLS" and msg.body["purpose"] == "REQUEST": # print(f"msg: {msg.body}") # await self.set_control(msg.body["control"], msg.body["value"]) # elif msg.subject == "RUNCONTROLS" and msg.body["purpose"] == "REQUEST": # print(f"msg: {msg.body}") # await self.handle_control_action(msg.body["control"], msg.body["value"]) await super().handle(msg, type)
async def handle(self, msg, type=None): # print(f'%%%%%Instrument.handle: {msg.to_json()}') # handle messages from multiple sources. What ID to use? if (type == 'FromChild' and msg.type == Interface.class_type): # print(f'aps scan: {msg.to_json()}') id = msg.sender_id dt = self.parse(msg) if self.scan_ready: # calc dp dp = [] for low, hi in zip(self.lower_dp_bnd, self.uppder_dp_bnd): dp.append(round(math.sqrt(low * hi), 4)) self.update_data_record( dt, {'diameter_um': dp}, ) # calc bin_conc conc = [] cnts = self.get_data_record_param(dt, 'bin_counts') flow = self.get_data_record_param(dt, 'sample_flow') if cnts and flow: for n in cnts: conc.append(round(n / flow, 4)) self.update_data_record( dt, {'bin_concentration': conc}, ) entry = self.get_data_entry(dt) # print(f'entry: {entry}') self.scan_ready = False data = Message( sender_id=self.get_id(), msgtype=Instrument.class_type, ) # send data to next step(s) # to controller # data.update(subject='DATA', body=entry['DATA']) data.update(subject='DATA', body=entry) # await self.msg_buffer.put(data) # await self.to_parent_buf.put(data) # print(f'999999999999msems data: {data.to_json()}') # await asyncio.sleep(.1) await self.message_to_ui(data) await self.to_parent_buf.put(data) # await PlotManager.update_data(self.plot_name, data.to_json()) if self.datafile: await self.datafile.write_message(data) # print(f'data_json: {data.to_json()}\n') # await asyncio.sleep(0.01) elif type == 'FromUI': if msg.subject == 'STATUS' and msg.body['purpose'] == 'REQUEST': # print(f'msg: {msg.body}') self.send_status() elif msg.subject == 'CONTROLS' and msg.body['purpose'] == 'REQUEST': # print(f'msg: {msg.body}') await self.set_control(msg.body['control'], msg.body['value']) elif msg.subject == 'RUNCONTROLS' and msg.body[ 'purpose'] == 'REQUEST': # print(f'msg: {msg.body}') await self.handle_control_action(msg.body['control'], msg.body['value'])