diff --git a/TimeBaseAOMDriver/blacs_workers.py b/TimeBaseAOMDriver/blacs_workers.py index f66f228417c043ef5f776297d8a6b48f9ad00538..66e4984dec0765a7a2b3ccc01685b97526ef594e 100644 --- a/TimeBaseAOMDriver/blacs_workers.py +++ b/TimeBaseAOMDriver/blacs_workers.py @@ -27,7 +27,15 @@ class TimeBaseWorker(Worker): break print(self.client.recv(200).decode()) self.smart_cache = {channel:{} for channel in self.channels} - self.remote_values = {channel:{} for channel in self.channels} + + def front_panel_from_smart_cache(self): + # Helper function to return only needed parameters to GUI, and convert ampl to dBm + front_panel = {ch : { + "gate" : int(self.smart_cache[ch]["Sout"]), + "freq" : int(self.smart_cache[ch]["Sfreq"]), + "amp" : 0.1*int(self.smart_cache[ch]["Sampl"]), + } for ch in self.channels} + return front_panel def transition_to_buffered(self, device_name, h5file, initial_values, fresh): with h5py.File(h5file,"r") as file: @@ -37,7 +45,7 @@ class TimeBaseWorker(Worker): for attr,value in group[channel].attrs.items(): if self.smart_cache[channel].get(attr) != group[channel].attrs[attr] or fresh: any_changed = True - print(f"Programming {channel}, {attr}") + print(f"Programming {channel}, {attr}={value}") self.client.send(f"{channel}|{attr}:{value:.0f}\r\n".encode()) self.smart_cache[channel][attr] = group[channel].attrs[attr] time.sleep(0.01) # TODO: What's the best time here? Do we need to wait at all? According to the DIM-3000 manual the rate is 10 commands per second, it seems router can also handle faster times? @@ -53,10 +61,8 @@ class TimeBaseWorker(Worker): if not initial_values[channel]["gate"]: print(f"Programming {channel}, Sout") self.client.send(f"{channel}|Sout:1\r\n".encode()) - initial_values[channel]["gate"] = True - initial_values[channel]["freq"] = group[channel].attrs["Sfreq"] - initial_values[channel]["amp"] = group[channel].attrs["Sampl"] * 0.1 - return initial_values + self.smart_cache[channel]["Sout"] = 1 + return self.front_panel_from_smart_cache() def abort_transition_to_buffered(self): return True @@ -80,11 +86,9 @@ class TimeBaseWorker(Worker): time.sleep(0.2) try: Gpar = self.client.recv(1000).decode() # Rfreq:xxx|Rampl:xxx|Rout:xxx|... + Gpar = Gpar.split("\n")[-2] # The ADRV-5 also sends Rpcbtemp messages without asking for it. Split off those from the response. # Create parameter dictionary from message string par = dict(map(lambda str:str.split(":"),Gpar.split("|")[:-1])) - self.remote_values[ch]["freq"] = int(par["Rfreq"]) - self.remote_values[ch]["amp"] = 0.1 * int(par["Rampl"]) - self.remote_values[ch]["gate"] = int(par["Rout"]) # Update values in smart cache for name,value in par.items(): self.smart_cache[ch][f"S{name[1:]}"] = int(value) @@ -99,19 +103,19 @@ class TimeBaseWorker(Worker): # except socket.timeout: # pass # Nothing was in the TCP server's buffer to send self.logger.debug(f"Checked remote values ({time.perf_counter()-start:.2f}s)") - return self.remote_values + return self.front_panel_from_smart_cache() def program_manual(self,values): for channel,dds in values.items(): - if dds["freq"] != self.remote_values[channel]["freq"]: + if dds["freq"] != self.smart_cache[channel]["Sfreq"]: self.client.send(f"{channel}|Sfreq:{dds['freq']}\r\n".encode()) - self.remote_values[channel]["freq"] = dds["freq"] - if dds["amp"] != self.remote_values[channel]["amp"]: + self.smart_cache[channel]["Sfreq"] = dds["freq"] + if 10*dds["amp"] != self.smart_cache[channel]["Sampl"]: self.client.send(f"{channel}|Sampl:{10*dds['amp']}\r\n".encode()) - self.remote_values[channel]["amp"] = dds["amp"] - if dds["gate"] != self.remote_values[channel]["gate"]: + self.smart_cache[channel]["Sampl"] = 10*dds["amp"] + if dds["gate"] != self.smart_cache[channel]["Sout"]: self.client.send(f"{channel}|Sout:{int(dds['gate'])}\r\n".encode()) - self.remote_values[channel]["gate"] = dds["gate"] + self.smart_cache[channel]["Sout"] = dds["gate"] def shutdown(self): # for i in range(1,self.num_AOM+1):