def get_and_display_data(self): self.device.usb_write('E0') raw_data = self.device.get_data(self.usb_packet_count) raw_data.pop(0) self.run_button.config(state='active') if not raw_data: # if something is wrong just return return # call function to convert the raw ADC values into the current that passed # through the working electrode self.data = self.device.process_data( raw_data) # bind data to cv_frame master # make the voltages for the x-axis that correspond to the currents read x_line = cv_frame.make_x_line( self.params.asv_settings.low_voltage, self.params.asv_settings.high_voltage, self.params.dac.voltage_step_size, self.params.asv_settings.sweep_type, self.params.asv_settings.sweep_start_type) self.graph.update_data( x_line, self.data, raw_data) # send raw data for testing purposes self.run_button.config( text="Run ASV", command=lambda: self.asv_run(self.graph, self.run_button), relief=tk.RAISED)
def make_graph(self, sweep_type, start_volt_type): """ Make a graph of what the voltage versus time protocol looks like :param sweep_type: str - 'LS' or 'CV' for a linear sweep or cyclic voltammetry :param start_volt_type: str - 'Zero' or 'Start' for starting the protocol at zero volts or the starting voltage """ self.geometry("700x300") blank_frame = tk.Frame() # holder for toolbar that is not needed try: start_volt = int(float(self.start_volt.get())) end_volt = int(float(self.end_volt.get())) rate = float(self.freq.get()) except: return -1 low_voltage = min([start_volt, end_volt]) high_volt = max([start_volt, end_volt]) voltage_step = self.master.device_params.dac.voltage_step_size ylims = [low_voltage, high_volt] # make the voltage protocol, use the functions used by the cv_frame self.data = cv_frame.make_x_line(start_volt, end_volt, voltage_step, sweep_type, start_volt_type) steps_per_second = rate * float(voltage_step) total_time = len(self.data) * steps_per_second time = [x * steps_per_second for x in range(len(self.data))] plt_props = {'xlabel': "'time (msec)'", 'ylabel': "'voltage (mV)'", 'title': "'Voltage profile'", 'subplots_adjust': "bottom=0.15, left=0.12"} self.graph = tkinter_pyplot.PyplotEmbed(blank_frame, plt_props, self, ylims, 0, total_time) self.graph.pack(side='left') self.graph.simple_update_data(time, self.data)
def get_and_display_data_from_export_channel(self, canvas, _channel=None): """ For developers to get data from the device. Write to the device to let it know to export the data to the computer then call the method get_data to get the data, then convert the data to current :param canvas: tkinter frame with pyplot canvas to plot to :param _channel: int of the adc channel to get from the device :return: """ if not _channel: # if no channel sent, use the one saved in parameters dict _channel = self.params.adc_channel # the correct complete message was received so attempt to collect the data self.usb_write('E' + str(_channel)) # step 4 # Get the raw data from the ADC raw_data = self.get_data() if not raw_data: # if something is wrong just return return # call function to convert the raw ADC values into the current that passed # through the working electrode data = self.process_data(raw_data) self.master.current_data = data x_line = cv_frame.make_x_line(self.params.actual_low_volt, self.params.actual_high_volt, self.params.volt_increment) self.master.voltage_data = x_line # Send data to the canvas where it will be saved and displayed canvas.update_data(x_line, data, raw_data)
def update_graph(self, start_voltage_type, sweep_type): """ Update the graph displaying the voltage protocol :param start_voltage_type: str - 'LS' or 'CV' for a linear sweep or cyclic voltammetry :param sweep_type: str - 'Zero' or 'Start' for starting the protocol at zero volts or the starting voltage :return: """ try: start_volt = int(float(self.start_volt.get())) end_volt = int(float(self.end_volt.get())) rate = float(self.freq.get()) except: # if crap input just leave return -1 low_voltage = min([start_volt, end_volt]) high_volt = max([start_volt, end_volt]) ylims = [low_voltage, high_volt] # resize the y axis self.graph.graph_area.axis.set_ylim(ylims) # TODO: horrible for encapsulation # remake the voltage protocol voltage_step = self.master.device_params.dac.voltage_step_size self.data = cv_frame.make_x_line(start_volt, end_volt, voltage_step, sweep_type, start_voltage_type) # make a new t-axis data steps_per_second = rate / float(voltage_step) if steps_per_second <= 0: return # user is not done typing in the varible yet total_time = len(self.data) / steps_per_second time = [x / steps_per_second for x in range(len(self.data))] xlims = [0, total_time] # resize the x axis self.graph.graph_area.axis.set_xlim(xlims) # TODO: horrible for encapsulation self.graph.voltage_line.set_data(time, self.data) self.graph.update_graph()