frappy_psi: Added support for changing the observation frequency & number of scans. Further, added an automatic dashboard load on file setup, and a template dashboard for the Scout device.
This commit is contained in:
@@ -57,8 +57,8 @@ class TNMR:
|
||||
filepath: specifies a path to the file tnt you want to use
|
||||
"""
|
||||
#first we check if an instance of TNMR is running an get it or create it
|
||||
print('Opening TNMR connection')
|
||||
if(NTNMR_inst is None):
|
||||
print('Opening new TNMR connection')
|
||||
self.reset_NTNMR_instance()
|
||||
else:
|
||||
self.NTNMR = NTNMR_inst
|
||||
@@ -72,10 +72,18 @@ class TNMR:
|
||||
|
||||
def reset_NTNMR_instance(self):
|
||||
try:
|
||||
pythoncom.CoInitialize()
|
||||
self.NTNMR = win32com.client.GetActiveObject("NTNMR.Application")
|
||||
except pythoncom.com_error:
|
||||
raise TNMRNotRunnningError
|
||||
|
||||
def get_instance(self):
|
||||
try:
|
||||
pythoncom.CoInitialize()
|
||||
return win32com.client.GetActiveObject("NTNMR.Application")
|
||||
except pythoncom.com_error:
|
||||
raise TNMRNotRunnningError
|
||||
|
||||
def execute_cmd(self, cmd):
|
||||
print('W: Executing arbitrary command: ' + f'out = self.NTNMR.{cmd}')
|
||||
out = 0
|
||||
@@ -119,14 +127,15 @@ class TNMR:
|
||||
# for some reason CheckAcquisition is False while an experiment is
|
||||
# running but true otherwise
|
||||
print('Zero-going...')
|
||||
if self.NTNMR.CheckAcquisition == True:
|
||||
self.NTNMR.ZG
|
||||
ntnmr = self.get_instance()
|
||||
if not(self.acquisition_running()):
|
||||
ntnmr.ZG
|
||||
else:
|
||||
print('An Acquisition is already running')
|
||||
|
||||
if lock:
|
||||
print("Application locked during acquisition\n...waiting...")
|
||||
while self.NTNMR.CheckAcquisition == False:
|
||||
while self.acquisition_running():
|
||||
time.sleep(interval)
|
||||
print("Acquisition done")
|
||||
|
||||
@@ -138,10 +147,16 @@ class TNMR:
|
||||
True: if running
|
||||
False: if not running
|
||||
"""
|
||||
return not(self.NTNMR.CheckAcquisition)
|
||||
#try:
|
||||
ntnmr = self.get_instance()
|
||||
res = not(ntnmr.CheckAcquisition)
|
||||
#except AttributeError as e:
|
||||
# if(e
|
||||
# res = False
|
||||
return res
|
||||
|
||||
def get_data(self):
|
||||
raw_data = self.NTNMR.GetData
|
||||
raw_data = self.get_instance().GetData
|
||||
reals = raw_data[::2]
|
||||
imags = raw_data[1::2]
|
||||
|
||||
@@ -170,9 +185,9 @@ class TNMR:
|
||||
"""
|
||||
print('I: Saving')
|
||||
if filepath == '':
|
||||
self.NTNMR.Save
|
||||
self.get_instance().Save
|
||||
else:
|
||||
self.NTNMR.SaveAs(filepath)
|
||||
self.get_instance().SaveAs(filepath)
|
||||
print(f'I: Saved to file {filepath}')
|
||||
|
||||
def set_nmrparameter(self, param_name: str, value: str):
|
||||
@@ -189,7 +204,7 @@ class TNMR:
|
||||
False: otherwise.
|
||||
"""
|
||||
if(self.is_nmrparameter(param_name)):
|
||||
self.NTNMR.SetNMRParameter(param_name, value)
|
||||
self.get_instance().SetNMRParameter(param_name, value)
|
||||
print(f'I: Setting parameter {param_name} to value of {value}')
|
||||
return True
|
||||
print(f'W: Failed to set parameter {param_name} to {value}')
|
||||
@@ -208,10 +223,11 @@ class TNMR:
|
||||
None: Else
|
||||
"""
|
||||
try:
|
||||
return self.NTNMR.GetNMRParameter(param_name)
|
||||
except:
|
||||
return self.get_instance().GetNMRParameter(param_name)
|
||||
except Exception as e:
|
||||
print(str(e), repr(e))
|
||||
print('not a param. try one of:', self.get_page_parameters('Sequence'))
|
||||
return None
|
||||
return NoneW
|
||||
|
||||
def is_nmrparameter(self, param_name: str):
|
||||
"""Checks that a given parameter actually exists in the setup.
|
||||
@@ -226,8 +242,11 @@ class TNMR:
|
||||
False: otherwise.
|
||||
"""
|
||||
try:
|
||||
self.NTNMR.GetNMRParameter(param_name)
|
||||
self.get_instance().GetNMRParameter(param_name)
|
||||
return True
|
||||
except AttributeError:
|
||||
self.reset_NTNMR_instance()
|
||||
return self.is_nmrparameter(param_name)
|
||||
except:
|
||||
return False
|
||||
|
||||
@@ -239,7 +258,7 @@ class TNMR:
|
||||
A dictionary of all parameters, in form { [page name]: { [parameter name]: [parameter value], ... }, ... }
|
||||
"""
|
||||
full_dict = {}
|
||||
pages = self.NTNMR.GetParameterPageList.split(",")
|
||||
pages = self.get_instance().GetParameterPageList.split(",")
|
||||
for p in pages:
|
||||
p = p.strip()
|
||||
sub_dict = self.get_page_parameters(p)
|
||||
@@ -255,7 +274,7 @@ class TNMR:
|
||||
a dictionary of the sequence parameters.
|
||||
"""
|
||||
sub_dict = { }
|
||||
params_raw = self.NTNMR.GetParameterListInPage(page)
|
||||
params_raw = self.get_instance().GetParameterListInPage(page)
|
||||
params = params_raw[params_raw.find('=')+1:].split(",")
|
||||
for param in params:
|
||||
param_stripped = param.strip()
|
||||
@@ -288,25 +307,28 @@ class TNMR:
|
||||
False: if otherwise. (TODO: Exceptions-based rather than this)
|
||||
"""
|
||||
|
||||
ntnmr = self.get_instance()
|
||||
print(f'Loading sequence at {filename}')
|
||||
self.NTNMR.CloseActiveFile
|
||||
success = self.NTNMR.OpenFile(TEMPLATE_FILE_PATH + 'tmp.tnt')
|
||||
ntnmr.CloseActiveFile
|
||||
success = ntnmr.OpenFile(TEMPLATE_FILE_PATH + 'tmp.tnt')
|
||||
if(success):
|
||||
print('Template file reloaded')
|
||||
else:
|
||||
print(f'Failed to load template file. Please ensure that there exists an empty .tnt file named {TEMPLATE_FILE_PATH}/tmp.tnt (Close, New, Save As...)')
|
||||
return False
|
||||
self.set_activefile()
|
||||
|
||||
self.load_dashboard(TEMPLATE_FILE_PATH + 'scout_dashboard.txt')
|
||||
|
||||
success = self.NTNMR.LoadSequence(filename if filename[-4:]=='.tps' else (filename+'.tps'))
|
||||
success = ntnmr.LoadSequence(filename if filename[-4:]=='.tps' else (filename+'.tps'))
|
||||
if(success):
|
||||
print(f'Successfully loaded sequence')
|
||||
else:
|
||||
print('Failed to load sequence')
|
||||
return False
|
||||
|
||||
self.NTNMR.SaveAs(TEMPLATE_FILE_PATH + 'tmper.tnt') # even more temporary
|
||||
success = self.NTNMR.OpenFile(TEMPLATE_FILE_PATH + 'tmper.tnt') # reload the file so that we can actually read/write to the Sequence parameters (TNMR bug)
|
||||
ntnmr.SaveAs(TEMPLATE_FILE_PATH + 'tmper.tnt') # even more temporary
|
||||
success = ntnmr.OpenFile(TEMPLATE_FILE_PATH + 'tmper.tnt') # reload the file so that we can actually read/write to the Sequence parameters (TNMR bug)
|
||||
self.set_activefile()
|
||||
|
||||
if(success):
|
||||
@@ -321,7 +343,7 @@ class TNMR:
|
||||
def load_dashboard(self, dashboard_fn):
|
||||
print(f'I: Loading dashboard setup from {dashboard_fn}')
|
||||
|
||||
success = self.NTNMR.LoadParameterSetupFromFile(dashboard_fn)
|
||||
success = self.get_instance().LoadParameterSetupFromFile(dashboard_fn)
|
||||
if(success):
|
||||
print(f'I: Successfully loaded dashboard')
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user