Results 1 to 20 of 47

Thread: serial port programming in qt

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: serial port programming in qt

    Why are you commenting out these lines? with out them you don't have an initialized serial port objet.
    Also, QextSerialPort is made crossplatform, so you don't need to explicitly use Posix_QextSerialPort (this wont compile under windows) - there are defines in the code that will select the correct version for you.
    Just use QextSerialPort.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  2. #2
    Join Date
    Dec 2006
    Posts
    123
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: serial port programming in qt

    high_flyer:

    if i use QextSerialPort instead of Posix_QextSerialPort, it shows me the following error:

    home/qtprograms/qwt/qextserial/qextserialport-0.8.0/win_qextserialport.h:11:21: error: windows.h: No such file or directory
    /home/qtprograms/qwt/qextserial/qextserialport-0.8.0/win_qextserialport.h:57:7: warning: no newline at end of file
    In file included from tux.cpp:21:
    /home/qtprograms/qwt/qextserial/qextserialport-0.8.0/qextserialport.h:26:7: warning: no newline at end of file
    /home/qtprograms/qwt/qextserial/qextserialport-0.8.0/win_qextserialport.h:50: error: ‘HANDLE’ does not name a type
    /home/qtprograms/qwt/qextserial/qextserialport-0.8.0/win_qextserialport.h:51: error: ‘COMMCONFIG’ does not name a type
    /home/qtprograms/qwt/qextserial/qextserialport-0.8.0/win_qextserialport.h:52: error: ‘COMMTIMEOUTS’ does not name a type
    make: *** [tux.o] Error 1
    .
    So only i used Posix_QextSerialPort. Should i define somewhere about _TTY_POSIX ? Also as i said before when i include them in my code its prompting me segmentation fault.

  3. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: serial port programming in qt

    So only i used Posix_QextSerialPort. Should i define somewhere about _TTY_POSIX ?
    Exactly - You should add DEFINES += _TTY_POSIX in your pro file (or if you are using KDevelop it has a field for that in the qmake configuration).
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  4. #4
    Join Date
    Dec 2006
    Posts
    123
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: serial port programming in qt

    high_flyer:

    that parameter has already been set when i untar the qextserial package. should i specify that in my application pro file ?

    Let me explain what i have done so far :

    1). Downloaded the qextserial package , untarred and entered qmake ,make. there were the following libraries created:
    libqextserialport.so libqextserialport.so.1 libqextserialport.so.1.0 libqextserialport.so.1.0.0

    2). Then created a directory ,copied my source files. entered the header files and the libraries for qextserial in my project file. then entered make.

    is this procedure correct ? else can you say me the correct one ?

  5. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: serial port programming in qt

    should i specify that in my application pro file ?
    yes.
    is this procedure correct ? else can you say me the correct one ?
    It should work.
    But I would not copy the header files and libs, I would link to them or user the -L and -I in my make file.
    But that is a subjective private taste matter, your way should work just as well.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  6. #6
    Join Date
    Dec 2006
    Posts
    123
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: serial port programming in qt

    hi ,

    i specified in my project file also and it compiled successfully.but still the same error comes . Is there any permission i need to set to serial port ? i'l post my full code here if any one find any error please point me :

    Qt Code:
    1. #include <qwidget.h>
    2. #include <qapplication.h>
    3. #include <stdlib.h>
    4.  
    5. #include <qextserialport.h>
    6.  
    7. class Widget : public QWidget
    8. {
    9. public:
    10. Widget( QWidget *parent=0, const char *name=0 );
    11. private:
    12. int mouse;
    13. int mouseidx;
    14. };
    15.  
    16. Widget::Widget( QWidget *parent, const char *name )
    17. : QWidget( parent, name)
    18. {
    19. setMinimumSize(640,480 );
    20.  
    21. QextSerialPort *note= new QextSerialPort("/dev/ttyS0");
    22. note->setBaudRate(BAUD115200);
    23. note->setParity(PAR_NONE);
    24. note->setDataBits(DATA_8);
    25. note->setStopBits(STOP_1);
    26. note->open(IO_ReadOnly);
    27. }
    28.  
    29. int main( int argc, char **argv )
    30. {
    31. QApplication a( argc, argv );
    32. Widget connect1;
    33. a.setMainWidget( &connect1 );
    34. connect1.show();
    35. return a.exec();
    36. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by high_flyer; 7th May 2007 at 10:54. Reason: missing [code] tags

  7. #7
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: serial port programming in qt

    compiled successfully.but still the same error comes .
    I guess you mean the segmentation fault.

    Your code has the following problems:
    Qt Code:
    1. QextSerialPort *note= new QextSerialPort("/dev/ttyS0");
    To copy to clipboard, switch view to plain text mode 
    You are allocating the serial port on to a local pointer.
    You will not be able to access the serial port outside the constructor.
    'note' needs to be a member variable.

    Where is the code that handels the reading/writing to the serial port?

  8. #8
    Join Date
    Dec 2006
    Posts
    123
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: serial port programming in qt

    theLSB:
    I did not add the read/write operation. i thougth first let me open the port sucessfuly. then,read that.

    'note' needs to be a member variable
    Do you mean that i need to declare it under protected and use it in the constructor ?

  9. #9
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: serial port programming in qt

    Do you mean that i need to declare it under protected and use it in the constructor ?
    No, you need to declare it as a member variable.
    Do you know what a member variable is?
    Qt Code:
    1. class Widget : public QWidget
    2. {
    3. private: //depends on your needs, this can be any access mode
    4. QextSerialPort *m_note;
    5. public:
    6. Widget( QWidget *parent=0, const char *name=0 );
    7. private:
    8. int mouse;
    9. int mouseidx;
    10. };
    11.  
    12. Widget::Widget( QWidget *parent, const char *name )
    13. : QWidget( parent, name),
    14. m_note(NULL)
    15. {
    16. setMinimumSize(640,480 );
    17.  
    18. m_note= new QextSerialPort("/dev/ttyS0");
    19. if(note)
    20. {
    21. m_note->setBaudRate(BAUD115200);
    22. m_note->setParity(PAR_NONE);
    23. m_note->setDataBits(DATA_8);
    24. m_note->setStopBits(STOP_1);
    25. m_note->open(IO_ReadOnly);
    26. }
    27. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by high_flyer; 7th May 2007 at 13:46.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  10. #10
    Join Date
    Dec 2006
    Posts
    123
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: serial port programming in qt

    high_flyer:

    yeah i did as you said. i tried both the ways-private or protected. But no use.

  11. #11
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: serial port programming in qt

    But no use.
    Could you be a bit more descriptive?
    The access mode has nothing to do with it.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  12. #12
    Join Date
    Dec 2006
    Posts
    123
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: serial port programming in qt

    first i tried declaring the Qextserialport as a private member variable, compiled and when i rum the same error came. next i tried declaring it as protected member variable, the same thing happened.

Similar Threads

  1. Serial Port communication
    By mgurbuz in forum Qt Programming
    Replies: 12
    Last Post: 22nd January 2011, 02:38
  2. First attempt to display serial port data on GUI
    By ShaChris23 in forum Newbie
    Replies: 12
    Last Post: 4th May 2007, 09:14
  3. Replies: 12
    Last Post: 23rd March 2007, 09:23
  4. Serial Port access in Qt
    By Doug Broadwell in forum Newbie
    Replies: 2
    Last Post: 18th October 2006, 21:03
  5. Replies: 16
    Last Post: 7th March 2006, 15: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
  •  
Qt is a trademark of The Qt Company.