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
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    21
    Thanked 418 Times in 411 Posts

    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.

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

    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 ?

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

    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.

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

    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

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

    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?

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

    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 ?

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

    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.

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

    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.

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

    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.

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

    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.

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

    Default Re: serial port programming in qt

    what error? segmentation falut?
    Are there any other methods do the Widget class?
    Try setting debug messages along the code or run in a debugger and see where the applciation crashes.

    EIDT:
    Wait, in the code I edited for you, your should change all 'note' instances to 'm_note' did you do that?
    ==========================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
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: serial port programming in qt

    Hi,

    i solved that problem. i did not declare it in the heap.The following is what i did:
    Qt Code:
    1. QextSerialPort note("/dev/ttyS0");
    2. note.setBaudRate(BAUD115200);
    3. note.setParity(PAR_NONE);
    4. note.setDataBits(DATA_8);
    5. note.setStopBits(STOP_1);
    6. note.open(IO_ReadOnly);
    To copy to clipboard, switch view to plain text mode 
    With this the application opens without segmentation fault. Now i'm finding out how to read the datas ? the suggestion b1 gave did not work out as there is no member function called read in the Qextserialport.

    Anyway thanks a lot for all of your kind response .

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.