LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Programmatically Add Network Device (VISA)

We have some balances connected to a DeviceMaster Serial Device server, which basically takes 16 serial devices and turns them into a TCP/IP "port".  If we go into MAX, we can open Network Devices, choose Add Network Device, choose VISA TCI/IP Resource, choose Manual Entry of Raw Socket, specify an IP and a Port Number, and choose an Alias for the newly created Resource Name (which has the form TCPIP::192.168.23.45::8000::SOCKET).  After a few more "Next" and "Finish" clicks, the new Port appears in MAX, and if we drop a VISA Configure function and create a VISA Resource Name control on its input, the Alias we just created appears on the list, along with COM1 and LPT1.

 

This is a somewhat tedious manual process to do in MAX, also one easily forgotten (we had not set up this switch in a while, and fiddled around for an hour or two before we again figured it out).

 

Is it possible to do this programmatically?  Can I write a VI that will take an IP, an array of Ports, an array of Aliases, and create a VISA Resource that I can use?  [I'm "taking a short cut" by asking here before diving into the Web, Help files, etc. in an attempt to figure it out myself ...].  I figure if it can be done, one of the LabVIEW Forum champions (lower-case "c", as not all of the Gurus on this Forum are "LabVIEW Champions") has already done it and is willing to help.

 

Bob Schor

 

P.S. -- the first place I looked was the Help for the Serial Protocol (a folder) under Data Communications.  The Help for the Serial Protocol says "Additional functions are also available on the VISA Palette" -- what VISA Palette?  In my LabVIEW 2016 installation, I have the following Protocols:

Protocols.png

0 Kudos
Message 1 of 24
(6,146 Views)

The "missing" VISA Sub-palette is hiding, naturally, under Instrument I/O -- go figure ...

 

Bob Schor

0 Kudos
Message 2 of 24
(6,129 Views)

Quite possible

 

Capture.PNG

 

Not quite right but, it should point you in the general direction of the system API.  Your bright enough to figure it out from that and the help file 🙂


"Should be" isn't "Is" -Jay
0 Kudos
Message 3 of 24
(6,124 Views)

Drat!  I hate it when I can't live up to Jeff's inflated opinion of my abilities!

 

So I've been experimenting with how to programmatically address a VISA-over-TCPIP device that supports multiple identical units (they're Balances that report their weights over a serial port).  What we originally did five years ago was to open MAX, go to Network Devices, and manually create, on a per-port basis, all of the TCPIP VISA Devices, giving them Aliases.

 

Jeff suggested finding them using Find Systems and Find Hardware, but these don't work because the "System" is not "NI-Friendly" and I can't "see" it.  But I had my own "brilliant" idea -- just do a VISA Open and instead of using the default I/O constant that can expand into one of the Alias names, use a string with the Alias name and hope LabVIEW is clever enough to properly coerce it.  That worked!  However, I wanted to avoid creating Aliases, which requires manual interactions with MAX and thus doesn't "scale" (hard to move to another machine without going through the whole MAX exercise, and don't tell me to "Export the Configuration ...").  So how about putting in the "Real" name, TCPIP0::<et cetera>?.  The virtue is that knowing the IP and the Port names, I could easily build these strings at run-time.  That does not work.  Which brings me back to my original goal -- how can I programmatically do what MAX does and take a VISA TCPIP specification and come back with an I/O constant (which seems to be what MAX calls an "Alias") that I can use to open this VISA channel.

 

Surely someone has encountered this, no?

 

Bob Schor

0 Kudos
Message 4 of 24
(6,059 Views)

Rename Device does what MAX does to assign an allias.

 

The real problem here is the device is not "NI-Friendly" meaning you can't use find remote systems to find these devices right?  In that case the system API is only going to be useful in renaming them AFTER they are found and you haven't "Found" them yet!  STBY.

 

Currently you appear to be "Finding" them by TCP/IP address.  Does that mean you have another means of learning those addresses?  If so HOW?


"Should be" isn't "Is" -Jay
0 Kudos
Message 5 of 24
(6,058 Views)

Here's my scenario:

  • I'm building an application, and I have a bunch of devices hanging on a "Concentrator" that accepts 16 serial devices and aggregates them as 16 ports on an Ethernet Address.  I know (in advance) the IP of the device and the Port numbers.
  • My routine spawns 16 Clones, each assigned to one of these devices.
  • At Run Time, I want Clone n to open the VISA Device plugged into Port n.  To do this, I have to do the following (I think):
    • Create a "VISA Handle", which MAX shows in the form TCPIP0::<IP>::<Port>::SOCKET (I'm not sure if all the parts of this name are needed, but it is what MAX makes when I create, by hand, a New Network Device).
    • Create an Alias for this Handle.
    • Wire the string representing the Alias to an Open VISA function.  There will be a coercion dot on the input, but the output will be an I/O indicator having the Alias showing (at least that's what happens when I use a "real" VISA Alias string that I created "by hand").
  • One reason to do it this way is that I have "programmatic" control over my VISA assignments, independent of MAX.  I used to be more "MAX-dependent", creating DAQmx Tasks in MAX (or in LabVIEW Project) and using them in my Project, but this Fall, I learned the Error of my Ways (thanks to some helpful criticism from the Forums) and now build everything with DAQmx functions.  This is my attempt to do the same for VISA devices.
  • Another drawback to the current method is that the assignment is "machine-specific" -- I have to go into MAX on the target machine (assuming it has MAX), manually create all of the VISA devices, then program in the Aliases or hand-code (as constants) the 16 I/O VISA names in my program.  Especially if I'm dealing with an Executable, it makes moving the code to another machine much more difficult and labor-intensive (I'm willing to spend a hour coding to save 5 minutes of wrestling with MAX ...).

Thanks for your suggestions and help.  I can't quite tell from your last response (I don't know, for example, what STBY means) if  you know how to create the Aliases I need.  Suggestions continue to be welcome, and will be tested ...

 

Bob Schor

Message 6 of 24
(6,036 Views)

Ok, so you know all the parts of the resource discriptor. Some parts will change between stations, some parts will change between Clones (you'll have to pass those parts to the clones or create the discriptor first and paas the individual clones their discriptor.  Life is easy! the TCPIP address goes in a config file change the value with a text edit (Always create a config editor for the project build it into a seperate exe and deploy it to the target without documenting that to the end user!.)  I just know that you can append strings even if they come from part of a config file and a clone identifier.

 

Forget about the VISA Open!  If the Clone gets a string into a IO Session input it is coerced.  Ditto just even wiring it to a VISA Resource Out indicator- strings coerce to IO easy.  If you typo the discriptor you will get an error.   If you don't want MAX to know about your stuff then you should not worry about "Aliases"  They are a MAX thing!  The closest I think you can come without MAX is a combo box you set Strings[] and Values[] on programatically from the resource discripors you know about before hand and put in the Station config file. 

 

5 minutes in MAX vs an hour coding is totally appropriate if you deploy to 12 or more targets.  But its only 5 minutes with MAX IF you documented the IQ process (That took 2 hours)  Unfortunately, now you are over-complicating Installation by avoiding a commonly used and well documented configuration utility.  My preference would be Name your Ailiases well (e.g. I've used BLEUART0-9 for serial coms to UARTS for Bluetooh Low Energy modules that were tested in 10-up panels) Then DOCUMENT the required Aliases as part of the install instructions!  WHY! if I lost a FTDI Ser-RS-232 adaptor I cold just plug in a new one and assign the Alias.  Cooler! for NI-USB devices I usually hack DevMon and run my Alias renamer exe when the device is discovered.  (Yeah, you can do that but you need MAX)

 

Writing your own DAQmx Config file is silly.  Put everything in the *.lvproj and when you build the exe LabVIEW writes the config file for you <AppDir>\Data\NI_DAQ\*.ini  Alternatly put it all in MAX and imprt the *.nce with your installer and it gets in XML he(ck) just peachy.  xml He(ck) is my pet name for the innards of MAX.

 

STBY defined: <Suc*s to be you>

 

Bob, you are making configuration harder than it needs be. 

 

 

 


"Should be" isn't "Is" -Jay
0 Kudos
Message 7 of 24
(6,028 Views)

 

 


@Bob_Schor wrote:

... But I had my own "brilliant" idea -- just do a VISA Open and instead of using the default I/O constant that can expand into one of the Alias names, use a string with the Alias name and hope LabVIEW is clever enough to properly coerce it.  That worked!  However, I wanted to avoid creating Aliases, which requires manual interactions with MAX and thus doesn't "scale" (hard to move to another machine without going through the whole MAX exercise, and don't tell me to "Export the Configuration ...").  So how about putting in the "Real" name, TCPIP0::<et cetera>?.  The virtue is that knowing the IP and the Port names, I could easily build these strings at run-time.  That does not work.  ...


You should be able to construct a resource name string like TCPIP0::<ip>::<port>::SOCKET and pass it to VISA Open and it will open the session as long as the session is valid. Is that not working? What was the error that you were getting? If you are familiar with the NI VISA Interactive Control (NIVisaic.exe) app, you might be able to do some experimentation in opening the session using the resource name.

Message 8 of 24
(6,023 Views)

@JÞB wrote:

 

Bob, you are making configuration harder than it needs be. 

 


Jeff,

     Thanks for the comments.  I will try your suggestions, but I think I had already tried the "Alias-free" approach and it didn't work, but maybe I typoed somewhere.

     As for my "do it all in DAQmx" -- this came about when I maybe got too clever.  In my triaxial accelerometer routine, I wanted to take voltage data from my accelerometers, solve some equations to compute the appropriate scale factors, then add a Scale factor so that I got all three axes in g's and pushed into DAQmx the conversion of volts to g's (yes, I could have done the math myself, but it was also, in part, a "teach yourself what DAQmx Scaling Is All About").  I kept getting errors when trying to modify my task to add scaling, and someone (Hooovaah?) suggested "rolling my own", which worked.  It was No Big Deal, especially since it was buried in a sub-VI called "Create Show Task".  

 

Bob Schor

0 Kudos
Message 9 of 24
(6,007 Views)

@pankaj wrote:

You should be able to construct a resource name string like TCPIP0::<ip>::<port>::SOCKET and pass it to VISA Open and it will open the session as long as the session is valid. Is that not working? What was the error that you were getting? If you are familiar with the NI VISA Interactive Control (NIVisaic.exe) app, you might be able to do some experimentation in opening the session using the resource name.


I think I tried using the resource name as you suggested.  I'll try again, and will document my findings.  I am not familiar with the NI VISA Interactive Control, but will try to learn about it.  Thanks for the suggestions.

 

BS

0 Kudos
Message 10 of 24
(6,005 Views)