LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

cannot open port

I recently updated to CVI version 6.0 from 5.5 and have since been getting the RS232 error "cannot open port" when trying to OpenCom on my com1. I've noticed that if I have another program open that is using COM1 (i.e. a terminal emulator) during the initial startup of my s/w, then close the terminal emulator, and thus closing the com port, I can then successfully open my com port. Also, I have a PCMCIA 4-serial-port card installed that are assigned to com ports 4 thru 7. If I open one of these other ports before opening Com1, it usually works. Once I receive this RS232 error, I have to restart Win2K from the beginning (logging off and back on doesn't do the trick).

I have tried to CloseCom at the time my s/w starts up in case the system thinks it's
open, and have tried to GetComStatus(), but the system thinks the port's closed.

The device manager shows no conflicts. I have tried uninstalling and reinstalling Com1 in case the driver was corrupted - no luck. This is a serious problem and one that just surfaced after changing over to ver 6.0. Any help would be appreciated.
0 Kudos
Message 1 of 4
(4,385 Views)
Are you sure that no other applications have locked COM1 by opening it before your application? Have you been able to reproduce the same behavior on other machines? Really, all CVI does is try to obtain the port from the Window's serial driver just like any other application would, and there is little room for error in how this works. The installation of CVI 6.0 really has no way of altering this behavior and works exactly the same as it did in previous versions. I would be willing to bet that either something has changed with your OS, another application is hindering the process, or just a general hardware failure is occurring. Nonetheless if it is a problem with our RS232 library we would be more than happy to try to get to the bottom of this. If you can prod
uce some sample code that reliably reproduces the problem as well as a very thorough system description for us, you can send in a support email request via www.ni.com/ask and we will try to reproduce the issue in house.

Jason F.
Applications Engineer
National Instruments
www.ni.com/ask
0 Kudos
Message 2 of 4
(4,385 Views)
Thanks for the response. I actually finally found the problem. I had the same thought that the upgrade should not be the problem here. But it happened right about the same time. I have worked on this problem for about a month, and two hours after I left a message here, I figured it out. But I'm not sure that I understand it.

In my global variable declarations above my main(), I had the following:

char gszComPortStrings[8][8] = {"COM1","COM2","COM3","COM4","COM5","COM6","COM7","COM8"};

This is used for the OpenCom() functions so that I could use an index to determine the proper Com Port string. To fix the problem, I removed the assignment/initialization in this line and initialized in a simple for loop with a Fmt() function inside main().

i
.e. char gszComPortStrings[8][8];

main()
{
int i;
for (i=0; i<8; i++)
Fmt(gszComPortStrings[i], "%s
...
}

Now I can't reproduce the problem. How is the original assignment illegal?
0 Kudos
Message 3 of 4
(4,385 Views)
It's not, both of your code samples do about the same thing just in different ways. You should really be careful with initializing static strings like that though, because if you ever do change the value of those character pointers the handle to those strings will be lost forever and can cause a memory leak. If you try the following code you can see that your initial way of doing things works fine as well, therefore it must not be the real cause of the problem.

#include
#include

char gszComPortStrings[8][8] = {"COM1","COM2","COM3","COM4","COM5","COM6","COM7","COM8"};

int main (int argc, char *argv[])
{
int i = 0;

if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */

for (i=0;i<8;i++) {

printf("%s\n", gszComPortStrings[i]);
}
getchar();

return 0;
}

Jason F.
Applications Engineer
National Instruments
www.ni.com/ask
0 Kudos
Message 4 of 4
(4,385 Views)