Results 1 to 13 of 13

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

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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
    309
    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,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 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
    309
    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?

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.