Results 1 to 7 of 7

Thread: serial programming

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2013
    Posts
    11
    Qt products
    Qt4
    Platforms
    Windows

    Default serial programming

    I am trying to write to serial port and read as well. Below is my code for it.
    //mainwindow.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include <qextserialport.h>
    4. #include <QDebug>
    5.  
    6. MainWindow::MainWindow(QWidget *parent) :
    7. QMainWindow(parent),
    8. ui(new Ui::MainWindow)
    9. {
    10. ui->setupUi(this);
    11. }
    12.  
    13. MainWindow::~MainWindow()
    14. {
    15. delete ui;
    16. }
    17.  
    18. void MainWindow::on_pushButton_clicked()
    19. {
    20. PortSettings portSettings;
    21. portSettings.BaudRate = BAUD9600;
    22. portSettings.DataBits = DATA_8;
    23. portSettings.Parity = PAR_EVEN;
    24. portSettings.StopBits = STOP_1;
    25. portSettings.FlowControl = FLOW_OFF;
    26. //portSettings.Timeout_Millisec=1000;
    27.  
    28. port= new QextSerialPort("COM3",portSettings,QextSerialPort::EventDriven);
    29. QObject::connect(port,SIGNAL(readyRead()),this,SLOT(readData()));
    30. if(port->isOpen())
    31. {
    32. port->flush();
    33. port->close();
    34. }
    35. port->open(QextSerialPort::ReadWrite);
    36. if (port->isOpen()) {
    37. qDebug("connected!!");
    38. //delay->setInterval(2000);
    39.  
    40. }
    41. else qDebug("not connected");
    42. writeData(":0B1000408000102FA00DC\r\n");//this is the data that i need to send
    43. }
    44. void MainWindow::readData()
    45. {
    46. port->flush();
    47. QByteArray response=port->readAll();
    48. ui->textBrowser->append(response);
    49. }
    50. void MainWindow::writeData(char* msg)
    51. {
    52. port->write(msg);
    53. ui->textBrowser->append("writing data");
    54. ui->textBrowser->append(msg);
    55. port->flush();
    56. }
    To copy to clipboard, switch view to plain text mode 

    this code writes to virtual serial(realterm) and even reads the response. But when i use hardware to write serial data to an atmega, no response is obtained. But i received response when i sent this data to atmega using python. Is there any fault in here?
    Last edited by anda_skoa; 27th January 2014 at 08:20. Reason: add code tags

Similar Threads

  1. Serial Programming
    By pavan in forum Qt Programming
    Replies: 3
    Last Post: 10th August 2010, 11:49
  2. serial programming help
    By eva2002 in forum Qt Programming
    Replies: 2
    Last Post: 22nd January 2010, 11:45
  3. Serial Programming with QT
    By ape in forum Newbie
    Replies: 3
    Last Post: 24th December 2007, 20:33
  4. serial port programming in qt
    By sar_van81 in forum Qt Programming
    Replies: 46
    Last Post: 13th June 2007, 12:27
  5. Replies: 12
    Last Post: 23rd March 2007, 09:23

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
  •  
Qt is a trademark of The Qt Company.