コード例 #1
0
ファイル: RTGraph.py プロジェクト: sgds23/RTGraph
 def start(self):
     log.info("Clicked start")
     self.sp = SerialProcess(self.queue)
     ports = self.sp.get_ports()
     log.info(ports)
     if 0 < len(ports):
         self.sp.open_port(ports[0])
         if self.sp.is_port_available(ports[0]):
             self.sp.start()
             self.timer_plot_update.start(10)
         else:
             log.info("Port is not available")
     else:
         log.warning("No ports detected")
コード例 #2
0
ファイル: main.py プロジェクト: victorgabr/RTGraph
    def start(self):
        self.data = SerialProcess(self.queue)
        # Select serial port configuration form ui
        self.data.openPort(str(self.ui.cBox_Port.currentText()),
                           int(self.ui.cBox_Speed.currentText()))

        if self.data.start() is False:
            QtGui.QMessageBox.question(self,
                                       "Can't open Serial Port",
                                       "Serial port is already opened.",
                                       QtGui.QMessageBox.Ok)
        else:
            # start CSV data export if enabled
            if self.ui.chBox_export.isChecked():
                # export data
                self.csv = CSVExport()
                self.ui.statusbar.showMessage("Exporting data")
            else:
                self.ui.statusbar.showMessage("Acquiring data")
            # start data process, lock the ui and set plot update time
            self.set_ui_locked(True)
            self.timer_plot_update.start(PLOT_UPDATE_TIME)
            self.timer_freq_update.start(PLOT_UPDATE_TIME*10)
コード例 #3
0
ファイル: main.py プロジェクト: victorgabr/RTGraph
class MainWindow(QtGui.QMainWindow):
    ##
    # @brief Configures initial settings of the window.
    # Initialize data, plots, imported functions and timers
    # @param self Object handler
    def __init__(self):
        QtGui.QMainWindow.__init__(self)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        # Initializes plots
        self.ui.plt.setBackground(background=None)
        self.ui.plt.setAntialiasing(True)
        self.plt1 = self.ui.plt.addPlot(row=1, col=1)

        # Variables
        self.queue = Queue(N_SAMPLES)
        self.data = None
        self.csv = None
        self.DATA0 = deque([], maxlen=N_SAMPLES)
        self.TIME = deque([], maxlen=N_SAMPLES)
        self.reset_buffers()

        ##
        # @brief Reference update plot timer
        # Qt4 timer to trigger the @updatePlot function
        self.timer_plot_update = QtCore.QTimer(self)

        self.timer_freq_update = QtCore.QTimer(self)

        # Qt signals and slots
        QtCore.QObject.connect(self.ui.pButton_Start,
                               QtCore.SIGNAL('clicked()'), self.start)
        QtCore.QObject.connect(self.ui.pButton_Stop,
                               QtCore.SIGNAL('clicked()'), self.stop)
        QtCore.QObject.connect(self.timer_plot_update,
                               QtCore.SIGNAL('timeout()'), self.update_plot)
        QtCore.QObject.connect(self.timer_freq_update,
                               QtCore.SIGNAL('timeout()'), self.update_freq)

        # Configure UI
        ports = getSerialPorts()
        if len(ports) <= 0:
            ans = QtGui.QMessageBox.question(self,
                                             "No serial ports available",
                                             "Connect a serial device.\n" +
                                             "Scan again?",
                                             QtGui.QMessageBox.Yes,
                                             QtGui.QMessageBox.No)
            if ans == QtGui.QMessageBox.Yes:
                ports = getSerialPorts()
        self.ui.cBox_Port.addItems(ports)
        self.ui.cBox_Speed.addItems(["9600", "57600", "115200"])
        self.ui.cBox_Speed.setCurrentIndex(2)
        self.set_ui_locked(False)

        # Configure plots
        self.configure_plot(self.plt1, "CSV1", "")

    ##
    # @brief Start SerialProcess for data acquisition
    # @param self Object handler
    def start(self):
        self.data = SerialProcess(self.queue)
        # Select serial port configuration form ui
        self.data.openPort(str(self.ui.cBox_Port.currentText()),
                           int(self.ui.cBox_Speed.currentText()))

        if self.data.start() is False:
            QtGui.QMessageBox.question(self,
                                       "Can't open Serial Port",
                                       "Serial port is already opened.",
                                       QtGui.QMessageBox.Ok)
        else:
            # start CSV data export if enabled
            if self.ui.chBox_export.isChecked():
                # export data
                self.csv = CSVExport()
                self.ui.statusbar.showMessage("Exporting data")
            else:
                self.ui.statusbar.showMessage("Acquiring data")
            # start data process, lock the ui and set plot update time
            self.set_ui_locked(True)
            self.timer_plot_update.start(PLOT_UPDATE_TIME)
            self.timer_freq_update.start(PLOT_UPDATE_TIME*10)

    ##
    # @brief Updates graphs and writes to CSV files if enabled
    # @param self Object handler
    def update_plot(self):
        # Get new data from buffer
        while self.queue.qsize() != 0:
            data = self.queue.get(True, 1)
            self.TIME.append(data[0])
            self.DATA0.append(data[1])
            # If enabled, write to log file
            if self.ui.chBox_export.isChecked():
                self.csv.csvWrite(data)
        # Draw new data
        self.plt1.clear()
        self.plt1.plot(x=list(self.TIME)[-PLOT_UPDATE_POINTS:], y=list(self.DATA0)[-PLOT_UPDATE_POINTS:], pen='#2196F3')

    def update_freq(self):
        # Show adquisition frequency
        self.ui.statusbar.showMessage("Sampling at " + str(1/(self.TIME[-1] - self.TIME[-2])) + " Hz")

    ##
    # @brief Stops SerialProcess for data acquisition
    # @param self Object handler
    def stop(self):
        self.data.closePort()
        self.data.join()
        self.timer_plot_update.stop()
        self.timer_freq_update.stop()
        self.set_ui_locked(False)
        self.reset_buffers()
        self.ui.statusbar.showMessage("Stopped data acquisition")

    ##
    # @brief Basic configurations for a plot
    # @param self Object handler
    # @param plot Plot to be customized
    # @param title Title for the plot
    # @param unit Unit for the plot
    # @param plot_range List with min and max values to show in the plot
    @staticmethod
    def configure_plot(plot, title, unit, y_min=0, y_max=0,
                       label_color='#2196F3', label_size='11pt'):
        label_style = {'color': label_color, 'font-size': label_size}
        plot.setLabel('left', title, unit, **label_style)
        plot.setLabel('bottom', 'Time', 's', **label_style)
        plot.showGrid(x=False, y=True)
        if y_min != y_max:
            plot.setYRange(y_min, y_max)
        else:
            plot.enableAutoRange(axis=None, enable=True)
        plot.setMouseEnabled(x=False, y=False)

    ##
    # @brief Basic configurations for a plot
    # @param self Object handler
    # @param enabled Sets the ui locked
    def set_ui_locked(self, enabled):
        self.ui.pButton_Stop.setEnabled(enabled)
        self.ui.pButton_Start.setEnabled(not enabled)
        self.ui.cBox_Port.setEnabled(not enabled)
        self.ui.cBox_Speed.setEnabled(not enabled)
        self.ui.chBox_export.setEnabled(not enabled)

    ##
    # @brief Clears the buffers
    # @param self Object handler
    def reset_buffers(self):
        self.DATA0.clear()
        self.TIME.clear()

    ##
    # @brief Function to be executed while closing the main window
    # @param self Object handler
    # @param event Event who calls the exit
    def closeEvent(self, event):
        log.i('Starting close')
        try:
            if self.data.is_alive():
                log.w('SerialProcess running, stopping it')
                self.stop()
        except:
            pass
        app.exit()
        sys.exit()
コード例 #4
0
    glTranslatef(0.0, 0.0, -5.0)


def keyboard(*args):
    if args[0] == 'c':
        global first
        first = True


def main():
    glutInit(sys.argv)
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
    glutInitWindowSize(500, 500)
    glutInitWindowPosition(100, 100)
    glutCreateWindow("title")
    init()
    glutDisplayFunc(display)
    glutIdleFunc(display)
    glutReshapeFunc(reshape)
    glutKeyboardFunc(keyboard)
    glutMainLoop()


if __name__ == '__main__':
    queue = Queue(512)
    data = SerialProcess(queue)
    #~ data.openPort("/dev/ttyACM0", 115200)
    data.openPort("/dev/ttyUSB0", 115200)
    data.start()
    main()
コード例 #5
0
ファイル: RTGraph.py プロジェクト: sgds23/RTGraph
class MainWindow(QtGui.QMainWindow):
    def __init__(self):
        QtGui.QMainWindow.__init__(self)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        self.plt1 = None
        self.timer_plot_update = None
        self.timer_freq_update = None
        self.data = None
        self.time = None
        self.sp = None

        self.queue = multiprocessing.Queue()
        self.reset_buffers()

        # configures
        self.configure_plot()
        self.configure_timers()
        self.configure_signals()

    def configure_plot(self):
        self.ui.plt.setBackground(background=None)
        self.ui.plt.setAntialiasing(True)
        self.plt1 = self.ui.plt.addPlot(row=1, col=1)

    def configure_timers(self):
        self.timer_plot_update = QtCore.QTimer(self)
        # self.timer_freq_update = QtCore.QTimer(self)
        QtCore.QObject.connect(self.timer_plot_update,
                               QtCore.SIGNAL('timeout()'), self.update_plot)
        # QtCore.QObject.connect(self.timer_freq_update,
        #                       QtCore.SIGNAL('timeout()'), self.update_freq)

    def configure_signals(self):
        QtCore.QObject.connect(self.ui.pButton_Start,
                               QtCore.SIGNAL('clicked()'), self.start)
        QtCore.QObject.connect(self.ui.pButton_Stop,
                               QtCore.SIGNAL('clicked()'), self.stop)

    def reset_buffers(self):
        self.data = RingBuffer(SAMPLES)
        self.time = RingBuffer(SAMPLES)
        while not self.queue.empty():
            self.queue.get()
        log.info("Buffers cleared")

    def update_plot(self):
        log.debug("Updating plot")
        while not self.queue.empty():
            data = self.queue.get(False)
            value = str(data[0]).split(',')
            self.data.append(float(value[1]))
            self.time.append(data[1])

        self.plt1.clear()
        self.plt1.plot(x=self.time.get_all(),
                       y=self.data.get_all(),
                       pen='#2196F3')

    def start(self):
        log.info("Clicked start")
        self.sp = SerialProcess(self.queue)
        ports = self.sp.get_ports()
        log.info(ports)
        if 0 < len(ports):
            self.sp.open_port(ports[0])
            if self.sp.is_port_available(ports[0]):
                self.sp.start()
                self.timer_plot_update.start(10)
            else:
                log.info("Port is not available")
        else:
            log.warning("No ports detected")

    def stop(self):
        log.info("Clicked stop")
        self.timer_plot_update.stop()
        self.sp.stop()
        self.sp.join()
        self.reset_buffers()
コード例 #6
0
ファイル: demo2.py プロジェクト: ssepulveda/ICB_TT
    gluPerspective(65.0, float(w)/float(h), 1.0, 20.0)
    glMatrixMode(GL_MODELVIEW)
    glLoadIdentity()
    glTranslatef(0.0, 0.0, -5.0)

def keyboard(*args):
   if args[0] == 'c':
        global first
        first = True

def main():
    glutInit(sys.argv)
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
    glutInitWindowSize(500, 500)
    glutInitWindowPosition(100, 100)
    glutCreateWindow("title")
    init()
    glutDisplayFunc(display)
    glutIdleFunc(display)
    glutReshapeFunc(reshape)
    glutKeyboardFunc(keyboard)
    glutMainLoop()

if __name__ == '__main__':
    queue = Queue(512)
    data = SerialProcess(queue)
    #~ data.openPort("/dev/ttyACM0", 115200)
    data.openPort("/dev/ttyUSB0", 115200)
    data.start()
    main()