Results 1 to 11 of 11

Thread: serial communication

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

    Default serial communication

    Hi all,

    i got my qt and mfc programs talking via the com port. (using the infamous qextserial...)

    one probelm though is that the qt side has a difficulty modifing the properties of the comp port.

    i need to use 9600, no parity, 8 , 2 stop, no flow.

    i configure my port with these setting but for some reason the connection cannot be made.
    to fix this, i open the windows hyperterminal, make a new connection with my settings and then close the connection, my qt application is working fine.
    whenever i reboot my computer the connection is lost again and i have to configure a new connection trhough the terminal, disconnect the connection and open the qt connection to work again.

    i've tried this trick on qestserial... example on both sides and i get this problem as well.

    does someone knows what i'm talking about and maybe how to fix this ?
    can someone post a working example please (and not point me the qestserial..)
    thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    69
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: serial communication

    Hi,

    I have the same problem using QextSerialPort 1.2Alpha and EventDriven behaviour.

    I'm able to open the port but when sending data, the receiver recives invalid data (00 00 00...).
    Last edited by ^NyAw^; 10th March 2009 at 16:46.
    Òscar Llarch i Galán

  3. #3
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    69
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: serial communication

    Hi,

    Have you tried to set the port properties directly to windows driver?
    I can't try now but maybe it can be helpful.
    Òscar Llarch i Galán

  4. #4
    Join Date
    Mar 2009
    Location
    Poland
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: serial communication

    Quote Originally Posted by ^NyAw^ View Post
    Hi,

    I have the same problem using QextSerialPort 1.2Alpha and EventDriven behaviour.

    I'm able to open the port but when sending data, the receiver recives invalid data (00 00 00...).
    Use QExtSerialPort 1.1 ... , check transmission parameters on sender and receiver...

    and take code with problems...

  5. #5
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    69
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: serial communication

    Hi,

    I'm using 1.2Alpha version because "readyRead" SIGNAL can be used.
    Using version 1.1 has to use a timer to read data and you have to calculate the timer interval depending on baud rate. Using version 1.2Alpha let's you use "eventDriven" behaviour that sends "readyRead" SIGNAL.
    Òscar Llarch i Galán

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

    Hi,

    I've been developing a comport program for Qt on windows as a means of learning Qt. If you want to give it a try as an alternative to qextserialport the files are attached to this post. The readyRead signal is working and all the port parameter change functions are in place and there's a popup user dialogue to allow changes to the port, it's still a work in progress but let me know if it solves your problems. Note, the style is still a bit odd as i'm going through the change from Borland to Qt.
    Attached Files Attached Files

  7. #7
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    69
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: serial communication

    Hi,

    Will try it.

    If someone can try QextSerialPort 1.2Alpha and test if the reciver is getting incorrect data will be helpful
    Òscar Llarch i Galán

  8. #8
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    69
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: serial communication

    Hi,

    I have been taking a look to your WinComPort project.
    I recommend you to separate the serial port behaviour and the GUI.
    WinComPort is a QWidget and if I want to use it I will always need the widget. Instead of this, generate a class that manages the serial port communication where you can set the baud rate, stop bits, ... and then, other users can create their own widgets to configure the port or use it without any widget.

    Òscar Llarch i Galán

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

    Hi,

    I did originaly write the gui as a seperate widget but it ment that the parent widget of the port and the gui had more work to do, once I'm satisfied that the port widget functions ok I'll look again at seperating the two parts. At the moment I'm trying to write a non-blocking version with intermediate buffers in the port widget and a seperate thread so read & write functions return immediately and the thread handles the interface with windows api's.

  10. #10
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    69
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: serial communication

    Hi klitsuk,

    Yesterday I have been playing with QextSerialPort and finally get a solution to the connection problem.
    I can't explain the reason because I had no time to know why it was really not working.
    Open "win_qextserialport.cpp" and take a look at "open" method:
    Qt Code:
    1. setBaudRate(Settings.BaudRate);
    2. setDataBits(Settings.DataBits);
    3. setStopBits(Settings.StopBits);
    4. setParity(Settings.Parity);
    5. setFlowControl(Settings.FlowControl);
    6. setTimeout(Settings.Timeout_Millisec);
    To copy to clipboard, switch view to plain text mode 

    If you take a llok at this methods there is a check "if (isOpen())" that checks if the port is opened, so if it is not opened the method don't changes the BaudRate,DataBits, ...

    Try commenting the line containing "if (isOpen())" in the methods above.
    Òscar Llarch i Galán

  11. #11
    Join Date
    Sep 2009
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: serial communication

    Simply change the baud rate after the port is opened. Works for me. No need to change the library.

    Qt Code:
    1. if (!SerialPort->open(QIODevice::ReadWrite)) cout << "unable to connect to serial port" << endl;
    2. else {
    3. SerialPort->setBaudRate(BAUD4800);
    4. // other serial port settings
    5. }
    To copy to clipboard, switch view to plain text mode 

    Thanks for pointing out the "if port open" statement Ã’scar. This is what lead me to this fix. I too found that if I opened the port with Putty first at the right baud rate it would work.

    Matthew Currie
    Nanaimo, BC Canada

Similar Threads

  1. serial communication
    By semden in forum Qt Programming
    Replies: 2
    Last Post: 13th February 2009, 09:57
  2. serial communication problem
    By Tavit in forum Qt Programming
    Replies: 3
    Last Post: 31st May 2008, 12:56
  3. serial communication programming
    By jagadish in forum Qt Programming
    Replies: 1
    Last Post: 30th August 2007, 07:47
  4. C++ Library for serial communication
    By dec0ding in forum General Programming
    Replies: 7
    Last Post: 8th July 2007, 18:18
  5. How to transfer file through serial communication
    By shamik in forum Qt Programming
    Replies: 29
    Last Post: 29th May 2007, 10:22

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.