jiuzhuaxiong / qextserialport

Automatically exported from code.google.com/p/qextserialport
Other
0 stars 0 forks source link

win32 Change Baud bug #73

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hey,
hello every one. i started to write a Program in QT for a serial communication 
on win xp. it works fine, until i checked the data incoming. I tried a lot to 
find this problem until i use my old tool for this communication and i got the 
correct data. i started my new qt program and got the correct data. after my 
old program change the settings for the com port. i tried to change the baud 
rate with the new program and it didn't work, i got still the correct data.
the syntax of my program is like this:
Setting up the port,
open the port,
poll this port for data. 
my open-port funktion:

QextSerialPort myserial;
    myserial->setPort("COM1"); //Port
    myserial->setBaudRate(BAUD9600); //BaudRate
    myserial->setDataBits(DATA_8); //DataBits;
    myserial->setParity(PAR_NONE); //Parity
    myserial->setStopBits(BIT_1); //StopBits
    myserial->setFlowControl(FLOW_NONE); //FlowControl
    myserial->setTimeout(0,10);
    myserial->open();

i debug this program to the end of the open method and i found the bug. 
In file win_qextserialport.cpp methos setBaudRate()line 744 there is a if issue 
for QIODevice::isOpen? if we got a true, we are goinge to set up this change in 
a variable "Win_CommConfig.dcb.BaudRate"
but this will never happen. in the method Win_QextSerialPort::open(OpenMode 
mode) line 175, we are calling setBaudRate() before the IODevice::open() method 
is called. that's why the settings are ignored. 

with kind regards
Konstantin.

Original issue reported on code.google.com by seth...@web.de on 24 Aug 2010 at 12:48

GoogleCodeExporter commented 8 years ago
i use following patch to fix this issue.

--- win_qextserialport.cpp  Thu Sep  6 00:47:20 2007
+++ win_qextserialport-patched.cpp  Mon Sep 20 17:11:27 2010
@@ -187,6 +187,7 @@
         Win_Handle=CreateFileA(port.toAscii(), GENERIC_READ|GENERIC_WRITE,
                               FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, dwFlagsAndAttributes, NULL);
         if (Win_Handle!=INVALID_HANDLE_VALUE) {
+        QIODevice::open(mode);
             /*configure port settings*/
             GetCommConfig(Win_Handle, &Win_CommConfig, &confSize);
             GetCommState(Win_Handle, &(Win_CommConfig.dcb));
@@ -216,11 +217,11 @@
                if (!SetCommMask( Win_Handle, EV_TXEMPTY | EV_RXCHAR | EV_DSR)) {
                    qWarning("Failed to set Comm Mask. Error code: %ld", GetLastError());
                    UNLOCK_MUTEX();
+           QIODevice::close();
                    return false;
                }
                overlapThread->start();
             }
-           QIODevice::open(mode);
         }
     } else {
        UNLOCK_MUTEX();

Original comment by maxillus...@gmail.com on 22 Sep 2010 at 3:30

GoogleCodeExporter commented 8 years ago
Thanks

Original comment by dbzhang...@gmail.com on 16 Mar 2012 at 8:15