Results 1 to 2 of 2

Thread: Problem with QSerialPort

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2018
    Qt products
    MacOS X Windows

    Default Problem with QSerialPort

    My problem is the following, I have two slot functions connected to a QPushButton that make the connection and disconnect to an arduino . And in the connection function I show a message on a display that arduino is already connected to the PC and in the other function show a message on the display when I disconnect. Then I show the functions A and B, I have reviewed and the problem I have is that the signal does not send the arduino, in the case of the connection function if I do a slot function where it has only arduino -> write(code), the message is received by the arduino. And in the case of disconnection if I remove the function close () I get the message displayed on the display.
    Why is the message not sent to the arduino when I send it through the slot functions A and B?

    How can I correct these functions?
    Thanks for help me.

    Qt Code:
    1. void Widget::connectToArduino()
    2. {
    3. if(arduino_is_available){
    4. // open and configure the serialport
    5. arduino->setPortName(selectedPort);
    6. arduino->open(QSerialPort::WriteOnly);
    7. arduino->setBaudRate(QSerialPort::Baud9600);
    8. arduino->setDataBits(QSerialPort::Data8);
    9. arduino->setParity(QSerialPort::NoParity);
    10. arduino->setStopBits(QSerialPort::OneStop);
    11. arduino->setFlowControl(QSerialPort::NoFlowControl);
    13. arduino->write("#STAR\n");//Code to show message of connection to the pc.
    15. connectButton->setText("Disconnect");
    16. enableControls();
    17. }else{
    18. // give error message if not available
    19. QMessageBox::warning(this, "Port error", "Couldn't find the Arduino!");
    20. }
    21. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. void Widget::disconnectFromArduino()
    2. {
    3. arduino_is_available = false;
    4. arduino_port_name="";
    5. selectedPort="";
    6. resetDefaults();
    7. if(arduino->isWritable())
    8. {
    9. qDebug() << "Is writable";
    10. arduino->write("#STOP\n");
    11. }
    12. closePort();
    13. this->repaint();
    14. }
    15. void Widget::closePort()
    16. {
    17. portList.clear();
    18. PortComboBox->clear();
    19. //delete arduino;
    20. arduino->close();
    21. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by anda_skoa; 24th August 2019 at 09:14. Reason: missing [code] tags

Similar Threads

  1. QSerialPort responces
    By ad5xj in forum Qt Programming
    Replies: 3
    Last Post: 27th December 2017, 16:14
  2. QSerialPort and QThread
    By maratk1n in forum Qt Programming
    Replies: 12
    Last Post: 5th May 2017, 23:50
  3. QSerialPort
    By fmarques in forum Qt Programming
    Replies: 0
    Last Post: 20th April 2016, 17:04
  4. QserialPort
    By arturs in forum Newbie
    Replies: 0
    Last Post: 13th May 2015, 21:37
  5. QSerialport in multithread
    By snow_starzz in forum Newbie
    Replies: 3
    Last Post: 3rd December 2013, 11:18


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.