I accidently posted this question in the Digital I/O section, so I am reposting it here in hopes more people will see it...
I am having an issue with my COM port setup that I believe is related to the current Session ID and selected COM port in the VISA Resource Name session.
I am developing a utility that allows a user to pick any number of specific USB devices connected to the computer. I do this by reading specific values in the computer's registry and pulling active COM port values for those devices. Once I determine the active devices, I allow the user to select the COM port of the device that they wish to use, and then this COM port string value is written to an .ini file that is read from before my VI runs. This is how the VISA sessioin knows what COM port to use. I want this process to be dynamic because different computers will assign the COM ports differently, so hard coding the COM ports is not an option.
A problem occurs if multiple devices are connected to the computer and an alternate COM port is selected each time the program is run. Let's say that a user starts the VI from scratch. They have the option to select a device on either COM port 4 or 5. Let's say they pick the device on COM4. COM4 is used to open a VISA session. Let's assume the Session ID is 0x9EEAF68 for this VISA session.
If the user realizes the device on COM4 is not the device they want, they can stop the program and restart it. Once again, they will be asked to select COM 4 or 5. This time the user selects COM5. The problem is the Session ID may or may not keep the value of 0x9EEAF68 (95% of the time it keeps the same session ID). If the VISA session changes the Session ID value to something other than 0x9EEAF68 then no errors will occurs when a VISA write happens. However, most of the time, the old Session ID is used. When the old Session ID is used, the first time there a VISA read occurs the VISA Read will give an error of -1073807252. After this, the old session ID is now associated with COM5 and the error will not happen again.
I have noticed if the Session ID changes to a different ID value then this error will not occur, even if a different COM port is selected.
When the COM port string is read out of the initialization file, I had connected it to a VISA session indicator of class Instr. Connecting the string to this indicator causes a coercion dot (clearly...). This VISA session indicator is what is then connected to the VISA Open block. Since I was sloppy and let the coercion dot do the "work" for me, could this be the source of the problem?
Also, I open only one VISA session and I close that VISA session when the program stops.
Any other ideas on how to force a new Session ID in VISA so this error is not an issue in my application?
I am using NI-VISA version 4.3 and LabVIEW 8.5.
Thanks in advance.