Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   NI LabVIEW (http://www.chiefdelphi.com/forums/forumdisplay.php?f=182)
-   -   Using Global Variables Instead of Get Refnum (http://www.chiefdelphi.com/forums/showthread.php?t=133207)

GuyM142 20-01-2015 09:14

Using Global Variables Instead of Get Refnum
 
Is it possible to use a global variable to store the registry refnum for the motors/sensors etc. instead of the refnum get vi?
It can make things a bit easier and prevent stupid name typo mistakes.

Alan Anderson 20-01-2015 09:46

Re: Using Global Variables Instead of Get Refnum
 
It's certainly possible to use global variables to store RefNum values. The first year of the NI control system, it was normal to do it that way.

Two years ago we discovered a big drawback to not using the RefNum Registry, though. That's the mechanism that lets Test mode work to give you manual access to all the robot inputs and outputs that you use. So we use sort of a hybrid scheme, where we do a RefNum Set in Begin.vi, and also keep the RefNum in another place for easier and less typo-prone access.

Doug Norman 21-01-2015 08:55

Re: Using Global Variables Instead of Get Refnum
 
Quote:

Originally Posted by Alan Anderson (Post 1430919)
keep the RefNum in another place for easier and less typo-prone access.

One way some teams do this is by creating a typedef enum updated with a list of all their RefNum names. Then they simply drop that enum followed by the Format Into String function any place they need a RefNum name. It's a bit of extra code, but makes it so they don't have to remember the names or correct spellings - they simply pick it from the enum list.

Alan Anderson 21-01-2015 10:46

Re: Using Global Variables Instead of Get Refnum
 
Quote:

Originally Posted by Doug Norman (Post 1431455)
One way some teams do this is by creating a typedef enum updated with a list of all their RefNum names. Then they simply drop that enum followed by the Format Into String function any place they need a RefNum name. It's a bit of extra code, but makes it so they don't have to remember the names or correct spellings - they simply pick it from the enum list.

We've done that, and actually took the concept a bit farther a couple of years ago. Along with the typedefs (.ctl files in LabVIEW), we had a Global Variable vi full of cluster constant arrays that defined everything that goes into the Open functions. In Begin, we looped through those arrays for Drive, Digital Input, Motor, Encoder, etc. to open everything. In Finish, we did the same thing to close everything. We made copies of each Refnum Get vi and modified them to take the enum directly. The rest of the robot code looked almost the same as the "normal" way of doing things, except that the enums are blue where strings are pink.


All times are GMT -5. The time now is 23:35.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi