Results 1 to 20 of 20

Thread: Serial comms on Windows Pc (Qextserialport)

  1. #1
    Join Date
    Jan 2009
    Location
    Midlands UK
    Posts
    62
    Thanks
    6
    Thanked 9 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Serial comms on Windows Pc (Qextserialport)

    Hi all,

    I'm currently updating a copy of Qextserialport for my own use on a MS Windows based pc. This will be a 'real world' use as I intend to port a big program to Qt that my business uses for race timing that is left running on a pc 24/7 with 3 concurrent serial ports open and data traffic flowing all the time (this program was originally written in Borland Builder 6 C++, by me). Once I'm satisfied that everything functions ok I will post it on this site for everyone to use.

    So far I've stripped it down to a pure windows version (no linux - as yet) and ironed out a few bugs. I've added a number of features and am interested in feedback from other users out there that might want other features adding- if there's something not on the following list that might be useful drop me a line !

    Note - WinComPort will automatically scan the pc on startup and build a table of all usable com ports, it also supplies text strings of all possible and current settings. The popup dialogue (ShowDialogue) will populate various comboboxes with valid user selections for all settings of the comport.

    Features working so far :-

    WinComPort(QWidget *parent) ;
    ~WinComPort(void) ;

    void ShowDialogue(void) ; // show user port setup dialog

    bool CheckValidPort(int portnum) ; // true if valid port fitted to pc

    QString GetPortName(void) ;
    int GetPortNumber(void) ;
    bool SetPortNumber(int newportnum) ;

    int GetBaudRate(void) ;
    QString GetBaudRateText(void) ;
    void SetBaudRate(int newbaudrate) ;

    int GetDataBits(void) ;
    QString GetDataBitsText(void) ;
    void SetDataBits(int newdatabits) ;

    int GetStopBits(void) ;
    QString GetStopBitsText(void) ;
    void SetStopBits(int newstopbits) ;

    int GetParity(void) ;
    QString GetParityText(void) ;
    void SetParity(int newparity) ;

    int GetFlowControl(void) ;
    QString GetFlowControlText(void) ;
    void SetFlowControl(int newflow) ;

    void SetDtr(bool set = true) ;
    void SetRts(bool set = true) ;
    ulong GetLineStatus(void) ;

    void SetTimeout(long newtimeout) ;

    ulong GetLastError(void) ;
    void TranslateError(ulong error) ;

    void CheckComEvents(void) ; // used by seperate thread
    void StopComEvents(void) ; // used by seperate thread

    // overridden from QIODevice :-

    virtual bool open(void) ;
    virtual void close(void) ;
    virtual void flush(void) ;
    virtual bool putChar(char chr) ;
    virtual bool getChar(char *chr) ;
    virtual qint64 writeData(const char *data, qint64 maxSize) ;
    virtual qint64 readData(char *data, qint64 maxSize) ;
    virtual qint64 readLine(char * data, qint64 maxSize) ;

    virtual qint64 bytesToWrite(void) ;
    virtual qint64 bytesAvailable(void) ;

    // not relevant for serial comms but included from Qextserialport

    virtual bool atEnd(void) ;
    virtual void ungetChar(char c) ;
    virtual qint64 size(void) ; // not thread safe
    virtual bool isSequential(void) ;
    virtual bool waitForReadyRead(int msecs);

    signals:
    void DsrChanged(bool state) ;
    void CtsChanged(bool state) ;
    void DcdChanged(bool state) ;
    void RiChanged(bool state) ;
    void SettingsChanged(void) ; // port settings changed in popup user dialog
    void readyRead(void) ;


    Steve Holmes
    (a beginner to Qt maybe - but I started programming in the time of punched cards and tape !)

  2. #2
    Join Date
    Mar 2008
    Location
    Houston, Texas, USA
    Posts
    277
    Thanks
    9
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: Serial comms on Windows Pc (Qextserialport)

    The only thing I see wrong with your code. Is it doesn't follow the Qt styling guide. on getters there should be no get on it. and it starts with a lower case then Upper on each word. You shouldn't put void when there are no parameters. and use like is on getting boolean values. And the constructor should be WinComPort(QWidget *parent = 0). And use 0 instead of NULL. I only see cosmetic changes. But other than that it seems fine.

    Oh and use const on getters unless there is a good reason not to And don't use Q on your own classes because those are meant for Qt classes to stand out from yours unless you registered a Qt prefix for extending Qt
    Qt-4.7.3 | Gentoo ~amd64 | KDE-4.7
    Aki IRC Client for KDE4 | Qt Documentation

  3. #3
    Join Date
    Feb 2009
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Serial comms on Windows Pc (Qextserialport)

    hi...

    where is the cpp ?

  4. #4
    Join Date
    Jan 2009
    Location
    Midlands UK
    Posts
    62
    Thanks
    6
    Thanked 9 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Serial comms on Windows Pc (Qextserialport)

    Hi

    If you want to try out my serial port code as it stands at the moment (warts and all) please feel free to download the attached zip file. I'm using QCreator 1.0 to get into Qt and the files are just a snapshot from my working directory.

    To all you serious Qt guys out there - please don't flame me for the style, I'm slowly changing from Windows/Borland but it takes time to pick up all of the infrastructure of exisiting Qt styles, classes and methods.

    The zip file contains a mainwindow class that has a terminal display gui for interacting with the WinComPort widget. just click on everything to find out how it works - there are not many comments in the code (yet). User kbd input is always directed to the Tx data line edit box.

    The WinComPort class uses standard Windows api's and overlapped calls but uses INFINITE timeouts for read & write callss o effectivly blocks . I intend to re-write the class using another thread and internal buffers to de-couple read & write calls so that they are non blocking.

    I am still working on the waitForReadyRead function as I only spotted a thread on the forum this morning and decided to include it. I've tested most of the code using a null modem breakout box with leds, plus I've a second PC running to do end to end testing.
    I've not tested the various flow control settings or flooded the port with data as yet.

    Please send feedback about stability issues.
    Attached Files Attached Files

  5. The following 2 users say thank you to SteveH for this useful post:

    HyperB (17th May 2009), LoomVortex (19th February 2010)

  6. #5
    Join Date
    Mar 2008
    Location
    Houston, Texas, USA
    Posts
    277
    Thanks
    9
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: Serial comms on Windows Pc (Qextserialport)

    Oh I wasn't flaming you mate. I was just helping

    I noticed that you were deleting some this variables. If you set a object's parent you don't need to call delete on it. In mainwindows.cpp you are deleting ui and WinComPort.

    I know you're saying that you're slowly translating. on your E_*_* defines. If you need to set multiple flags. do a search on QFlags. Else just wrap them around enum instead of #define's. And maybe around a namespace.
    Last edited by ComaWhite; 10th March 2009 at 19:24.
    Qt-4.7.3 | Gentoo ~amd64 | KDE-4.7
    Aki IRC Client for KDE4 | Qt Documentation

  7. #6
    Join Date
    Jan 2009
    Location
    Midlands UK
    Posts
    62
    Thanks
    6
    Thanked 9 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Smile Re: Serial comms on Windows Pc (Qextserialport)

    Sorry to make it look like I was being grumpy, I'm not, and I do appreciate any feedback.

    Thanks.

  8. #7
    Join Date
    Mar 2008
    Location
    Houston, Texas, USA
    Posts
    277
    Thanks
    9
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: Serial comms on Windows Pc (Qextserialport)

    No worries mate. ^_^
    Qt-4.7.3 | Gentoo ~amd64 | KDE-4.7
    Aki IRC Client for KDE4 | Qt Documentation

  9. #8
    Join Date
    Mar 2010
    Posts
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Serial comms on Windows Pc (Qextserialport)

    Hi,

    I am fresher to Qt , so if I write something rubbish please forgive me.

    I need to develop a GUI on Linux which uses serial port so I used code from this application.

    This application (WinComPort) works fine on Windows. As QT claims that application developed in QT can work on any OS after just recompilation. I installed qt on linux and I tried to compile this application.

    It gives me following error.

    g++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I../qtsdk-2010.02/qt/mkspecs/linux-g++ -I. -I../qtsdk-2010.02/qt/include/QtCore -I../qtsdk-2010.02/qt/include/QtGui -I../qtsdk-2010.02/qt/include -I. -I. -o main.o main.cpp
    In file included from mainwindow.h:6,
    from main.cpp:2:
    wincomport.h:10:21: error: windows.h: No such file or directory
    In file included from mainwindow.h:6,
    from main.cpp:2:
    wincomport.h:162: error: ‘HANDLE’ does not name a type
    wincomport.h:163: error: ‘COMMCONFIG’ does not name a type
    wincomport.h:164: error: ‘COMMTIMEOUTS’ does not name a type
    wincomport.h:165: error: ‘HANDLE’ does not name a type
    wincomport.h:166: error: ‘HANDLE’ does not name a type
    wincomport.h:167: error: ‘OVERLAPPED’ does not name a type
    wincomport.h:168: error: ‘OVERLAPPED’ does not name a type
    wincomport.h:169: error: ‘OVERLAPPED’ does not name a type
    make: *** [main.o] Error 1


    Can anybody help?

    Regards,
    Bakul

  10. #9
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Serial comms on Windows Pc (Qextserialport)

    on a MS Windows based pc.
    on Linux which uses serial port
    There's your problem.
    And read the actual error report. It tells you very clearly what is wrong! You just have to take the little effort to read a few lines.

  11. #10
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Serial comms on Windows Pc (Qextserialport)

    I think some common sense is needed here: Sure, a Qt application can be compiled on multiple platforms, but seriously, if someone includes a call to a Windows-only API function in there application, do you really expect Qt to be able to convert that API call to every other platform?

  12. #11
    Join Date
    May 2010
    Location
    USA/ Boston
    Posts
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: Serial comms on Windows Pc (Qextserialport)

    WinComPort.zip downloads as an invalid zip file on windows. Can you attach it again?

    Thanks

    Did you make any further progress with this?

  13. #12
    Join Date
    Jan 2009
    Location
    Midlands UK
    Posts
    62
    Thanks
    6
    Thanked 9 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Serial comms on Windows Pc (Qextserialport)

    Hi,

    I've attached the latest work files from my serial coms project for you to look at, it includes a simple terminal program to demo usage. At the moment all seems to work correctly and it's being used in the real world for an engine dyno rig in my business at 19.2kb. There may be a possible bug when used at very high baud rates with a continuous rx data steam causing a buffer overflow, this may just be due to flow control settings or the program using this program, unfortunately do to pressure of work I won't have time to do any more serious programming on it until about October. Note, as highlighted in the earlier posts, this only works on windows OS.


    SteveH
    Attached Files Attached Files

  14. #13
    Join Date
    Dec 2009
    Posts
    26
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Serial comms on Windows Pc (Qextserialport)

    Steve,

    Having trouble downloading your ZIP. Could you email it t me?

    --Sam

  15. #14
    Join Date
    Jan 2009
    Location
    Midlands UK
    Posts
    62
    Thanks
    6
    Thanked 9 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Serial comms on Windows Pc (Qextserialport)

    Looks like I'm having problems posting zip files - last few are corrupted (but the files on my computer or ok), this is another try at uploading....
    Attached Files Attached Files

  16. The following 2 users say thank you to SteveH for this useful post:

    jnadelman (10th June 2010), sgrant327 (24th May 2010)

  17. #15
    Join Date
    Jan 2009
    Location
    Midlands UK
    Posts
    62
    Thanks
    6
    Thanked 9 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Serial comms on Windows Pc (Qextserialport)

    Yep, definately something wrong with my posting, is anybody higher up the tree able to point out where I'm going wrong ?

    My steps are :-

    click - Reply to Thread
    click - Go Advanced
    ... enter my test message
    click - Manage Attachments
    click - Add files
    click - Select Files
    ... browse to file on my computer, click Open
    click - Upload files
    ... tick box on file now showing in Attachments
    click Insert Attatchment
    click - Submit Reply

    Also, looking at the file name as now shown on the forum, in this case it seems to add another dot to the name just after the first dot ?

    Any help apreciated SteveH

  18. #16
    Join Date
    Jun 2010
    Posts
    18
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Serial comms on Windows Pc (Qextserialport)

    Quote Originally Posted by SteveH View Post
    Looks like I'm having problems posting zip files - last few are corrupted (but the files on my computer or ok), this is another try at uploading....
    Yes, the .zip is corrupted. Are you able to post the unzipped source files? Also, did you get qextserialport from qextserialport.sourceforge.net or code.google.com/p/qextserialport? I have been able to get the qextserialport.sourceforge.net working on windows but not Linux, and I just learned that the code.google.com version is the latest.

  19. #17
    Join Date
    Jan 2009
    Location
    Midlands UK
    Posts
    62
    Thanks
    6
    Thanked 9 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Serial comms on Windows Pc (Qextserialport)

    Hi,

    Sorry about the corrupted zip file, everything is ok this end but most people (including me) find the file copy on the forum corupted (and all my other posts !) - however some persons have reported that they can open the file - still looking into it.

    In the meantime here are my unziped source files (first 5 anyway.

    Regards
    SteveH
    Attached Files Attached Files

  20. #18
    Join Date
    Jan 2009
    Location
    Midlands UK
    Posts
    62
    Thanks
    6
    Thanked 9 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Serial comms on Windows Pc (Qextserialport)

    Here are another 5 files -(some others are limited by forum upload quota)

    I note that the uploading process is still mangaling the file names - can any expert advise on this and why the zip files get corrupted during the upload process ?

    SteveH
    Attached Files Attached Files

  21. #19
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Serial comms on Windows Pc (Qextserialport)

    Your uploaded zips are fine - I can open them all no problem. The problem is probably the extraneous dot '.' in the filename.

  22. #20
    Join Date
    Jan 2009
    Location
    Midlands UK
    Posts
    62
    Thanks
    6
    Thanked 9 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Serial comms on Windows Pc (Qextserialport)

    Hi fatjuicymole,

    Thanks for the update that you can open my posted zip file - for the record, what browser & OS are you using to do it ?

    As to the extra dot in the file name, that is something the forum uploader software is adding, I do not believe it affects reading a zip file. Also, while the uplaoder usually adds a dot, in one case above it added &# instead !

    SteveH

Similar Threads

  1. Installing QextSerialPort on windows
    By gawauter in forum Installation and Deployment
    Replies: 4
    Last Post: 25th December 2011, 06:22
  2. Replies: 16
    Last Post: 7th March 2006, 16:57

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.