def log_data(self, duration):

        if duration != 1:  # if have to log
            self.data_logging = not self.data_logging  # reverse status
            if not self.data_logging:  # if not logging, quit
                return

        print "Beginning to log data.."

        # Initialize Plot Visualization
        self.plot_visualization = Continual_Plot.ContinualPlot()

        # Figure out time
        now = datetime.datetime.now()
        now_s = "%d.%d.%d - %dh.%dm.%ds" % (now.month, now.day, now.year, now.hour, now.minute, now.second)

        # Name file
        if duration == 1:
            filename = "%s\\data\\data - %s - single data log.txt" % (os.getcwd(), now_s)
        else:
            filename = "%s\\data\\data - %s - continual data log.txt" % (os.getcwd(), now_s)

        # Make output directory (unless already exists)
        dataLogger.makeDir()

        # Open File
        print "Writing to file: %s" % filename
        fout = open(filename, "w")

        # Write starting data/time
        fout.write("Start time: %s\n\n\n" % now_s)

        # Write Column headers
        # fout.write(dataLogger.makeHeaders())

        # Either run once, or start thread (depending on run specs)
        if duration == 1:
            self.log_data_write(fout)
            fout.close()
            print "Finished logging PIC state"
            self.statusBar.showMessage("Finished logging PIC state")
        else:
            if self.data_logging:
                thread.start_new_thread(self.log_data_thread, (fout,))
                self.statusBar.showMessage("Started Live data logging")
    def get_eeprom_clicked(self):
        print "getting eeprom"

        # Asks the pic for the 256 eeprom bytes. Each time, PIC gives next 8 values
        # Thus, we loop 8 bytes * 32 times = 256 total bytes
        for i in range(0, 256 / 8):
            self.usb.control_transfer(
                self.dev, 0xC0, GET_EEPROM, 0, 0, 8, self.buffer
            )  # input = #bytes host requesting (the 1)
            for j in range(0, 8):
                index = 8 * i + j
                self.eeprom[index] = ord(self.buffer[j])  # ord converts self.buffer characters to ints

        print "\nEEPROM is 256 bytes"
        print self.eeprom
        # Write EEPROM to text file

        # Figure out time
        now = datetime.datetime.now()
        now_s = "%d.%d.%d - %dh.%dm.%ds" % (now.month, now.day, now.year, now.hour, now.minute, now.second)

        # Name file
        filename = "%s\\data\\eeprom - %s - eeprom get.txt" % (os.getcwd(), now_s)

        # Make output directory (unless already exists)
        dataLogger.makeDir()

        # Open File
        print "Writing to file: %s" % filename
        fout = open(filename, "w")

        # Create output string
        s_out = ""
        for i in range(0, 256):
            s_out += "Byte %d: \t%d\n" % (i, self.eeprom[i])

        # Write starting data/time
        fout.write("Eeprom state at: %s\n\n\n" % now_s)
        fout.write(s_out)
        fout.close()