Real Time Plot on Surface Example



  • I am trying to plot real time serial data onto the surface example graph
    https://doc.qt.io/qt-5/qtdatavisualization-surface-example.html
    I am able to read my serial data once and then plot it onto the surface example once, but this code doesnt keep checking for new serial data and updating the surface plot. I was wondering what you would add to the surface example in order for it to plot real time data? Where should I put my serial reading code so that it is continually prompted and read, then plotted onto the graph?

    I would like to run the code to open the serial port once, then I would like to be continually be prompted the serial device for more data and graphing it.


  • Qt Champions 2018

    @b.zar Can you show how you're reading serial port data? Usually you would use signals/slots to read data as soon as it is available (see https://doc.qt.io/qt-5/qiodevice.html#readyRead signal) and then plot the new data.



  • Hi I open the serial communication channel with

        serial.setPortName("COM3");
        serial.setBaudRate(QSerialPort::Baud9600); /*, QSerialPort::Output*/
        serial.setDataBits(QSerialPort::Data8);
        serial.setParity(QSerialPort::NoParity);
        serial.setStopBits(QSerialPort::TwoStop);
        serial.setFlowControl(QSerialPort::NoFlowControl);
        serial.open(QIODevice::ReadWrite);
    
    
    
        if(!serial.isOpen()){
            standardOutput << "this port is not currently open\r\n" << endl;
        }
        if(serial.isOpen()){
            standardOutput << "this port is now opennnnnnnnnnnnnnnnnn\r\n" << endl;
        }
    
    
    
        //Setup Command
        serial.write("!sm\r\n");
        standardOutput << "!SM\r\n" << endl;
        serial.waitForReadyRead();
        data = serial.readLine();
        if(data != "\n")
            standardOutput << data << endl;
        while(data != "Normal Mode"){
        data = serial.readLine();
        }
          standardOutput << data << endl;
    
    
    
    
        //Set Columns Number
        serial.write("!nc24\r\n");
        standardOutput << "!NC24\r\n" << endl;
        serial.waitForReadyRead();
        data = serial.readLine();
        if(data != "\n")
            standardOutput << data << endl;
        serial.waitForReadyRead();
    
        while(data != "Number of col 24"){
        data = serial.readLine();
        }
         standardOutput << data << endl;
    
    
    
    
      //Set Rows Number
         serial.write("!nr16\r\n");
         standardOutput << "!NR24\r\n" << endl;
         serial.waitForReadyRead();
         data = serial.readLine();
         standardOutput << data << endl;
         serial.waitForReadyRead();
    
         while(data != "Number of row 16"){
         data = serial.readLine();
         }
           standardOutput << data << endl;
    
    
    
    
          //Set Delay
          serial.write("!sd10\r\n");
          standardOutput << "!SD10\r\n" << endl;
          serial.waitForReadyRead();
          data = serial.readLine();
          serial.waitForReadyRead();
    
          while(data != "Sampling Delay 10"){
              data = serial.readLine();
          }
          standardOutput << data << endl;
    
    
    
           //Start Sampling
        serial.write("!ss\r\n");
        standardOutput << "!ss\r\n" << endl;
        serial.waitForReadyRead();
        data = serial.readLine();
        serial.waitForReadyRead();
    
        while(data != "Sampling Matrix"){
            data = serial.readLine();
        }
        standardOutput << data << endl;
    
    
    
        serial.write("!rm\r\n");
        standardOutput << "!RM\r\n" << endl;
    

    Then each time I run this to get the data and put it into a 2D array to be graphed. I am receiving data from a matrix.

    int j = 0;
    int i = 0;
    int k = 0;
    int p = 0;
    
    
    
    
    QTextStream standardOutput(stdout);
    QByteArray data;
    const char * point;
    
    
    
    
    
    
    
    
    
    serial.waitForReadyRead();
    data = serial.readLine();
    
      while(j<16){
      serial.waitForReadyRead();
      data = serial.readLine();
    
      if(data != "\n"){
    //      standardOutput << data << endl;
          point = data.constData();
    
          p = 0;
          k = 0;
    

    // standardOutput << "here" << endl;

          while(point[p]){
    
              if(point[p] == ','){
                  p++;
              }
              if(point[p] == NULL){
    
              }
              else{
    
                            if(k<24){
                          integertest[j][k] = point[p] - '0';
                           standardOutput << integertest[j][k] << endl;
                  }
           k++;
           p++;
          }
    

    }

       //   aux = QByteArray::constData(data);
        //  aux = strtok(NULL, ",");
    
          j++;
      }
    

    }

    i++;
    j=0;
    standardOutput << "next" << endl;

    serial.write("!rm\r\n");
    standardOutput << "!RM\r\n" << endl;

    So I would like to open the channel by running the top code once in main, then have this second part constantly getting new data and updating the graph. The array I would like to graph is the integertest[j][k] array. Currently I put the second part of the code in the graphing object in the surface example, but it is only getting the data once. Also I need to send a serial command each time to get new matrix data. The 'rm' command prompts the matrix sensor to send data. I store each row into a QBytearray then put that into a row of an integer 2D array. I do this for each row of the matrix.

    Basically I need the code to continue prompted the serial device for data and then update the graph.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.