Results 1 to 8 of 8

Thread: serial port issues

  1. #1
    Join Date
    Sep 2008
    Location
    Falmouth, MA, USA
    Posts
    34
    Thanks
    4
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default serial port issues

    I have a need to read and write from a QT program to a serial port. I would like to maintain platform independence, although my primary platform at this point is Windows

    Clearly, QextSerialPort is something I need to look at, and I am doing so, as you will see from questions below. But first...is this the only option available for serial ports and QT? And if so, what version should I be trying to use? It looks like some of the features in qextserialport-1.2win-alpha are not available in non-Windows environments. And needless to say, using "alpha" code is a little worrisome.

    And what is the clear answer to whether the "ReadyRead" signal works in what versions and environments? I've been through the threads, and seen lots of conflicting information

    Anyway, I am trying to compile the example qespta in the version 1.1 distribution. I am using VS 2005, and QT 4.4.2.

    I typed qmake, and then nmake -F Makefile--MessageWindow.cpp gives me the following errors:

    ./MessageWindow.cpp(93) : error C2061: syntax error : identifier '{ctor}'
    ./MessageWindow.cpp(121) : error C2061: syntax error : identifier '{ctor}'
    here is line 93

    Qt Code:
    1. msgTextEdit.append(dynamic_cast<MessageEvent::MessageEvent* >(event)->msg);
    To copy to clipboard, switch view to plain text mode 

    here is line 121

    Qt Code:
    1. QCoreApplication::postEvent(this, new MessageEvent::MessageEvent(qmsg));
    To copy to clipboard, switch view to plain text mode 

    the constructor for MessageEvent looks like this:

    Qt Code:
    1. MessageEvent::MessageEvent(QString & msg):
    2. QEvent(static_cast<QEvent::Type>(MessageWindow::MessageEvent))
    3. {
    4. this->msg = msg;
    5. }
    To copy to clipboard, switch view to plain text mode 
    clearly this code works in some environments, but doesn't in mine. Has anybody seen it? I want to concentrate on my task, and not on the example code, but also want to be sure things are working

    thanks very much in advance

    Jonathan Howland
    Last edited by jpn; 8th January 2009 at 18:27. Reason: missing [code] tags

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: serial port issues

    Try removing those extra "MessageEvent::" prefixes.
    J-P Nurmi

  3. #3
    Join Date
    Aug 2006
    Posts
    250
    Thanks
    19
    Thanked 49 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: serial port issues

    Quote Originally Posted by jhowland View Post
    I have a need to read and write from a QT program to a serial port. I would like to maintain platform independence, although my primary platform at this point is Windows

    Clearly, QextSerialPort is something I need to look at, and I am doing so, as you will see from questions below. But first...is this the only option available for serial ports and QT? And if so, what version should I be trying to use? It looks like some of the features in qextserialport-1.2win-alpha are not available in non-Windows environments. And needless to say, using "alpha" code is a little worrisome
    Qextserialport is the best available, but it's pretty broken. On Windows, 1.1 needs a patch before it will even communicate properly (really slow receiving). Readyread has never worked for me, I just used a thread that does something like:
    Qt Code:
    1. forever{
    2. while(port->bytesAvailable() <= 0) msleep(10)
    3. buffer = port->read(port->bytesAvailable())
    4. // do stuff
    5. }
    To copy to clipboard, switch view to plain text mode 

    I've alternated between using readLine and readAll but they are both kinda flaky sometimes. just plain read is still your best bet.

    On linux the situation is worse. bytesAvailable() can't be trusted at all. Sometimes it returns 1 or 2 bytes available, sometimes it returns -1, and sometimes it returns the correct value. readAll() just hangs forever.
    The only thing I could do on Linux was just try reading constantly. Something like
    Qt Code:
    1. forever {
    2. msleep(1)
    3. buffer.append(devicePorts[DEVICE_WISP]->read(qMax(1, devicePorts[DEVICE_WISP]->bytesAvailable())));
    4. }
    To copy to clipboard, switch view to plain text mode 

    Sure would be nice if the development of that lib picked up. Right now it's just marginally better than writing your own serial code for each platform.

  4. #4
    Join Date
    Sep 2008
    Location
    Falmouth, MA, USA
    Posts
    34
    Thanks
    4
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: serial port issues

    thanks for the speedy replies. No luckyet though.

    I tried following jpn's suggestion of removing the

    extra "MessageEvent::" prefixes

    and the error message changed--now instead of the identifier being '{ctor}', it's 'MessageEvent'

    In lots of cases, I have been able to avoid reading serial ports in QT by using a network device server to send my app UDP packets instead of serial data. But I can't always do that

    Jonathan Howland

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: serial port issues

    Quote Originally Posted by jhowland View Post
    I tried following jpn's suggestion of removing the

    extra "MessageEvent::" prefixes

    and the error message changed--now instead of the identifier being '{ctor}', it's 'MessageEvent'
    Do you have the appropriate include directive in place?
    J-P Nurmi

  6. #6
    Join Date
    Sep 2008
    Location
    Falmouth, MA, USA
    Posts
    34
    Thanks
    4
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: serial port issues

    Quote Originally Posted by jpn View Post
    Do you have the appropriate include directive in place?
    I dont think so--what would that be?

    jch

  7. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: serial port issues

    I meant including the header that declares MessageEvent. For example:
    Qt Code:
    1. #include "messageevent.h"
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  8. #8
    Join Date
    Aug 2006
    Location
    The Netherlands
    Posts
    64
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: serial port issues

    I wrote my own serial port code for Linux and WIN32 some time ago.
    I released it under the GPL v2 license.

    http://www.teuniz.net/RS-232

    It has been tested with GCC on Linux and MinGW on Windows XP/2000.
    Handshaking or flowcontrol is not supported.
    It uses polling to receive characters from the serial port.
    Interrupt/event-based is not supported.
    Baudrate is fixed at 115K2 but can be easily modified to other baudrates.
    Without modifications, this code uses 115K2 8N1 (8 databits, no parity, 1 stopbit).

    I use it in some data-aquisition programs using Qt on Linux and Windows.

    Regards.

Similar Threads

  1. serial port programming
    By sujatashooter in forum Qt Programming
    Replies: 1
    Last Post: 29th November 2008, 16:51
  2. accessing serial port without CONFIG += console
    By bnilsson in forum Qt Programming
    Replies: 2
    Last Post: 21st July 2008, 22:47
  3. serial port communiction
    By jagadish in forum Qt Programming
    Replies: 4
    Last Post: 7th July 2007, 13:04
  4. First attempt to display serial port data on GUI
    By ShaChris23 in forum Newbie
    Replies: 12
    Last Post: 4th May 2007, 10:14
  5. Replies: 16
    Last Post: 7th March 2006, 16:57

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.