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.
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.
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.