PDA

View Full Version : serial communication



klitsuk
10th March 2009, 15:08
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

^NyAw^
10th March 2009, 15:58
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...).

^NyAw^
12th March 2009, 09:18
Hi,

Have you tried to set the port properties directly to windows driver?
I can't try now but maybe it can be helpful.

Rudobrody
12th March 2009, 14:10
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...

^NyAw^
12th March 2009, 14:58
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.

SteveH
12th March 2009, 17:35
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.

^NyAw^
12th March 2009, 17:39
Hi,

Will try it.

If someone can try QextSerialPort 1.2Alpha and test if the reciver is getting incorrect data will be helpful

^NyAw^
12th March 2009, 18:28
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.

:)

SteveH
12th March 2009, 19:29
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.

^NyAw^
1st April 2009, 08:59
Hi klitsuk (http://www.qtcentre.org/forum/u-klitsuk-11064.html),

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:


setBaudRate(Settings.BaudRate);
setDataBits(Settings.DataBits);
setStopBits(Settings.StopBits);
setParity(Settings.Parity);
setFlowControl(Settings.FlowControl);
setTimeout(Settings.Timeout_Millisec);


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.

crosswalkguy
24th September 2009, 01:21
Simply change the baud rate after the port is opened. Works for me. No need to change the library.



if (!SerialPort->open(QIODevice::ReadWrite)) cout << "unable to connect to serial port" << endl;
else {
SerialPort->setBaudRate(BAUD4800);
// other serial port settings
}


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