Avoided setup-dependent error (file structuring). Implemented TNMR application search and re-open if it closes. This will not fix any particularly odd situations, but it will recover the majority of TNMR crashes and user error.

This commit is contained in:
2025-08-15 11:15:10 +02:00
parent bee3f5615a
commit 558bbfded9
4 changed files with 18 additions and 2 deletions

View File

@@ -309,7 +309,8 @@ class ProgrammedSequence(fc.Drivable): # Drivable only for kill() funcitonality
self.approx_sequence_length += float(self.post_acquisition_time)*1e-6
# then, save the thing
filepath = os.getcwd()
# save it in a reasonable location, within frappy
filepath = os.path.dirname(os.path.realpath(__file__))
filename = self.title + f'_{time.time()}'
filename = filepath + '/sequences/' + filename.replace('.','')
seq_gen.save_sequence(filename, seq)

View File

@@ -211,7 +211,7 @@ def get_event_header(event_type, vals, tables, table_reg, tuning_number, col_del
if(len(codes) == 6): # regular header
headerstr += f'{tuning_number}{Z*3}{codes[0]}1{codes[1]}{codes[2]}'
headerstr += f'{codes[5]}{Z*3}{codes[3]}{codes[4]}{Z*2}\x01'
elif(len(codes) == 4): # exteension
elif(len(codes) == 4): # extension
headerstr += f'{tuning_number}{Z*3}{codes[0]}{Z*3}{codes[1]}{Z*3}{codes[2]}{Z*3}{codes[3]}'
else:
print('PANIC')

View File

View File

@@ -17,6 +17,8 @@ import win32com.client
import pythoncom
import frappy_psi.tnmr.NTNMR as NTNMR
import winapps
import time
import json
import traceback
@@ -102,8 +104,21 @@ class TNMR:
pythoncom.CoInitialize()
return win32com.client.GetActiveObject("NTNMR.Application")
except pythoncom.com_error:
try:
self.open_TNMR()
time.sleep(10)
# try again
pythoncom.CoInitialize()
return win32com.client.GetActiveObject("NTNMR.Application")
except:
raise TNMRNotRunnningError
raise TNMRNotRunnningError
def open_TNMR(self):
'''Tries to open up TNMR, using its registration in the Windows registry'''
for app in winapps.search_installed('TNMR'):
os.system('start ' + str(app.install_location.absolute()) + '\\bin\\TNMR.exe')
def execute_cmd(self, cmd):
'''Sends an arbitrary command through to TNMR'''
print('W: Executing arbitrary command: ' + f'out = self.get_instance().{cmd}')