Thank you for the replay. I guess the operator has to be involved in the selection. My desire is to have LV detect available com ports and select itself without operator involvement. Is it possible ?
3 stars?? I'd rather have you not rate the post at all
In order to do an auto select, you will have to have a way to query the instrument and find out if it exists on that com port.
You can create a loop that concatenates "Com" with a number to create a string such as Com1, Com2, ... as high as you need to check and feed that string into the VISA resource. Write your query, read the response. If you get a valid response then you can stop the loop and you know what your Com port is and use that later in the program. If you get an error or an invalid response, repeat the loop incrementing to the next Com port. Create an upper limit of possible com ports (such as com8) so that if the device fails to respond (such as if it got disconnected), the loop won't run endlessly. Have the loop stop and raise an error saying the device is not connected.
Let me throw out another option that is less automatic.
Com1, Com2, etc. are aliases. If the program uses constants, when the pc is configured with serial ports, the aliases can be renamed to match what the program wants. For example, if you add new ports (pci, usb, whatever) and they show up in MAX as Com3 and Com4, you can rename them Com1 and Com2. You can even name them something more meaningful such as the instrument name they are connected to. Your program could have constants such as DMM, Counter, whatever. This approach will require a bit of setup up front but less coding would be required.
Thank you all,
These are all good ideas to try out. I'll try them out and let you know which one works best for my case!
This is a program I wrote a while ago that detects all COM ports that are in use, sends out a test message, and if it gets the correct response it will send out the VISA info of the COM port that worked. It's a debug version so it's not the cleanest code, but it worked.