Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 47

Thread: serial port programming in qt

  1. #21
    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.

  2. #22
    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.

  3. #23
    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.

  4. #24
    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.

  5. #25
    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

    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.

  6. #26
    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 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 .

  7. #27
    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

    What you did is no good.
    The serial port gets created on the stack, and dies when the constructor ends.
    Use the code I gave you.
    ==========================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. #28
    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:

    Oops. it still not working. This is my code:

    ConnectWidget::ConnectWidget( QWidget *parent, const char *name )
    : QWidget( parent, name),m_note(NULL)
    {
    setBackgroundColor( white );
    setMinimumSize(640,480 );

    m_note= new QextSerialPort("/dev/ttyS0");
    if(m_note)
    {
    m_note->setBaudRate(BAUD115200);
    m_note->setParity(PAR_NONE);
    m_note->setDataBits(DATA_8);
    m_note->setStopBits(STOP_1);
    m_note->open(IO_ReadOnly);
    }
    printf("\n serial port openned \n");
    }

    Is this what you suggested?

  9. #29
    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

    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.
    And please use code tags.
    ==========================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. #30
    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

    Sir,

    I modified the code. Now i have onely three lines in my code:

    Qt Code:
    1. class ConnectWidget : public QWidget
    2. {
    3. public:
    4. ConnectWidget( QWidget *parent=0, const char *name=0 );
    5. private:
    6. QextSerialPort *m_note;
    7. };
    8. ConnectWidget::ConnectWidget( QWidget *parent, const char *name )
    9. : QWidget( parent, name),m_note(NULL)
    10. {
    11. setMinimumSize(640,480 );
    12. m_note= new QextSerialPort("/dev/ttyS0");
    13. printf("\n serialport openned \n");
    14. }
    To copy to clipboard, switch view to plain text mode 

    I have not added the settings of the serial port.As i found that starting from this line the error pops up. the following is the error message:

    suse:/home/qtprograms/roughserial # ./roughserial -qws
    Connected to VFB server: 640 x 480 x 32
    Segmentation fault
    suse:/home/qtprograms/roughserial #

  11. #31
    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 B1,

    DId you experience any segementation problem in creating the serialport in heap like mine ? i tried your way of declaring also ? but i still could not make it ?

  12. #32
    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

    I have not added the settings of the serial port.As i found that starting from this line the error pops up.
    Do you mean that the program crashes on:
    m_note->setBaudRate(BAUD115200); ?

    This code should run.
    How did you discover on which line the program crashes, what method did you use to debug?
    ==========================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.

  13. #33
    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:

    No , the program crashes in the first line itself. i mean :

    m_note= new QextSerialPort("/dev/ttyS0");

    I had only this line in my constructor ( as i had posted in the above post). i did not have any other line.

  14. #34
    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

    I had only this line in my constructor ( as i had posted in the above post). i did not have any other line.
    You mean the only line of code in ConnectWidget constructor right?
    Does it run if you remove that line as well?
    Does it run when this construcotr is empty?
    Are you sure you are not trying to use a 'note' or 'm_note' somehwere else in your code?
    It would be good if you could post you mail() function.
    The problem in your code is not the parts we currently see.
    Ofcourse there is also the chance that the QextSerialPort lib is faulty for some reason on your system.
    ==========================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.

  15. #35
    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

    yeah, it runs if i comment that line and place a printf there.And i'm sure i dont use that anywhere in my code.
    It would be good if you could post you mail() function.
    I have not used any thing like this function .

    Also i'm using qextserialport-0.8.0 package since only this supports qt-3.3.5 version. remaining packages such as qextserialport-0.9.0,1.0,1.1 supports higher versions of qt. will there be any problem with this version changes ?

  16. #36
    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

    I have not used any thing like this function .
    Sorry, I meant main().

    yeah, it runs if i comment that line and place a printf there.And i'm sure i dont use that anywhere in my code.
    Hmm... then from what you have said so far, it all points to a problem in your QextSerialPort lib.
    Also i'm using qextserialport-0.8.0 package since only this supports qt-3.3.5 version. remaining packages such as qextserialport-0.9.0,1.0,1.1 supports higher versions of qt. will there be any problem with this version changes ?
    What do you mean?
    using a Qt4 QextSerialPort with Qt3?
    That wont work.
    ==========================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.

  17. #37
    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

    The following in my main():

    Qt Code:
    1. int main( int argc, char **argv )
    2. {
    3. QApplication a( argc, argv );
    4. ConnectWidget connect1;
    5. a.setMainWidget( &connect1 );
    6. connect1.show();
    7. return a.exec();
    8. }
    To copy to clipboard, switch view to plain text mode 
    What do you mean?
    using a Qt4 QextSerialPort with Qt3?
    That wont work.
    No i mean i'm using qt-3.3.5 version and the other versions of qextserialport requires header and libraries of qt 4 or greater version.

  18. #38
    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

    Well, from what I can see, there is no problem with the code it self.

    You can only link QextSerialPort for Qt3 (which is linked against Qt3) with Qt3 applications.
    You can only link QextSerialPort for Qt4 (which is linked against Qt4) with Qt4 applications.
    ==========================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.

  19. #39
    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

    yeah as you said the code is right. and qextserialport package is used is also correct i think. i mean(for qt-3.3.5 package i used qextserialport-0.8.0 package).

    I think they may have updated these features in the latest versions.And i'm linking qt3 application with qt3 package only.

  20. #40
    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

    And i'm linking qt3 application with qt3 package only.
    That is the way it should be.

    Strange.
    ==========================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.

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.