Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. STM32 Virtual COM Port and Qt

STM32 Virtual COM Port and Qt

Scheduled Pinned Locked Moved Solved Mobile and Embedded
2 Posts 1 Posters 496 Views
  • 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.
  • C Offline
    C Offline
    czukuczan
    wrote on 14 Oct 2020, 08:47 last edited by
    #1

    Hey,
    My aim is to enable communication via USB CDC HS on STM32 with Ubuntu 20.04 based PC in Qt app created in QtCreator.

    So far I've managed to run communication via UART and everything is working fine. Then I decided to switch to USB and I still can read incoming data (but only in CuteCom) and in my Qt app nothing appears.

    To be honest I have no idea what is going on and where to look for mistakes. Here I put the code:

        void MainWindow::on_pushButtonConnect_clicked()
    {
     if (ui->comboBoxDevices->count() == 0){
         this->addToLogs("No devices found.");
                 return;
     }
     QString portName = ui->comboBoxDevices->currentText().split(" ").first();
     this->device->setPortName(portName);
     this->device->setBaudRate(QSerialPort::Baud115200);
     this->device->setDataBits(QSerialPort::Data8);
     this->device->setParity(QSerialPort::NoParity);
     this->device->setStopBits(QSerialPort::OneStop);
     this->device->setFlowControl(QSerialPort::NoFlowControl);
    
     if(device->open(QIODevice::ReadWrite)){
         this->addToLogs("Port opened");
         qDebug() << "Writing down the parameters...";
         qDebug() << "Baud rate:" << this->device->baudRate();
         qDebug() << "Data bits:" << this->device->dataBits();
         qDebug() << "Stop bits:" << this->device->stopBits();
         qDebug() << "Parity:" << this->device->parity();
         qDebug() << "Flow control:" << this->device->flowControl();
         qDebug() << "Read buffer size:" << this->device->readBufferSize();
         qDebug() << "Read buffer size:" << this->device->portName();
            if (this->device->canReadLine() == true)  {
                  qDebug() << "Reading lines.";
              }  else  {
                  qDebug() << "Cannot read lines.";
              }
              while (this->device->canReadLine()){
                  qDebug() << "Reading line: " << this->device->readLine();
              }
              connect(this->device, SIGNAL(readyRead()), this, SLOT(readFromPort()));
    

    And the readFromPort() function:

    void MainWindow::readFromPort()
    {
        while(this->device->canReadLine()){
            QString line = this->device->readLine();
            qDebug() << line;
            QString terminator = "\r";
            int pos = line.lastIndexOf(terminator);
            qDebug()<<line.left(pos);
            this->addToLogs(line.left(pos));
        }
    }
    

    Do you have any idea what might be wrong or not set properly? Output:

    Baud rate: 9600
    Data bits: QSerialPort::Data8
    Stop bits: QSerialPort::OneStop
    Parity: QSerialPort::NoParity
    Flow control: QSerialPort::NoFlowControl
    Read buffer size: 0
    Read buffer size: "ttyACM0"
    Cannot read lines.
    

    Would be thankful for all help.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      czukuczan
      wrote on 14 Oct 2020, 12:18 last edited by
      #2

      Solution found. As it seems, in my code I put commands to read the port in if (with function canReadLine()). When I commented the whole condition out leaving just the reading, everything worked fine.

      Maybe someone will find a solution here. Cheers

      1 Reply Last reply
      0

      1/2

      14 Oct 2020, 08:47

      • Login

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