Results 1 to 8 of 8

Thread: Opening a serial terminal based on COM port selection from QComboBox

  1. #1
    Join Date
    Jan 2021
    Posts
    20
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Opening a serial terminal based on COM port selection from QComboBox

    Hi,

    OS - Windows 10
    Qt version - Qt5

    In my Qt GUI, I have a QComboBox for the COM port selection and "connect" push button. When I click on connect button, able to configure serial port properly and open() call is successful.

    I am trying to build an serial port application between PC and a device.

    But I am able to see a serial console terminal on clicking connect button. Can somebody help me out here!

    Thanks in Advance,
    Anita

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,732
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Opening a serial terminal based on COM port selection from QComboBox

    Help with what exactly?

  3. #3
    Join Date
    Jan 2021
    Posts
    20
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Opening a serial terminal based on COM port selection from QComboBox

    Small correction, I am not able to open a new terminal on clicking connect push button for the COM port selected through combo box.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,943
    Thanks
    276
    Thanked 804 Times in 793 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Opening a serial terminal based on COM port selection from QComboBox

    Why do you think that opening a serial port should create a complete terminal application?

    I suggest you study Qt's Terminal example. If you use Qt Creator, it is one of the examples on the Examples part of the Welcome page.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #5
    Join Date
    Jan 2021
    Posts
    20
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Opening a serial terminal based on COM port selection from QComboBox

    Thanks, It was my understanding that just by configuring serial port and clicking a button would open a serial port.
    Yes, I have already executed Terminal example while exploring documents. For now, I think not necessary to open a new terminal.

    My serial interface frame format is, SOF | command | Len | Data | Checksum | EOF. I would like to extract my read data based on command types with variable Len. Which is the better way to store frame data, buffer or structure?

    connect(serial, &QSerialPort::readyRead, this, &MainWindow::serialReadyRead);

    void MainWindow::serialReadyRead()
    {

    QByteArray data = serial->readAll();
    QString str = QString(data);
    qDebug()<<"Received data : "<<data;

    /* SOF | command | Len | Data | Checksum | EOF */
    /* parsing serial frame data takes place here */
    }

    Where serialReadyRead() function, parses serial frame received data from another PC. Is there any correction required in the above implementation?

    Best Regards,
    Anita

  6. #6
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,530
    Thanked 281 Times in 276 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Opening a serial terminal based on COM port selection from QComboBox

    Yes, the readyRead signal is generated after a few (one, several, different) bytes, not after a packet. Serial port knows nothing about your data structure. You have to build the package in the buffer yourself and start its analysis after receiving the EOF.

  7. #7
    Join Date
    Jan 2021
    Posts
    20
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Opening a serial terminal based on COM port selection from QComboBox

    Thanks...

    Just want to know, to build a package I am using QByteArray. But my Len and Checksum are of 2 bytes in size. How can I append 2 bytes to QByteArray?

    Best Regards,
    Anita

  8. #8
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,943
    Thanks
    276
    Thanked 804 Times in 793 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Opening a serial terminal based on COM port selection from QComboBox

    How can I append 2 bytes to QByteArray?
    QByteArray::append() sounds like it could be useful for appending to a QByteArray.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 2
    Last Post: 27th October 2017, 20:55
  2. Opening Serial Port in ui
    By reg in forum Newbie
    Replies: 3
    Last Post: 17th January 2017, 09:18
  3. Serial read misses to read data from the serial port
    By mania in forum Qt for Embedded and Mobile
    Replies: 11
    Last Post: 18th August 2014, 08:49
  4. Opening A Terminal using QProcess
    By sujan.dasmahapatra in forum Qt Programming
    Replies: 1
    Last Post: 3rd February 2011, 14:51
  5. Serial Port
    By b1 in forum Qt Programming
    Replies: 2
    Last Post: 18th January 2007, 02:05

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.