Results 1 to 13 of 13

Thread: Way to check for input data from serial port without polling in main

  1. #1
    Join Date
    Jul 2012
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Way to check for input data from serial port without polling in main

    Hey!

    I'm trying to make a class in Qt to handle communication with a turnable button with programable resistens. The button came with some functions for communicating with it. I can communicate with it just fine. Every time it is turn it sends a report to the serial port it's connected to. Untill now I've just been polling a function that came with the device for reading these reports. Now I was wondering if I somehow could check for input outside the main loop. Then when there's input call this function to read it.

    I've tried solving this problem by overwriting the winEventFilter but I only see when the device is plugged-in or removed. No event goes through here when the device sends a report. Is there a good reason for this?
    Then I found something about SerialPort::DataReceived Event but this seem only to be useful if I myself had initialized the port and not through the function I got with the device. Am I wrong?

    Hope someone got a good advice on how to solve this!

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

    Default Re: Way to check for input data from serial port without polling in main

    Use ready-made library as QtSerialPort or QextSerialPort and use the signal is readyRead().

    I would suggest taking QtSerialPort

  3. #3
    Join Date
    Jul 2012
    Posts
    19
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Way to check for input data from serial port without polling in main

    Quote Originally Posted by kuzulis View Post
    Use ready-made library as QtSerialPort or QextSerialPort and use the signal is readyRead().

    I would suggest taking QtSerialPort
    i suggest this same solution and use the readyRead to fire up a slot function in your class

  4. #4
    Join Date
    Jul 2012
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Way to check for input data from serial port without polling in main

    I've been trying to install the library by following the instructions in the link you gave. I've not tried running qt projects in the command propt before so it might be a simple mistake from my side. I get this:

    SerialPortd_resource.rc(4):fatal error RC1015: cannot open include file 'winver.h'

    I think maybe I have to include something in my path but I don't know what.

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,543
    Thanks
    13
    Thanked 1,577 Times in 1,506 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Way to check for input data from serial port without polling in main

    You need to be using a command prompt with both the Qt build and Microsoft compiler environments established. If you are using the Qt SDK then you can get a Qt Command Prompt using the option in your Start Menu. Then you need the Microsoft environment: http://msdn.microsoft.com/en-us/library/f35ctcxw.aspx

  6. #6
    Join Date
    Jul 2012
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Way to check for input data from serial port without polling in main

    I've now tried openning the serialport.pro in Qt and then ran it there. A window open saying "Press <Return> to close this window". The window was named C:\QtSDK\QtCreator\bin\qtcreator_process_stub.exe. Does this mean that the library was installed?

    I then tried running my project but it didn't compile saying:
    main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall QtAddOn::SerialPort::SerialPort::~SerialPort(void) " (__imp_??1SerialPort@0QtAddOn@@UAE@XZ)
    main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall QtAddOn::SerialPort::SerialPort::SerialPort(class QObject *)" (__imp_??0SerialPort@0QtAddOn@@QAE@PAVQObject@@@Z)
    release\test2.exe : fatal error LNK1120: 2 unresolved externals

    It seems I need to include some library related to SerialPort


    Added after 34 minutes:


    Thanks. Ran it in the command prompt for MSVC and it worked! I also got a qt project where a SerialPort is initialized to work. But only the debug version. No release was installed. Tried writing CONFIG += release as the guide says but it just says Cannot find file: CONFIG Cannot find file: release.

    Besides that I need some documentation. Can't find it on the internet. Something about qdoc but don't know what that means exactly..
    Last edited by Kammersgaard; 16th July 2012 at 09:33.

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

    Default Re: Way to check for input data from serial port without polling in main

    Tried writing CONFIG += release as the guide says but it just says Cannot find file: CONFIG Cannot find file: release.
    Oops.. Sorry.. My mistake.
    Should be written without spaces:
    CONFIG+=release
    I'll correct the WiKi.

  8. #8
    Join Date
    Jul 2012
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Way to check for input data from serial port without polling in main

    Thanks that worked but now it says cannot open input file 'SerialPort.lib'. I emptied the build folder before running it. Should I remove anything else?

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

    Default Re: Way to check for input data from serial port without polling in main

    Can't find it on the internet. Something about qdoc but don't know what that means exactly..
    The documentation is not finished yet, but you can use, need build:
    1. Check in installed Qt for file <path to qt directory>\doc\html\qt.index
    2. Set path to Qt directory:
    Qt Code:
    1. set QT5DOC=<path to qt directory>
    To copy to clipboard, switch view to plain text mode 
    3. Make QDoc, example:
    Qt Code:
    1. qdoc3 <path to serialport source>\doc\serialport.qdocconf
    To copy to clipboard, switch view to plain text mode 
    4. The result will appear the documentation in:
    Qt Code:
    1. <path to serialport source>\doc\html\
    To copy to clipboard, switch view to plain text mode 

    Thanks that worked but now it says cannot open input file 'SerialPort.lib'. I emptied the build folder before running it. Should I remove anything else?
    Before assembling the Release should be completely clean build directory, and then (after assembly) - install the library.
    Then in the Qt /lib and /bin directory will contain both Debug and Release serial port.


    Added after 39 minutes:


    UPD:
    Thanks that worked but now it says cannot open input file 'SerialPort.lib'.
    To solve this problem there are 3 way:

    1) Build Debug and Release in separate directories, for example:
    serialport-release
    serialport-debug
    and then, after build, turn run "make install" for each target ( from serialport-release and serialport-debug )

    2) After build and install Debug target, need delete /QtAddOnSerialPort directory from <qt path>\include, and next,
    restart Command promt and build and install Release target.

    3) Just comment out the build of examples and tests in serialport.pro:
    Qt Code:
    1. SUBDIRS = src #examples tests
    To copy to clipboard, switch view to plain text mode 
    Last edited by kuzulis; 16th July 2012 at 11:25.

  10. #10
    Join Date
    Jul 2012
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Way to check for input data from serial port without polling in main

    With path to qt directory do you mean something like C:\QtSDK\Desktop\Qt\4.8.1\msvc2008? I didn't find any doc folder there. Checked the entire computer and no qt.index file. The closest was qt-sdk.index.

    With the release installation I first installed the debug. Then I emptied the "serialport-build" folder where I had build the debug. Then I moved ahead with the release installation. First ran the qmake. That went fine. Then during the nmake I got the "cannot open input file 'SerialPort.lib'" error. What did I do wrong?


    Added after 7 minutes:


    Got the release installed now.
    Last edited by Kammersgaard; 16th July 2012 at 11:35.

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

    Default Re: Way to check for input data from serial port without polling in main

    With path to qt directory do you mean something like C:\QtSDK\Desktop\Qt\4.8.1\msvc2008?
    Yes, something like that.

    I didn't find any doc folder there. Checked the entire computer and no qt.index file. The closest was qt-sdk.index.
    So you need to build the documentation will take the file qt.index from source Qt4.

    What did I do wrong?
    I wrote to you three ways to solve this problem.


    Added after 9 minutes:


    UPD: Try download documentation as html.zip here: http://www.freeupload.cn/download.php?file=56885
    Last edited by kuzulis; 16th July 2012 at 13:38.

  12. The following user says thank you to kuzulis for this useful post:

    Kammersgaard (17th July 2012)

  13. #12
    Join Date
    Jul 2012
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Way to check for input data from serial port without polling in main

    Got it all working now so thanks a lot for the help! Now I'm trying to run the program on another computer. Should I install the library again in the same way or is it possible to just copy some of the files that the first installation made? In that case where to?

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

    Default Re: Way to check for input data from serial port without polling in main

    Need copy to another computer necessary *.dll libraries Qt and QtSerialPort, put them in a folder with your *.exe file, provided that you work in Windows.
    If you work in Linux - a little differently.

    In any case - this topic is not relevant to this post. Look for a solution in Google.

Similar Threads

  1. read data from serial port
    By amitpatel22 in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 20th July 2011, 17:11
  2. DataPlot with data from Serial Port
    By przemek in forum Qwt
    Replies: 4
    Last Post: 2nd April 2011, 17:11
  3. can't set serial port data bits
    By yyiu002 in forum Qt Programming
    Replies: 6
    Last Post: 23rd June 2010, 22:28
  4. data from serial port
    By bhe in forum Newbie
    Replies: 4
    Last Post: 3rd May 2009, 10:19
  5. First attempt to display serial port data on GUI
    By ShaChris23 in forum Newbie
    Replies: 12
    Last Post: 4th May 2007, 09:14

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.