def loop_test(): try: print('test pulse started') while (not event.is_set()): lzamp.test_pulse(0.1) print('test pulse stopped') except: error.set() print('ERROR: test loop failure')
def loop_heartbeat(): try: print('SC heartbeat started') while (not event.is_set()): lzamp.heartbeat_pulse(2) print('SC heartbeat stopped') except: error.set() print('ERROR: heartbeat failure')
def loop_heartbeat(): try: while (not end_log.is_set()): lzamp.heartbeat_pulse(2) except (KeyboardInterrupt, SystemExit): raise except Exception: exception_traceback_log.exception('The following error occurred:') pass
def crate_enabler(): try: if (not crate_disable.is_set()) & (not power.is_set()): lzamp.power_on() power.set() except (KeyboardInterrupt, SystemExit): raise except Exception: exception_traceback_log.exception('The following error occurred:') pass
def channel_enabler(slot, ch): try: if (not globals()['board_%s_ch_%s_disable' % (slot, ch)].is_set()) & (get_channel_status( slot, ch) == 0): lzamp.set_channel_enable(slot, ch, 1) except (KeyboardInterrupt, SystemExit): raise except Exception: exception_traceback_log.exception('The following error occurred:') pass
def insert_board(slot_num): try: pos = lzamp.switch_pos(slot_num) serNum = input( ("Insert Board in slot # {:d}, with swith in position " + pos + "\nOnce inserted, enter serial number: ").format(slot_num)) tmp = lzamp.set_serNum(slot_num, serNum) sleep(1) tmp = lzamp.get_serNum(slot_num) if tmp == serNum: return (serNum) else: return (-1) except: return (-2)
def loop_AMP_heartbeat(): try: print('amp heartbeat started') while (not event.is_set()): lzamp.set_AMP_alert_on(1) sleep(0.1) lzamp.set_AMP_alert_on(2) sleep(0.1) lzamp.set_AMP_alert_on(3) sleep(0.1) lzamp.set_AMP_alert_on(4) sleep(0.1) lzamp.set_AMP_alert_off(1) sleep(0.1) lzamp.set_AMP_alert_off(2) sleep(0.1) lzamp.set_AMP_alert_off(3) sleep(0.1) lzamp.set_AMP_alert_off(4) sleep(0.5) print('amp heartbeat stopped') except: error.set() print('ERROR: amp heartbeat failure')
def check_input_yn(question): tmp = 'n' while not tmp == 'y': tmp = raw_input((question)) if tmp == 'n': return (True) elif not tmp == 'y': print('try again') return (False) if __name__ == '__main__': event = Event() complete = Event() error = Event() lzamp.setup() lzamp.power_off() lzamp.test_on() # tester='JB' # date='12/15/2019' # tstart='0000' # serNums=[605,608,607,606] tester = raw_input('Enter name of tester: ') date = raw_input('Enter date: (MM/DD/YYYY) ') tstart = raw_input( 'Enter start time in 24-hour format: (1:17 pm would be 1317) ') serNums = [0, 0, 0, 0] for slot in range(1, 5):
def get_channel_enabled_count(): tmp = 0 for ii in range(4): tmp += sum(lzamp.get_channels_enable(ii + 1)) return tmp
def get_channel_status(slot, ch): tmp = lzamp.get_channels_enable(slot)[ch - 1] return tmp
def set_board_enable(slot, en): for ch in range(8): lzamp.set_channel_enable(slot, ch + 1, en)
def loop_data_logging(serNums): global c_pos_voltage, c_neg_voltage, c_pos_current, c_neg_current, c_air_flow, c_af_temp, c_SC_temp global c_AMP_temps c_AMP_temps = zeros((4, 4)) global c_DC_offsets c_DC_offsets = zeros((4, 8)) log_dir = '/home/debian/LZAMP/daily_logs/' try: write_str = '{:.4g}, ' while (not end_log.is_set()): sleep(20) fname = 'data_{:d}_{:d}_{:d}_{:d}_' + c_date + '.csv' fname = fname.format(*serNums) if not isfile(log_dir + fname): print('\ncreating data log file\n') with open(log_dir + fname, 'w+') as f: f.write( "time (s), air flow (mm/s), af temp, SC temp, B1T1, B1T2, B1T3, " + "B1T4, B2T1, B2T2, B2T3, B2T4, B3T1, B3T2, B3T3, B3T4, B4T1, B4T2, B4T3, B4T4, " + "B1DC1, B1DC2, B1DC3, B1DC4, B1DC5, B1DC6, B1DC7, B1DC8, " + "B2DC1, B2DC2, B2DC3, B2DC4, B2DC5, B2DC6, B2DC7, B2DC8, " + "B3DC1, B3DC2, B3DC3, B3DC4, B3DC5, B3DC6, B3DC7, B3DC8, " + "B4DC1, B4DC2, B4DC3, B4DC4, B4DC5, B4DC6, B4DC7, B4DC8, " + "I+ (A), I- (A), V+, V-, NumChEnabled,\n") print('\ndata currently logging to: ' + log_dir + fname + '\n') with open(log_dir + fname, 'a+') as f: c_time = localtime() seconds_since_midnight = int(c_time.tm_hour * 3600 + c_time.tm_min * 60 + c_time.tm_sec) f.write(write_str.format(seconds_since_midnight)) sleep(0.1) c_air_flow = lzamp.get_airflow() c_af_temp = lzamp.get_airflow_temp() f.write(write_str.format(c_air_flow)) f.write(write_str.format(c_af_temp)) sleep(0.1) c_SC_temp = lzamp.get_temp() f.write(write_str.format(c_SC_temp)) sleep(0.1) for ii in range(4): for jj in range(4): c_AMP_temps[ii][jj] = lzamp.get_AMP_temp( ii + 1, jj + 1) f.write(write_str.format(c_AMP_temps[ii][jj])) sleep(0.1) for ii in range(4): for jj in range(8): c_DC_offsets[ii][jj] = lzamp.get_channel_offset( ii + 1, jj + 1) f.write(write_str.format(c_DC_offsets[ii][jj])) sleep(0.1) c_pos_current = lzamp.get_current_pos() c_neg_current = lzamp.get_current_neg() f.write(write_str.format(c_pos_current)) f.write(write_str.format(c_neg_current)) sleep(0.1) c_pos_voltage = lzamp.get_voltage_pos() c_neg_voltage = lzamp.get_voltage_neg() f.write(write_str.format(c_pos_voltage)) f.write(write_str.format(c_neg_voltage)) sleep(0.1) f.write(write_str.format(c_channels_enabled)) f.write('\n') print('\ndata logging ended\n') except (KeyboardInterrupt, SystemExit): raise except Exception: exception_traceback_log.exception('The following error occurred:') pass
for ii in range(4): globals()['board_%s_disable' % str(ii + 1)] = Event() for jj in range(8): globals()['board_%s_ch_%s_disable' % (ii + 1, jj + 1)] = Event() crate_disable = Event() power = Event() end_log = Event() error = Event() crate_lock = Lock() channel_lock = Lock() board_lock = Lock() lzamp.setup() lzamp.power_off() lzamp.test_on() serNums = [0, 0, 0, 0] for slot in range(1, 5): tmp = lzamp.get_serNum(slot) serNums[slot - 1] = tmp air_flow_min = 300 low_thresh_SC_temp = 30 mid_thresh_SC_temp = 35 high_thresh_SC_temp = 40 low_thresh_AMP_temp = 40
def loop_get_data(t0, serNums, tester, date, tstart): try: fname = 'data_{:d}_{:d}_{:d}_{:d}.csv'.format(*serNums) print('data logging started under file name: ' + fname) with open(fname, 'w+') as f: f.write( ("Burn in test for boards {:d}, {:d}, {:d}, {:d}. Tested by " + tester + " beginning on " + date + " at " + tstart + "\n\n").format(*serNums)) f.write( "PASSED power cycle test\nPASSED channel enable/disable test.\n" ) for slot in range(1, 5): for ch in range(1, 9): tmp = lzamp.get_channel_offset(slot, ch)**2 if tmp > 1: print('ERROR: bad offset') error.set() f.write("PASSED pre-burn in offset test test\n") f.write( "time (s), air flow (mm/s), af temp, SC temp, B1T1, B1T2, B1T3, " + "B1T4, B2T1, B2T2, B2T3, B2T4, B3T1, B3T2, B3T3, B3T4, B4T1, B4T2, B4T3, B4T4, I+ (A), I- (A), V+, V-,\n" ) write_str = '{:.4g}, ' nn = 0 while ((time() - t0) < (3600 * 24)) & (not event.is_set()): with open(fname, 'a+') as f: f.write(write_str.format(time() - t0)) af = lzamp.get_airflow() if (af < 300): nn += 1 else: nn = 0 if nn > 5: error.set() print('Low Airflow') f.write(write_str.format(af)) f.write(write_str.format(lzamp.get_airflow_temp())) t = lzamp.get_temp() if t > 40: error.set() print('SC Overheated') f.write(write_str.format(t)) for ii in range(4): for jj in range(4): t = lzamp.get_AMP_temp(ii + 1, jj + 1) if t > 50: error.set() print('AMP Overheated') f.write(write_str.format(t)) val = lzamp.get_current_pos() if (val < 2.0) | (val > 3.0): error.set() print("+ Current out of range") f.write(write_str.format(val)) val = lzamp.get_current_neg() if (val < 2.0) | (val > 3.0): error.set() print("- Current out of range") f.write(write_str.format(val)) val = lzamp.get_voltage_pos() if (val < 6) | (val > 10): error.set() print("+ Voltage out of range") f.write(write_str.format(val)) val = lzamp.get_voltage_neg() if (val < 6) | (val > 10): error.set() print("- Voltage out of range") f.write(write_str.format(val)) f.write('\n') if error.is_set(): break sleep(60) for slot in range(1, 5): for ch in range(1, 9): tmp = lzamp.get_channel_offset(slot, ch)**2 if tmp > 1: print('ERROR: bad offset') error.set() with open(fname, 'r') as f: contents = f.readlines() contents.insert(5, "PASSED Burn in test\n\n") contents.insert(5, "PASSED post-burn in offset test test\n") contents = "".join(contents) with open(fname, 'w') as f: f.write(contents) complete.set() print('\ndata logging stopped') except: print('data logging failed') error.set()
def get_board_status(slot): tmp = lzamp.get_channels_enable(slot) if sum(tmp) != 0: return 1 else: return 0
tmp = 'n' while not tmp == 'y': tmp = raw_input((question)) if tmp == 'n': return (True) elif not tmp == 'y': print('try again') return (False) if __name__ == '__main__': event = Event() complete = Event() error = Event() lzamp.setup() lzamp.power_off() lzamp.test_on() if check_input_yn( '\nHas last two digits of serial number been hand-written on the control board? (y/n) ' ): print('fatal error, exiting.') exit() try: tester = raw_input('Enter name of tester: ') date = raw_input('Enter date: (MM/DD/YYYY) ') tstart = raw_input( 'Enter start time in 24-hour format: (1:17 pm would be 1317) ') temperature = float(