|
-
May 5th, 2011, 11:31 AM
#1
SetCommState Problem
I am using Qt with the mingw compiler.
I'm having a problem with the SetCommState function from the Windows API.
It seems like any time I run SetCommState, it will get itself into an infinite loop. The program eventually crashes, and checking the call stack shows hundreds of calls into SetCommState.
However, if another program, such as PuTTy or a program compiled in Visual Studios opens the COM port first, then my program will work.
Even this simple program will reproduce the problem.
Code:
#include <QtCore/QCoreApplication>
#include <windows.h>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
DCB dcb;
HANDLE com = CreateFileA("COM5", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
if (com == INVALID_HANDLE_VALUE)
{
qDebug("Invalid handle");
return -1;
}
qDebug("GetCommState");
GetCommState(com, &dcb);
qDebug("SetCommState");
SetCommState(com, &dcb); // <-- infinite loop here
qDebug("Done.");
return a.exec();
}
Is this somehow because I am using mingw?
-
May 5th, 2011, 12:09 PM
#2
Re: SetCommState Problem
 Originally Posted by jnmacd
...
Is this somehow because I am using mingw?
Perhaps...
Because it never happens if using MS IDE (any version)
Victor Nijegorodov
-
May 5th, 2011, 12:23 PM
#3
Re: SetCommState Problem
What happens if you exclude all Qt-related code from this program?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|