def resetTest(self): # Reset the error counters and restart if self.id: self.master.after_cancel(self.id) if self.activity_id: self.master.after_cancel(self.activity_id) #if self.pass_id: # self.master.after_cancel(self.pass_id) if self.csvfile: self.csvfile.close() self.csfvile = None self.board = None self.device_open = False self.voltages = [0.0]*mcc118.info().NUM_AI_CHANNELS self.failures = [0]*mcc118.info().NUM_AI_CHANNELS self.test_count = 0 self.software_errors = 0 self.baseline_set = False self.watchdog_count = 0 self.pass_led.set(1) self.inst_pass_led.set(0) self.ready_led.set(0)
def updateInputs(self): if self.device_open: for channel in range(mcc118.info().NUM_AI_CHANNELS): if self.check_values[channel].get() == 1: value = self.board.a_in_read(channel) self.voltages[channel].config(text="{:.3f}".format(value)) # schedule another update in 200 ms self.master.after(200, self.updateInputs)
def enable_controls(self): """ Enable controls when board opened """ # Disable the address selector self.device_lister.config(state=tkinter.DISABLED) # Enable the board controls for child in self.bottom_frame.winfo_children(): child.config(state=tkinter.NORMAL) # Reset the channels to enabled for index in range(mcc118.info().NUM_AI_CHANNELS): self.check_values[index].set(1)
def openCsvFile(self): if not os.path.isdir('./data'): # create the data directory os.mkdir('./data') filename = "./data/mcc118_test_" + datetime.datetime.now().strftime( "%d-%m-%Y_%H-%M-%S") + ".csv" self.csvfile = open(filename, 'w') mystr = ("Time," + ",".join("Ch {}".format(channel) for channel in range(mcc118.info().NUM_AI_CHANNELS)) + ",Status\n") self.csvfile.write(mystr)
def channelsChanged(self, _event): self.num_channels = int(self.chan_combo.get()) # enable/disable controls for index in range(0, self.num_channels): self.voltage_labels[index].configure(state=NORMAL) self.failure_labels[index].configure(state=NORMAL) for index in range(self.num_channels, mcc118.info().NUM_AI_CHANNELS): self.voltage_labels[index].configure(state=DISABLED) self.failure_labels[index].configure(state=DISABLED) # set new sample rate max rate_max = int(100000/self.num_channels) self.sample_rate_widget.configure(to=rate_max) if self.sample_rate.get() > rate_max: self.sample_rate.set(rate_max)
def updateDisplay(self): for channel in range(mcc118.info().NUM_AI_CHANNELS): self.voltage_labels[channel].config( text="{:.1f}".format(self.voltages[channel])) self.failure_labels[channel].config( text="{}".format(self.failures[channel])) if self.current_failures > 0: self.inst_pass_led.set(2) self.pass_led.set(2) else: self.inst_pass_led.set(1) #self.pass_id = self.master.after(500, self.passBlink) self.software_error_label.config( text="{}".format(self.software_errors)) self.test_count_label.config(text="{}".format(self.test_count))
def __init__(self, master): self.master = master master.title("MCC 118 Control Panel") # Initialize variables self.device_open = False self.open_address = 0 self.board = None # GUI Setup self.bold_font = tkinter.font.Font( family=tkinter.font.nametofont("TkDefaultFont")["family"], size=tkinter.font.nametofont("TkDefaultFont")["size"], weight="bold") # Create and organize frames self.top_frame = tkinter.LabelFrame(master, text="Select Device") self.top_frame.pack(side=tkinter.TOP, expand=False, fill=tkinter.X) self.bottom_frame = tkinter.LabelFrame(master, text="Analog Inputs") self.bottom_frame.pack(side=tkinter.BOTTOM, expand=True, fill=tkinter.BOTH) # Create widgets self.dev_label = tkinter.Label(self.top_frame, text="MCC 118 address:") self.dev_label.grid(row=0, column=0) self.open_button = tkinter.Button( self.top_frame, text="Open", width=6, command=self.pressed_open_button) # Get list of MCC 118 devices for the device list widget self.addr_list = self.list_devices() if not self.addr_list == 0: self.device_lister = tkinter.Label(self.top_frame, text="None found") self.open_button.config(state=tkinter.DISABLED) else: self.device_variable = tkinter.StringVar(self.top_frame) self.device_variable.set(self.addr_list[0]) self.device_lister = tkinter.OptionMenu( self.top_frame, self.device_variable, *self.addr_list) self.device_lister.grid(row=0, column=1) self.open_button.grid(row=0, column=2) self.checkboxes = [] self.check_values = [] self.channel_labels = [] self.voltages = [] for index in range(mcc118.info().NUM_AI_CHANNELS): # Checkboxes self.check_values.append(tkinter.IntVar()) self.checkboxes.append( tkinter.Checkbutton( self.bottom_frame, variable=self.check_values[index], command=lambda index=index: self.pressed_check(index))) self.checkboxes[index].grid(row=index, column=0) self.checkboxes[index].select() # Labels self.channel_labels.append(tkinter.Label( self.bottom_frame, text="Ch {}".format(index), font=self.bold_font)) self.channel_labels[index].grid(row=index, column=1) self.channel_labels[index].grid_configure(sticky="W") # Voltages self.voltages.append(tkinter.Label( self.bottom_frame, text="0.000", font=self.bold_font)) self.voltages[index].grid(row=index, column=2) self.voltages[index].grid_configure(sticky="E") self.bottom_frame.grid_rowconfigure(index, weight=1) self.bottom_frame.grid_columnconfigure(1, weight=1) self.bottom_frame.grid_columnconfigure(2, weight=1) self.bottom_frame.bind("<Configure>", self.resize_text) # Disable widgets until a device is opened self.disable_controls() master.protocol('WM_DELETE_WINDOW', self.close) # exit cleanup icon = tkinter.PhotoImage(file='/usr/share/mcc/daqhats/icon.png') # pylint: disable=protected-access master.tk.call('wm', 'iconphoto', master._w, icon)
def __init__(self, master): self.master = master master.title("MCC 118 CE Test") # Initialize variables self.device_open = False self.board = None self.voltage_limit = DEFAULT_V_LIMIT self.voltages = [0.0]*mcc118.info().NUM_AI_CHANNELS self.failures = [0]*mcc118.info().NUM_AI_CHANNELS self.test_count = 0 self.software_errors = 0 self.baseline_set = False self.watchdog_count = 0 self.csvfile = None self.id = None self.activity_id = None self.num_channels = mcc118.info().NUM_AI_CHANNELS self.scan_rate = SCAN_RATE self.scan_count = SCAN_SAMPLE_COUNT # GUI Setup # Device Frame self.device_frame = LabelFrame(master, text="Device status") #self.device_frame.pack(side=TOP, expand=False, fill=X) self.device_frame.grid(row=0, column=0, padx=3, pady=3, sticky="NEW") # Device widgets label = Label(self.device_frame, text="Serial number:") label.grid(row=0, column=0, padx=3, pady=3, sticky="E") self.serial_number = StringVar(self.device_frame, "00000000") label = Label(self.device_frame, width=8, textvariable=self.serial_number, relief=SUNKEN) label.grid(row=0, column=1, padx=3, pady=3, ipadx=2, ipady=2) label = Label(self.device_frame, text="Software errors:") label.grid(row=1, column=0, padx=3, pady=3, sticky="E") self.software_error_label = Label( self.device_frame, width=8, text="0", relief=SUNKEN, anchor=E) self.software_error_label.grid(row=1, column=1, padx=3, pady=3, ipadx=2, ipady=2) label = Label(self.device_frame, text="Ready:") label.grid(row=0, column=3, padx=3, pady=3, sticky="E") self.ready_led = LED(self.device_frame, size=20) self.ready_led.grid(row=0, column=4, padx=3, pady=3) label = Label(self.device_frame, text="Activity:") label.grid(row=1, column=3, padx=3, pady=3, sticky="E") self.activity_led = LED(self.device_frame, size=20) self.activity_led.grid(row=1, column=4, padx=3, pady=3) # empty column for stretching self.device_frame.grid_columnconfigure(2, weight=1) # Test Frame self.test_frame = LabelFrame(master, text="Test setup") self.test_frame.grid(row=0, column=1, rowspan=2, sticky="NEW", padx=3, pady=3) # Test widgets label = Label(self.test_frame, text="# Channels:") label.grid(row=0, column=0, padx=3, pady=3, sticky="E") chan_values = ['1', '2', '3', '4', '5', '6', '7', '8'] self.chan_combo = Combobox(self.test_frame, values=chan_values, width=8, justify="right") self.chan_combo.set('8') self.chan_combo.bind("<<ComboboxSelected>>", self.channelsChanged) self.chan_combo.grid(row=0, column=1, padx=3, pady=3, sticky="NSEW") self.start_button = Button(self.test_frame, text="Start", command=self.startTest) self.start_button.grid(row=0, column=2, padx=3, pady=3) label = Label(self.test_frame, text="Sample rate:") label.grid(row=1, column=0, padx=3, pady=3, sticky="E") self.sample_rate = IntVar(value=12500) self.sample_rate_widget = Spinbox( self.test_frame, from_=1, to=12500, width=8, textvariable=self.sample_rate, justify="right") self.sample_rate_widget.grid(row=1, column=1, padx=3, pady=3, sticky="NSEW") style = Style() style.configure("C.TButton", foreground='red') self.stop_button = Button(self.test_frame, text="Stop", style="C.TButton", #foreground="red", command=self.stopTest, state=DISABLED) self.stop_button.grid(row=1, column=2, padx=3, pady=3, sticky="NSEW") v = IntVar() self.watchdog_check = Checkbutton( self.test_frame, text="Use watchdog", variable=v) self.watchdog_check.var = v self.watchdog_check.grid(row=2, column=0, columnspan=2, padx=3, pady=3, sticky="E") self.reset_button = Button(self.test_frame, text="Reset", command=self.resetTest) self.reset_button.grid(row=2, column=2, padx=3, pady=3, sticky="NSEW") label = Label(self.test_frame, text="Pass/fail (latch):") label.grid(row=3, column=0, padx=3, pady=3, sticky="E") self.pass_led = LED(self.test_frame, size=20) self.pass_led.grid(row=3, column=1, padx=3, pady=3) label = Label(self.test_frame, text="Pass/fail (inst):") label.grid(row=4, column=0, padx=3, pady=3, sticky="E") self.inst_pass_led = LED(self.test_frame, size=20) self.inst_pass_led.grid(row=4, column=1, padx=3, pady=3) label = Label(self.test_frame, text="Test count:") label.grid(row=5, column=0, padx=3, pady=3, sticky="E") self.test_count_label = Label(self.test_frame, width=8, text="0", relief=SUNKEN, anchor=E) self.test_count_label.grid(row=5, column=1, padx=3, pady=3) # Voltage Frame self.volt_frame = LabelFrame(master, text="Voltage Inputs, mV") #self.tc_frame.pack(side=BOTTOM, expand=True, fill=BOTH) self.volt_frame.grid(row=1, column=0, sticky="NSEW", padx=3, pady=3) # Voltage widgets label = Label(self.volt_frame, text="Limit: ±") label.grid(row=0, column=0, padx=3, pady=3, sticky="E") label = Label(self.volt_frame, text="{:.1f}".format(self.voltage_limit), relief=SUNKEN, anchor=E, width=8) label.grid(row=0, column=1, padx=3, pady=3, ipadx=2, ipady=2) label = Label(self.volt_frame, text="Channel") label.grid(row=1, column=0, padx=3, pady=3) label = Label(self.volt_frame, text="Current") label.grid(row=1, column=1, padx=3, pady=3) label = Label(self.volt_frame, text="Failures") label.grid(row=1, column=2, padx=3, pady=3) self.voltage_labels = [] self.failure_labels = [] for index in range(mcc118.info().NUM_AI_CHANNELS): # Labels label = Label(self.volt_frame, text="{}".format(index)) label.grid(row=index+2, column=0, padx=3, pady=3) #label.grid_configure(sticky="W") # Voltages self.voltage_labels.append(Label(self.volt_frame, width=8, anchor=E, text="0.0", relief=SUNKEN)) self.voltage_labels[index].grid(row=index+2, column=1, padx=3, pady=3, ipadx=2, ipady=2) self.voltage_labels[index].grid_configure(sticky="E") self.failure_labels.append(Label(self.volt_frame, width=8, anchor=E, relief=SUNKEN, text="0")) self.failure_labels[index].grid(row=index+2, column=2, padx=3, pady=3, ipadx=2, ipady=2) master.protocol('WM_DELETE_WINDOW', self.close) # exit cleanup icon = PhotoImage(file='/usr/share/mcc/daqhats/icon.png') master.tk.call('wm', 'iconphoto', master._w, icon) self.pass_led.set(1)
def main(): """ This function is executed automatically when the module is run directly. """ options = OptionFlags.DEFAULT low_chan = 0 high_chan = 3 mcc_118_num_channels = mcc118.info().NUM_AI_CHANNELS sample_interval = 0.5 # Seconds try: # Ensure low_chan and high_chan are valid. if low_chan < 0 or low_chan >= mcc_118_num_channels: error_message = ('Error: Invalid low_chan selection - must be ' '0 - {0:d}'.format(mcc_118_num_channels - 1)) raise Exception(error_message) if high_chan < 0 or high_chan >= mcc_118_num_channels: error_message = ('Error: Invalid high_chan selection - must be ' '0 - {0:d}'.format(mcc_118_num_channels - 1)) raise Exception(error_message) if low_chan > high_chan: error_message = ('Error: Invalid channels - high_chan must be ' 'greater than or equal to low_chan') raise Exception(error_message) # Get an instance of the selected hat device object. address = select_hat_device(HatIDs.MCC_118) hat = mcc118(address) print('\nMCC 118 single data value read example') print(' Function demonstrated: mcc118.a_in_read') print(' Channels: {0:d} - {1:d}'.format(low_chan, high_chan)) print(' Options:', enum_mask_to_string(OptionFlags, options)) try: #input("\nPress 'Enter' to continue") #except (NameError, SyntaxError): #pass print('\nAcquiring data ... Press Ctrl-C to abort') # Display the header row for the data table. print('\n Samples/Channel', end='') for chan in range(low_chan, high_chan + 1): print(' Channel', chan, end='') print('') try: samples_per_channel = 0 while True: # Display the updated samples per channel count samples_per_channel += 1 print('\r{:17}'.format(samples_per_channel), end='') # Read a single value from each selected channel. for chan in range(low_chan, high_chan + 1): value = hat.a_in_read(chan, options) print('{:12.5} V'.format(value), end='') stdout.flush() # Wait the specified interval between reads. sleep(sample_interval) except KeyboardInterrupt: # Clear the '^C' from the display. print(CURSOR_BACK_2, ERASE_TO_END_OF_LINE, '\n') except (HatError, ValueError) as error: print('\n', error) if __name__ == '__main__': # This will only be run when the module is called directly. main()
from daqhats import mcc118, OptionFlags, HatIDs, HatError # Constants CURSOR_BACK_2 = '\x1b[2D' ERASE_TO_END_OF_LINE = '\x1b[0K' urls = ( '/(.*)', 'hello' ) app = web.application(urls, globals()) options = OptionFlags.DEFAULT low_chan = 0 high_chan = 7 mcc_118_num_channels = mcc118.info().NUM_AI_CHANNELS # Get an instance of the selected hat device object. address = select_hat_device(HatIDs.MCC_118) hat = mcc118(address) class hello: def GET(self, name): #if not name: # name = 'World' #return 'Hello, ' + name + '!' #pyDict = {'one':1,'two':2} pyDict = {0:0,1:0,2:0,3:0,4:0,5:0,6:0,7:0} global hat