From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Auto-detect new VISA connection

Solved!
Go to solution

I am constantly working with new USB devices (Adapters to CAN/RS/SPI...) on various computers.

To my knowledge, that makes it impossible to easily* recognise them in Labview if you haven't renamed them in NI max beforehand.... which, in my experience has caused issues (for some reasons, a motor controller connected via USB had the same COM port (and so alias I created) than an adapter... that was a mess)

*For now we either have to open the device manager and unplug/replug the device to see to which com port it has been associated OR do the same in NI Max...

 

I got annoyed by that and started to find a solution for a "New device auto-detection" and I couldn't find any on this forum, so I've made my own and I'm sharing it here.

I'm sure there are better solutions, and I'm happy to see yours 🙂

My idea was, either by use of a keyboard shortcut, or constantly in the background to call this VI which uses the Find VISA ressources in loop, and checks if the table created between two iterations have changed or not.

 

The thing is, because Find VISA ressources.vi is auto-sorting the ressources found (if the devices ASRL11 is connected after ASRL12, it will still appear before in the table), a simple "Not Equal" differenciation would not work, so I came up with this double FOR loop checking every elements of both arrays (the new array and the previous one) between each others. And the VI stops as soon as one element in the new was not found in the old.

 

Auto-Detect new VISA connection.png

This can be adapted to be more flexible (detecting all types of instruments and not only serial ones for instance), but again, I'm mostly working with serial adapters.

 

I'm sure there is another way: Windows does auto-detect a new connection. So there must be a way somehow to setup an event based on Windows interruptions, no? 

 

In any case, if you were looking for a solution, I hope you'll like this one 🙂

-Vinny

Download All
Message 1 of 13
(2,028 Views)

Could you save it for 2019 please?

 

EDIT: Nvm, didn't see you added 2015 in the original post

------------------------------------------------

 

I've been thinking about making something like this, because currently the device i'm working with uses 3 USB connections and port for each has to be manually checked in device manager and then written to config file. Luckily windows remembers the configuration so this only has to be done once (unless you switch sensors or machines).

I would go a step further than checking ports tho, i'd have to send a data packet to each sensor and check if response is viable.

0 Kudos
Message 2 of 13
(2,026 Views)

A slight tweak I would make: You can replace your innermost FOR loop with a Search 1D Array.

 

I have had to do something similar and here is the VI I made to do the detection.  This basically replaces the code inside of your loop as I used "Filtered Ports" as the list of ports that were found before I did something (in my exact case, turn on a UUT that then showed up as a COM port).  I also had to make sure it was a COM port because I had issues with the parallel port also showing up.  This does require that nobody change alias names in MAX as I depend on the default alias names for serial ports (COM%d).


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 3 of 13
(2,012 Views)

@crossrulz  a écrit :

A slight tweak I would make: You can replace your innermost FOR loop with a Search 1D Array.

 


For some reason I can't find such Search 1D array ... I was sure it would exist, but even after double checking, I still can't find it... but only the "Search 1D sorted Array.vim" which didn't worked as it requires a class as input ?!?

 


@crossrulz  a écrit :

This does require that nobody change alias names in MAX as I depend on the default alias names for serial ports (COM%d).


Yes exactly, that's why I preferred to work with the cannonical names which, if I'm not wrong, are fully unique on a specific machine, right?

And as I was exploring the aliases in the past, some devices are now named, and some others not. For some reason there is a difference in labview between COM ports and Canonical names: Devices can have the same COM port, but not the same Canonical name (in my experience, but I could've made some mistakes.)

0 Kudos
Message 4 of 13
(1,985 Views)

@AeroSoul  a écrit :

 

EDIT: Nvm, didn't see you added 2015 in the original post

yes I thought that 2015 would be old enough for most people 🙂

 


@AeroSoul  a écrit :

I would go a step further than checking ports tho, i'd have to send a data packet to each sensor and check if response is viable.


Agreed, but then it is very specific to each and everyone cases 🙂 I just wanted something that I could re-use in all my programs, that gives me a Ressource name that I can directly link to Open VISA 🙂
If the device doesn't communicate properly, then it means that I've either connected the wrong one (not that it never happened 🙄, this made me go crazy a few times...); the device is broken; or the drivers are not installed on the computer. At least in my case 🙂

0 Kudos
Message 5 of 13
(1,982 Views)

Hi Vinny,

 


@VinnyAstro wrote:
For some reason I can't find such Search 1D array ... I was sure it would exist, but even after double checking, I still can't find it... but only the "Search 1D sorted Array.vim" which didn't worked as it requires a class as input ?!?

You are working with LV2020SP1? NI decided to hide that primitive function in favor of that VIM…

 

Btw. you could just remove the inner FOR loop and still get the same result! (Polymorphism…)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 13
(1,975 Views)

Yep I am.

 

That explains a lot:

1D array.pngerror.pngArray palette.png

 

But again, I've tried to connect my array of string to the vim one, and I had a broken wire. It's only by opening it and manually changing the inputs that it worked out... I quite don't get how .vim work yet 🙂

 

 

 

0 Kudos
Message 7 of 13
(1,966 Views)

@VinnyAstro wrote:

@crossrulz  a écrit :

A slight tweak I would make: You can replace your innermost FOR loop with a Search 1D Array.

 


For some reason I can't find such Search 1D array ... I was sure it would exist, but even after double checking, I still can't find it... but only the "Search 1D sorted Array.vim" which didn't worked as it requires a class as input ?!?

 



Both of the inputs have to be similar datatype for it to work (need to wire both):

Spoiler
FireFistRedhawk_0-1630504498697.pngFireFistRedhawk_1-1630504511041.png

 

 

Redhawk
Test Engineer at Moog Inc.

Saying "Thanks that fixed it" or "Thanks that answers my question" and not giving a Kudo or Marked Solution, is like telling your waiter they did a great job and not leaving a tip. Please, tip your waiters.

Message 8 of 13
(1,962 Views)

@VinnyAstro wrote:

@crossrulz  a écrit :

A slight tweak I would make: You can replace your innermost FOR loop with a Search 1D Array.


For some reason I can't find such Search 1D array ... I was sure it would exist, but even after double checking, I still can't find it... but only the "Search 1D sorted Array.vim" which didn't worked as it requires a class as input ?!?


You might want to give this thread a good read: Search 1D Array ... Changed in 2020 SP1 .  There is a VI somewhere in there you can run to make the primitive show up in the palettes.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 9 of 13
(1,956 Views)
Solution
Accepted by topic author VinnyAstro

Here is an updated version 🙂

A LV16 version is also enclosed using Search 1D Array.vi instead of Search sorted 1D array.vim

 

Autodetect VISA_LV20.png

 

Thanks for your inputs 🙂

0 Kudos
Message 10 of 13
(1,925 Views)