Small toys - temperature collection project (7)

Click the connect button. If the connection is successful, the local ip address will be displayed and the "connect" button will change to "disconnect". There is a bug here, that is, if you click disconnect yourself, the connection will be disconnected. "connect".

Well, finally we have to talk about the most important part, the processing and display of data.

void Widget::tcp_client_ReadData()
{
    static int i=0; //Static variable, used as the abscissa of the display
    qDebug()<<"e";      //测试
    QByteArray buf;
    buf = ctn->get_socket()->readAll();//读出
    if(!buf.isEmpty()) //Display if not empty
    {
        qDebug()<<buf;
        if(protocol(buf)) //Incoming buf, protocol
        {
            QDateTime time = QDateTime::currentDateTime();//Read in time
            if(save_intosql(time,a))qDebug()<<9; //Store in the database
            this->updata(i,temp_num); //displayed on the line chart
            i++;
        }
        qDebug()<<a[0]<<"  "<<a[1];
        QString str = get_msg_edit->toPlainText();
        str += buf;
        get_msg_edit->setText(str);

    }
}
//Protocol for data transfer. . . . . Communicate with the lower computer
bool protocol(const QByteArray &buf)
{
    //Possible problems, read time problems, match the acquisition time
    if(is_digits(buf.toStdString()))
    {
        a[0] = buf.toInt()/100; //take the integer part
        a[1] = buf.toInt()%100; //take the fractional part
        return true;
    }
    else return false;
}
//Check if it's all numbers
bool is_digits(const std::string &str)
{
    return str.find_first_not_of("0123456789") == std::string::npos;
}
My agreement is that the lower computer sends an integer, such as 1234, which means that the temperature is 12.34°c, and 123 is 1.23°c. If it is not a pure number, the data will be discarded without storing and displaying. will be displayed on the window, which is used for debugging.
There are several more ways to detect if strings are all numbers:

https://social.msdn.microsoft.com/Forums/zh-CN/5a76cbca-e074-42bf-9774-1ba371dbbc13/c?forum=visualcpluszhchs&forum=visualcpluszhchs

Dynamic Display of Line Chart

I have written two versions, one is the drawing tool that comes with Qt, and the other is using qcustomplot.

I will explain some qcustomplot here. Refer to http://m.blog.csdn.net/FPGADesigner/article/details/74315805 to write. It's a reference, but it's actually the same. . . After all, that's what the picture is.

So everyone sees him the same way.

In the next chapter, I will talk about the one that comes with Qt that I wrote myself.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325776112&siteId=291194637