Monday, 9 September 2013

Async Pro not properly closing com port?

Async Pro not properly closing com port?

I'm porting a few pieces of software to windows 7/8 and have run into a
bit of a snag. The code in question was last updated sometime around 1997,
and is written in C++. One was written in VC++, the other was done in
Borland C++Builder (I'm now using RAD Studio 2009), and uses Async Pro. I
have gotten both projects up to date and building under Win7, and they
work fine separately. Both applications are communicating with a device
that my employer makes, but each collects different data. They have both
been relegated to backend programs called by a Java app.
The problem I am now having is this: The program written in VC++ is able
to communicate with the device with no problems until I run the program
written using Borland/Async Pro. After that, it can successfully open the
port, and I see the activity LED on the TX light up, but the application
doesn't actually talk to the device. At this point, the Async Pro
application, Tera Term, and the Java application are all able to
communicate with device on the same port. If the port I'm using is a
USB-Serial bridge, I can unplug it and restore the functionality of the
VC++ application. Cycling power on the device to which I'm attempting to
talk does nothing.
Below is the VC++ code that opens the com port. As far as I have been able
to tell, this is how you're supposed to open COM ports in VC++.
std::ostringstream comCatString;
comCatString << "\\\\.\\COM" << (int)CommPort;
// Try to open the serial port.
hPort = CreateFile( TEXT(comCatString.str().c_str()),
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL);
if ( hPort == INVALID_HANDLE_VALUE )
{
//clear strstream
comCatString.str("");
comCatString.clear();
comCatString << "Unable to open serial port " << (int)CommPort << ".
\r\nError: " << GetLastError();
MessageBox (NULL, TEXT(comCatString.str().c_str()), TEXT("Error"),
MB_OK);
return FALSE;
}
And here is the code that's closing the com port from the AsyncPro app:
ApdComPort->Open = false;
ApdComPort->DonePort();
I have spent most of the afternoon searching on Google and StackExchange,
and haven't really found anything that's quite like this issue. It seems
like the issue most people have is that their Async Pro application will
hang on port closure.
I've suspected both the VC++ and the Async Pro applications, but I don't
know which is actually the problem because:
the VC++ app works when I haven't run the Async Pro applicaton, and
The other applications I've tried seem to work fine after the Async Pro
application runs.
I have also suspected that the target device is being left in some sort of
weird state by the Async Pro application, but cycling the power on it
should have resolved that.
Am I doing something wrong here? Is there something else I should test, or
some sort of finalization or initialization code that's missing? Something
that worked OK in XP and earlier versions of Windows, but has been fixed
or removed?
I have yet to try running either of these applications on Windows 8, as my
development machine is Windows 7. Are there any further gotchas I should
watch out for when I head that direction?
Thanks!
Edit: This happens when the port in question is an FT232 or the serial
port in my laptop dock.

No comments:

Post a Comment