Results 1 to 5 of 5

Thread: QWinEventNotifier alternative on Linux and Qt Embedded (Is there one?)

  1. #1
    Join Date
    Jul 2009
    Location
    Sao Paulo / Brazil
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Lightbulb QWinEventNotifier alternative on Linux and Qt Embedded (Is there one?)

    Hi there Folks.
    I'm implementing a QIODevice derived class for use with the FTDI232 API (ftd2xx.h) wich is Win-Mac-Linux API. FTDI makes Serial over USB chips.
    The API is kind enough to provide me a function for setting up events, but not kind enough to provide me a function based callback mechanism for getting notified over characters received or transmitted.
    So in my quest to making it adhere to QIODevice standards (actually talking about being able to emit the bytesWritten() and the readyReady() signals without spawning another thread) I've found:

    *On Windows*

    The way I was doing it before writing a nice QIODevice was, in another thread:

    Qt Code:
    1. HANDLE hEvtRead = ::CreateEventA(NULL, FALSE, FALSE, ""); //From the Windows API
    2. FT_SetEventNotification(ftHandle,FT_EVENT_RXCHAR,hEvtRead); // From the FTDI API
    3.  
    4. WaitForSingleObject(hEvtRead,INFINITE);
    5. //Handle the event..
    To copy to clipboard, switch view to plain text mode 

    But I don't want to do it on another thread, I want to keep it as simple as possible like being able to use my Serial Port on a single threaded application like one can with QTcpSockets, so I can't go Waiting for Single Objects on my code in the main thread. I have to find a way to insert the hEvtRead in the events that QCoreApplication's event loop is waiting for.
    And the I've found a very nice solution for this on the QProcess source code. It's a class called QWinEventNotifier that does in mere 3 lines, everything i want:

    Qt Code:
    1. //Inside my QIODevice derived class constructor:
    2. HANDLE hEvtRead = ::CreateEventA(NULL, FALSE, FALSE, ""); //From the Windows API
    3. FT_SetEventNotification(ftHandle,FT_EVENT_RXCHAR,hEvtRead); // From the FTDI API
    4.  
    5. charReceivedNotifier = new QWinEventNotifier(hEvtRead, this);
    6. QObject::connect(charReceivedNotifier, SIGNAL(activated(HANDLE)), this, SIGNAL(readyRead()));
    7. charReceivedNotifier->setEnabled(true);
    To copy to clipboard, switch view to plain text mode 

    Ok, ok I know I'll have to keep an eye on <qwineventnotifier_p.h> for it's a private class inside <QtCore/private>.

    *On Linux (glib and qt embedded)*

    The way I was doing it before writing a nice QIODevice for it was, in another thread:

    Qt Code:
    1. typedef struct _EVENT_HANDLE{
    2. pthread_cond_t eCondVar;
    3. pthread_mutex_t eMutex;
    4. int iVar;
    5. } EVENT_HANDLE;
    6.  
    7. //QThread's run() code:
    8. EVENT_HANDLE eh;
    9.  
    10. pthread_mutex_init(&eh.eMutex, NULL);
    11. pthread_cond_init(&eh.eCondVar, NULL);
    12.  
    13. FT_SetEventNotification(ftHandle, FT_EVENT_RXCHAR, (void*)&eh);
    14.  
    15. pthread_mutex_lock(&eh.eMutex);
    16. pthread_cond_wait(&eh.eCondVar, &eh.eMutex);
    17. pthread_mutex_unlock(&eh.eMutex);
    18.  
    19. //Handle event
    To copy to clipboard, switch view to plain text mode 

    But I just couldn't find a solution like QWinEventNotifier. I've found solutions that are close to it but are specific to socket descriptors.
    Has anyone run into this problem? Am I the first one trying this? I know it's a pain that the FTDI API doesn't provide me a function callback mechanism; it would be really simple..
    If you guys have a tip it'll be appreciated.

    Thanks
    Hernan

  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: QWinEventNotifier alternative on Linux and Qt Embedded (Is there one?)

    Hi chesterx!

    I decided a similar problem. Chip FTDI232 for any operating system looks like a serial port. Right? Therefore, in the *nix for the events of the reading / writing data can be used QSocketNotifier.

    [offtop]But the only bad thing is that the class QWinEventNotifier (in Windows) Private![/offtop]

    I wrote a library QSerialDevice to work with serial port. It works like QAbstractSocket.
    If you are interested in implementation - then look here: http://gitorious.org/qserialdevice

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

    chesterx (4th January 2011)

  4. #3
    Join Date
    Jul 2009
    Location
    Sao Paulo / Brazil
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QWinEventNotifier alternative on Linux and Qt Embedded (Is there one?)

    Tks kuzulis,
    I'll take a look as soon I get back to work next week.

    I know it's a private class, but all we have to do, if you want to keep your class up to date, is keep track of the QWinEventNotifier class.

    Happy New Year

  5. #4
    Join Date
    Jul 2009
    Location
    Sao Paulo / Brazil
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QWinEventNotifier alternative on Linux and Qt Embedded (Is there one?)

    Hi kuzulis.
    I just learned how to (well in a basic level) use github/gitorious and bitbucket with mercurial or git. I cloned qserialdevice and i'm going to help you with it. I don't want to reinvent the wheel .

  6. #5
    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: QWinEventNotifier alternative on Linux and Qt Embedded (Is there one?)

    Hi.

    Help is needed only to branches 2.0
    main areas are:

    - Symbian
    1. Implement a notification mechanism for tracking errors, data availability for read, empty of the transmit buffer.
    2. Implement a mechanism to track errors parity and frame
    3. Implement a policy of reading (IgnorePolicy, PassZeroPolicy and etc).
    4. Test on real device

    -WinCE
    1. Test on real device

    - Win32
    1. Test on real device

    -*nix
    1. Implement a mechanism to track errors parity and frame
    2. Implement a policy of reading (IgnorePolicy, PassZeroPolicy and etc).
    3. Test on real device

    Choose any of them.

    Ok. I'll wait for bug fixes

Similar Threads

  1. SDK 4.6 & Qt Embedded for Linux
    By zuck in forum Qt Programming
    Replies: 2
    Last Post: 21st December 2010, 14:56
  2. Qt Linux Embedded vs. Qt X11
    By memoody in forum Newbie
    Replies: 0
    Last Post: 1st November 2010, 20:59
  3. Qt for linux OR Qt/Embedded??
    By GeorgeOfTheBush in forum Installation and Deployment
    Replies: 5
    Last Post: 15th May 2009, 09:35
  4. Multiple apps using Qt/Embedded+Qtopia on Embedded Linux
    By drahardja in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 17th February 2008, 21:46

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.