Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. Chinese
  4. 串口如何稳定接收数据(转帖)
Forum Updated to NodeBB v4.3 + New Features

串口如何稳定接收数据(转帖)

Scheduled Pinned Locked Moved Chinese
30 Posts 4 Posters 24.6k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    ohno
    wrote on last edited by
    #11

    hi Vincent007,JohnYork

    我已经把代码上传到如下链接,同时里面有一个测试视频,qt5.3.1 mingw编译的
    http://pan.baidu.com/s/1kTh0ifd
    。
    谢谢你们的讨论。

    1 Reply Last reply
    0
    • O Offline
      O Offline
      ohno
      wrote on last edited by
      #12

      hi Vincent007,JohnYork
      你们是否看到代码?有问题吗?,有问题请留言谢谢.

      1 Reply Last reply
      0
      • V Offline
        V Offline
        Vincent007
        wrote on last edited by
        #13

        試把
        @
        connect(
        &m_Portconfigview,SIGNAL(signalConfigPort(const SPortsettings *)),&m_Serialportrecevie,SLOT(slotsConfigPort(const SPortsettings *)),Qt::QueuedConnection);
        connect(
        &m_Portconfigview,SIGNAL(signalConfigPort(const SPortsettings *)),this,SLOT(updatetstatus(const SPortsettings *)));
        connect(
        &m_Serialportrecevie,SIGNAL(signalThreadToStore( const QByteArray&)),&m_Serialportcachedata,SLOT(slotsSerialportcachedata(const QByteArray&)),Qt::BlockingQueuedConnection);
        connect(
        &m_Serialportcachedata,SIGNAL(signalToserialportwindow(const QByteArray&)),&m_pSerialPortWindow,SLOT(slotsserialportupdateview(const QByteArray&)),Qt::BlockingQueuedConnection);
        @
        改成
        @
        connect(
        &m_Portconfigview,SIGNAL(signalConfigPort(const SPortsettings *)),&m_Serialportrecevie,SLOT(slotsConfigPort(const SPortsettings *)));
        connect(
        &m_Portconfigview,SIGNAL(signalConfigPort(const SPortsettings *)),this,SLOT(updatetstatus(const SPortsettings *)));
        connect(
        &m_Serialportrecevie,SIGNAL(signalThreadToStore( const QByteArray&)),&m_Serialportcachedata,SLOT(slotsSerialportcachedata(const QByteArray&)));
        connect(
        &m_Serialportcachedata,SIGNAL(signalToserialportwindow(const QByteArray&)),&m_pSerialPortWindow,SLOT(slotsserialportupdateview(const QByteArray&)));
        @

        1 Reply Last reply
        0
        • O Offline
          O Offline
          ohno
          wrote on last edited by
          #14

          hi Vincent007
          我已经按照你说的进行测试,还是会卡住界面。谢谢。

          1 Reply Last reply
          0
          • V Offline
            V Offline
            Vincent007
            wrote on last edited by
            #15

            Did you test release build?

            1 Reply Last reply
            0
            • O Offline
              O Offline
              ohno
              wrote on last edited by
              #16

              hi Vincent007

              1.我是用的release build。谢谢。
              2.我看过java c# vc++写的类似串口调试助手都没有类似问题,qt版本网上所有的串口调试助手和qt官网自带的demo都有类似的问题。是不是qt控件本身的一个bug.

              1 Reply Last reply
              0
              • V Offline
                V Offline
                Vincent007
                wrote on last edited by
                #17

                measure time consumed by slotsSerialportcachedata and slotsserialportupdateview via QElapsedTimer
                另外你要確保你的PC 沒有問題.你有否在另一台PC試過你的程序?
                @
                QElapsedTimer timer;
                timer.start();
                slowOperation1();
                qDebug() << "The slow operation took" << timer.nsecsElapsed() << "nanoseconds";
                @

                1 Reply Last reply
                0
                • O Offline
                  O Offline
                  ohno
                  wrote on last edited by
                  #18

                  HI Vincent007
                  前阵子忙别的去,所以今天才回复你,不好意思按照你说的用以下代码进行测试
                  timer.start();
                  pSerialPortQPlainTextEdit.insertPlainText(DatatFormRead);
                  pSerialPortQPlainTextEdit.moveCursor(QTextCursor::End, QTextCursor::KeepAnchor);
                  qDebug() << "The slow operation took" << timer.nsecsElapsed() <<"nanoseconds";
                  下面是测试结果:
                  The slow operation took 1017500 nanoseconds
                  The slow operation took 1018310 nanoseconds
                  The slow operation took 1421502 nanoseconds
                  The slow operation took 1186476 nanoseconds

                  The slow operation took 10685984 nanoseconds
                  The slow operation took 10668154 nanoseconds
                  The slow operation took 10564419 nanoseconds
                  The slow operation took 10569686 nanoseconds
                  The slow operation took 10243486 nanoseconds
                  The slow operation took 10473245 nanoseconds
                  The slow operation took 10746766 nanoseconds
                  The slow operation took 10772700 nanoseconds
                  The slow operation took 10583059 nanoseconds
                  The slow operation took 11221681 nanoseconds
                  The slow operation took 10795798 nanoseconds
                  The slow operation took 16827051 nanoseconds

                  The slow operation took 222369451 nanoseconds
                  The slow operation took 205003460 nanoseconds
                  The slow operation took 222164411 nanoseconds
                  The slow operation took 204823949 nanoseconds
                  The slow operation took 209414655 nanoseconds
                  The slow operation took 186572559 nanoseconds
                  The slow operation took 209589304 nanoseconds
                  The slow operation took 214433676 nanoseconds
                  The slow operation took 219041401 nanoseconds
                  说明qt的窗口刷新确实有问题,请指教谢谢。

                  1 Reply Last reply
                  0
                  • V Offline
                    V Offline
                    Vincent007
                    wrote on last edited by
                    #19

                    @
                    #include "mainwindow.h"
                    #include "ui_mainwindow.h"

                    MainWindow::MainWindow(QWidget *parent) :
                    QMainWindow(parent),
                    ui(new Ui::MainWindow)
                    {
                    ui->setupUi(this);
                    _timer.setInterval(10);

                    for(int i = 0; i<1024;i++) {
                        message += "1";
                    }
                    connect(&_timer,&QTimer::timeout,this,&MainWindow::updateText);
                    _timer.start();
                    

                    }

                    MainWindow::~MainWindow()
                    {
                    delete ui;
                    }

                    void MainWindow::updateText()
                    {
                    ui->textEdit->append(message);
                    }
                    @
                    I did a simple application and test it. It works fine.
                    You can try it and adjust parameters.

                    1 Reply Last reply
                    0
                    • O Offline
                      O Offline
                      ohno
                      wrote on last edited by
                      #20

                      HI Vincent007
                      我以前测试过调用append是没有问题的,建议你改成ui->textEdit->insertPlainText(message);试试。
                      因为我不能使用append,改成append会有这么一个问题
                      一句完整的话分2次发送过来就变成2行,比如:
                      “你好,谢谢你回答我的问题”。
                      分两次之后,有可能变成
                      “你好,”
                      “谢谢你回答我的问题”

                      1 Reply Last reply
                      0
                      • B Offline
                        B Offline
                        blackRock
                        wrote on last edited by
                        #21

                        我发现MFC写的程序,会将多余的数据存储到硬盘,我用10ms的间隔,发送"hello",MFC占用内存一直变化不大,但是QT却会随着时间增大,接收的数据一旦超过一屏能显示的量的话,马上就会变卡,是不是那个人写得换行代码的逻辑非常复杂低效果呢

                        1 Reply Last reply
                        0
                        • B Offline
                          B Offline
                          blackRock
                          wrote on last edited by
                          #22

                          我发现MFC写的程序,会将多余的数据存储到硬盘,我用10ms的间隔,发送"hello",MFC占用内存一直变化不大,但是QT却会随着时间增大,接收的数据一旦超过一屏能显示的量的话,马上就会变卡,是不是那个人写得换行代码的逻辑非常复杂低效果呢

                          1 Reply Last reply
                          0
                          • B Offline
                            B Offline
                            blackRock
                            wrote on last edited by
                            #23

                            从2012到现在一直没什么改变

                            1 Reply Last reply
                            0
                            • B Offline
                              B Offline
                              blackRock
                              wrote on last edited by
                              #24

                              从2012到现在一直没什么改变

                              1 Reply Last reply
                              0
                              • O Offline
                                O Offline
                                ohno
                                wrote on last edited by
                                #25

                                HI blackRock blackRock
                                我也发现这个问题,但是不知道你是否遇到我类似的问题。

                                1 Reply Last reply
                                0
                                • O Offline
                                  O Offline
                                  ohno
                                  wrote on last edited by
                                  #26

                                  HI blackRock blackRock
                                  我也发现这个问题,但是不知道你是否遇到我类似的问题。

                                  1 Reply Last reply
                                  0
                                  • V Offline
                                    V Offline
                                    Vincent007
                                    wrote on last edited by
                                    #27

                                    I think you should ask this question on http://qt-project.org/forums/viewforum/10/
                                    because more people will answer you.

                                    1 Reply Last reply
                                    0
                                    • V Offline
                                      V Offline
                                      Vincent007
                                      wrote on last edited by
                                      #28

                                      I think you should ask this question on http://qt-project.org/forums/viewforum/10/
                                      because more people will answer you.

                                      1 Reply Last reply
                                      0
                                      • B Offline
                                        B Offline
                                        blackRock
                                        wrote on last edited by
                                        #29

                                        我跟你遇到的肯定是一样一样的

                                        1 Reply Last reply
                                        0
                                        • B Offline
                                          B Offline
                                          blackRock
                                          wrote on last edited by
                                          #30

                                          我跟你遇到的肯定是一样一样的

                                          1 Reply Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved