Results 1 to 5 of 5

Thread: qserialdevice & gui

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2013
    Posts
    3
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default qserialdevice & gui

    I want to use qtcreator and qserialdevice to allow my Beaglebone (branch 3.2 Angstrom) communicate with devices. I am developing on Ubuntu 13.10.

    I downloaded the qserial device and it built OK using the cross compiler. I then compiled the examples and they work on the Beaglebone. Now I want to use the qserialdevice within the QtCreator GUI but I'm having trouble compiling. The error is "error: cannot find -lqserialdeviced". I created a new directory under qserialdevice/examples and copied the files from writer directory before modifying them.

    I know it should be simple but I'm stuck and need help.

    Regards,
    James

    Heres my .pro file:-
    Qt Code:
    1. #-------------------------------------------------
    2. #
    3. # Project created by QtCreator 2013-06-21T16:11:25
    4. #
    5. #-------------------------------------------------
    6.  
    7. QT += core gui
    8.  
    9. greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    10.  
    11. TARGET = writerw1
    12. TEMPLATE = app
    13.  
    14.  
    15. SOURCES += main.cpp\
    16. mainwindow.cpp
    17.  
    18. HEADERS += mainwindow.h
    19.  
    20. FORMS += mainwindow.ui
    21.  
    22. OBJECTS_DIR = obj
    23. MOC_DIR = moc
    24. INCLUDEPATH += ../../src/qserialdevice
    25.  
    26.  
    27. CONFIG(debug, debug|release) {
    28. QMAKE_LIBDIR += ../../src/build/debug
    29. LIBS += -lqserialdeviced
    30. DESTDIR = debug
    31. TARGET = writerw1d
    32. } else {
    33. QMAKE_LIBDIR += ../../src/build/release
    34. LIBS += -lqserialdevice
    35. DESTDIR = release
    36. TARGET = writerw1
    37. }
    To copy to clipboard, switch view to plain text mode 

    The following is the mainwindow.cpp code

    Qt Code:
    1. The following is the mainwindow.cpp code
    2.  
    3. #include "mainwindow.h"
    4. #include "ui_mainwindow.h"
    5.  
    6. #include <QtCore/QCoreApplication>
    7. #include <QtCore/QDebug>
    8. #include <abstractserial.h>
    9. #include <iostream>
    10.  
    11.  
    12. MainWindow::MainWindow(QWidget *parent) :
    13. QMainWindow(parent),
    14. ui(new Ui::MainWindow)
    15. {
    16. ui->setupUi(this);
    17.  
    18. /* Writer
    19.   *
    20.   * This application is part of the examples on the use of the library QSerialDevice.
    21.   *
    22.   * writer - a test console application to write data to the port
    23.   *
    24.   * Copyright (C) 2009 Denis Shienkov
    25.   *
    26.   * Contact Denis Shienkov:
    27.   * e-mail: <scapig2@yandex.ru>
    28.   * ICQ: 321789831
    29.   */
    30.  
    31. using namespace std;
    32.  
    33. AbstractSerial *port = new AbstractSerial();
    34.  
    35.  
    36. /* 1. First - create an instance of an object.
    37.   */
    38.  
    39.  
    40. char dn[50]; //device name
    41. cout << "Please enter serial device name, specific by OS, \n example: in Windows -> COMn, in GNU/Linux -> /dev/ttyXYZn: ";
    42. cin >> dn;
    43.  
    44. /* 2. Second - set the device name.
    45.   */
    46. port->setDeviceName(dn);
    47.  
    48. /* 3. Third - open the device.
    49.  
    50.   Here, the port is opened with the flag "Unbuffered".
    51.   In this case (transfer data) can not use this flag.
    52.   */
    53. if (port->open(AbstractSerial::WriteOnly | AbstractSerial::Unbuffered)) {
    54.  
    55. qDebug() << "Serial device " << port->deviceName() << " open in " << port->openMode();
    56.  
    57. //Here, the default current parameters (for example)
    58. qDebug() << "= Default parameters =";
    59. qDebug() << "Device name : " << port->deviceName();
    60. qDebug() << "Baud rate : " << port->baudRate();
    61. qDebug() << "Data bits : " << port->dataBits();
    62. qDebug() << "Parity : " << port->parity();
    63. qDebug() << "Stop bits : " << port->stopBits();
    64. qDebug() << "Flow : " << port->flowControl();
    65.  
    66. /* 4. Fourth - now you can set the parameters. (after successfully opened port)
    67.   */
    68.  
    69. //Here example set baud rate 115200 bit/sec (baud)
    70. if (!port->setBaudRate(AbstractSerial::BaudRate115200)) {
    71. qDebug() << "Set baud rate " << AbstractSerial::BaudRate115200 << " error.";
    72. goto label;
    73. };
    74.  
    75. if (!port->setDataBits(AbstractSerial::DataBits8)) {
    76. qDebug() << "Set data bits " << AbstractSerial::DataBits8 << " error.";
    77. goto label;
    78. }
    79.  
    80. if (!port->setParity(AbstractSerial::ParityNone)) {
    81. qDebug() << "Set parity " << AbstractSerial::ParityNone << " error.";
    82. goto label;
    83. }
    84.  
    85. if (!port->setStopBits(AbstractSerial::StopBits1)) {
    86. qDebug() << "Set stop bits " << AbstractSerial::StopBits1 << " error.";
    87. goto label;
    88. }
    89.  
    90. if (!port->setFlowControl(AbstractSerial::FlowControlOff)) {
    91. qDebug() << "Set flow " << AbstractSerial::FlowControlOff << " error.";
    92. goto label;
    93. }
    94.  
    95. /*
    96.   ...
    97.   here you can set other parameters.
    98.   ...
    99.   */
    100.  
    101. /*
    102.   Important Note:
    103.  
    104.   1. For All OS:
    105.   If you use buffered mode (ie, at the opening did not put the flag AbstractSerial::Unbuffered),
    106.   there is no need to set timeouts reading (Ie they are to remain the default = 0)/
    107.   Any value other than 0 will only slow down data acquisition.
    108.  
    109.   2. For Windows:
    110.   If you are using unbuffered mode, the timeouts have the effect of reading!
    111.   Necessary for the total timeout to set the value of reading At least 1 ms,
    112.   or (at 0) will not be read.
    113.  
    114.   PS: I have not figured out yet what the reason.
    115.  
    116.   3. For *.nix:
    117.   If you are using unbuffered mode, the timeouts have the effect of reading!
    118.   Necessary for the total timeout to set the value of reading At least 100 ms,
    119.   as if the value is 0 read will return immediately,
    120.   so you can not read the requested number of bytes (ie, reading function can return fewer bytes).
    121.  
    122.   In any case, experiment with options for treatment with buffered/unbuffered,
    123.   as well as the timeout values from 0 to N and find the differences. :)
    124.   */
    125.  
    126.  
    127. //Here, the new set parameters (for example)
    128. qDebug() << "= New parameters =";
    129. qDebug() << "Device name : " << port->deviceName();
    130. qDebug() << "Baud rate : " << port->baudRate();
    131. qDebug() << "Data bits : " << port->dataBits();
    132. qDebug() << "Parity : " << port->parity();
    133. qDebug() << "Stop bits : " << port->stopBits();
    134. qDebug() << "Flow : " << port->flowControl();
    135.  
    136. QByteArray ba; //data to send
    137. qint64 bw = 0; //bytes really writed
    138.  
    139. /* 5. Fifth - you can now read / write device, or further modify its settings, etc.
    140.   */
    141. while (1) {
    142. bw = 0;
    143. cout << "Please enter count bytes for wtitten : ";
    144. cin >> bw;
    145.  
    146. qDebug() << "Starting writting " << bw << " bytes in time : " << QTime::currentTime();
    147.  
    148. ba.clear();
    149. ba.resize(bw);
    150.  
    151. while (bw--) //filling data array
    152. ba[(int)bw] = bw;
    153.  
    154. bw = port->write(ba);
    155. qDebug() << "Writed is : " << bw << " bytes";
    156. }
    157. }
    158. else {
    159. qDebug() << "Error opened serial device " << port->deviceName();
    160. }
    161.  
    162. label:
    163.  
    164. port->close();
    165. qDebug() << "Serial device " << port->deviceName() << " is closed";
    166. delete port;
    167. port = 0;
    168.  
    169. }
    170.  
    171. MainWindow::~MainWindow()
    172. {
    173. delete ui;
    174.  
    175.  
    176. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    2
    Thanked 43 Times in 42 Posts

    Default Re: qserialdevice & gui

    Hi.

    Instead of QSerialDevice please use QtSerialPort: http://qt-project.org/wiki/QtSerialPort,

    also see online doc: http://doc-snapshot.qt-project.org/q...ort-index.html

  3. #3
    Join Date
    Apr 2013
    Posts
    3
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: qserialdevice & gui

    Hi kuzulis,

    I would love to but my toolchain will only work up to Qt 4.6, I think QtSerialPort requires Qt 4.8.

    Regards,

  4. #4
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    2
    Thanked 43 Times in 42 Posts

    Default Re: qserialdevice & gui

    Yes, 4.8. But it is possible to build with a lower version. You just need replace QElapsedTimer to QTime (or something like that), if I'm not mistaken. Maybe something else will have to fix... by little things.

  5. #5
    Join Date
    Mar 2012
    Posts
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: qserialdevice & gui

    you can use qextserialport instead

Similar Threads

  1. QSerialDevice on Symbian
    By hubbobubbo in forum Qt Programming
    Replies: 2
    Last Post: 2nd October 2011, 19:00
  2. QSerialDevice v 0.2.0 released
    By kuzulis in forum Qt Programming
    Replies: 23
    Last Post: 18th September 2010, 23:30
  3. QSerialDevice Problem
    By waynew in forum Qt Programming
    Replies: 8
    Last Post: 21st January 2010, 14:31
  4. QSerialDevice
    By clinisbut in forum Qt Programming
    Replies: 2
    Last Post: 23rd October 2009, 13:30
  5. new library QSerialDevice
    By kuzulis in forum Qt Programming
    Replies: 2
    Last Post: 13th July 2009, 05:42

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.