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.
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,
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);
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.
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.
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.