LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Check com port

Is there a way to see if a com port exists? I read from rs-232 ports and only get a non-fatal runtime error if it does not exist but it would be nice to be able to check if it exists so I don't even get the non-fatal error.
0 Kudos
Message 1 of 17
(10,836 Views)
If you use VISA ressources to manage RS232 ports, you can use:
viFindRsrc on your serial port ressource (ex: ASRL4::INSTR).
(Using VISA functions instead of RS232 functions is a bit more complicated to start with.
Anyway downloading VISA Interactive Control from NI can help.)
Regards,
0 Kudos
Message 2 of 17
(10,807 Views)
To handle non-fatal runtime errors in your code (rather than getting the dialog box), you can use SetBreakOnLibraryErrors.

int previousBreak;
// disable break and store previous break state
previousBreak = SetBreakOnLibraryErrors(0);
// do the stuff in your code where you expect to get a library error
// ...
// restore the previous break state
SetBreakOnLibraryErrors(previousBreak);
0 Kudos
Message 3 of 17
(10,793 Views)
Thanks guys. I'll look into both of those options to see which one will work with my program the best.
0 Kudos
Message 4 of 17
(10,796 Views)
Question for you all along the lines of stopping non-fatal runtime error breaks,

An Example:

int fooFunction(void)
{
char *foo

DisableBreakOnLibraryErrors(0);
free (foo);
DisableBreakOnLibraryErrors(1);
}

When I run this code it will still break the program twice (in debug mode) because referencing unitilized variables is a non-fatal runtime error as well as freeing an uninitilized pointer. However neither of these are CVI library errors.

Is there some setting that I am not enabling that allows the SetBreakOnLibraryErrors to disable these non-CVI-library and also non-fatal runtime errors?

Yes, yes I know I shouldn't have errors such as this in my app anyway, but sometimes it would be easier to leave them when I'm first designing an application and just turn off the error messages until I'm ready to deal with them.
Message 5 of 17
(10,778 Views)
We have a DLL that can locate all the available COM ports, or check whether a particular port exists. I'm quite willing to post it here if you think it would be useful.

Martin.
--
Martin
Certified CVI Developer
Message 6 of 17
(10,775 Views)
Such a DLL is very useful. Please post it.
Regards,
0 Kudos
Message 7 of 17
(10,774 Views)
The attached Zip has the following files:

locatecom.dll
locatecom.h - header file for the DLL (includes some documentation)
locatecom.lib - import library
FindPort.c - example program demonstrating use

It also includes the relevant source code for the DLL in locatecom.cpp (it was built in VC++6).

We developed it originally as a handy way of locating virtual comms ports by name.

Martin.
--
Martin
Certified CVI Developer
Message 8 of 17
(10,781 Views)
Thanks you for the DLL.
Regards
Message 9 of 17
(10,767 Views)
I would also like to thank you for those zipped files, very easy to use and works great.
Message 10 of 17
(10,750 Views)