I am having trouble with passing data through my custom device using global variables. I would like to allow a user select a RIO device address while configuring the system definition file. This would be stored into a global variable using the Main Page VI. I would later use this RIO device address in the RT Driver to deploy a bitfile. I can hardcode it, but it is much more convenient to use a global.
When I try to store the address in the global variable, it updates the value temporarily (I have confirmed that the event structure recognizes the value change). When I click off the node in the system definition tree that is linked to the Main Page VI, and then click back onto it, the Main Page VI runs again. I wrote the code to repopulate the RIO device address with the value last stored in the global variable, but it is blank. I included the global variables VI in my build, so I can't think of why it might reset that value.
Any help would be much appreciated!
Solved! Go to Solution.
Have you tried using custom device properties to store this value instead of GVs?
In Configuration VI you can set this property and if I am not wrong, you can read these properties in RT Driver function.
That worked, thanks! For some reason, I thought that you could only pass properties for channels, and I wanted to avoid having to make a channel for the device address.
I would still like to know why globals don't work though out of curiosity. Do you know why?
I am not completely sure but i think I can answer that:
You see, Configuration VIs are run on Host PC where you configure System definition file and so on, so they are run as part of that Configuration LLB on PC. RT Driver executes as part of Execution LLB on RT target, so these two LLBs run on different targets under different libraries. Therefore you can only use global variables to share data between configuration VIs OR share data between RT Driver VIs.
I include the global VI in building both the configuration and engine libraries, but it would make sense why the data would not be passed between them. However, it doesn't explain why I lose the data when setting up the system definition, because that only uses the configuration LLB.
To answer your follow-up question, the VIs in your custom device are dynamically called by VeriStand. Once you click away from the page, these VIs are being unloaded from memory, which is probably also removing your global VI from memory, since your VI was the only thing referencing it. So when you go back to the page, your page VI is re-run and the global will take on its default value.
Thanks, Devin! So in order to use global variables, it sounds like I would have to programmatically set the default values of the controls on the front panel? It will probably be easier to avoid them.
Yeah, globals aren't really going to work in custom devices, so you should stick with the set/get property subVIs. Those are really the only way to guarantee persistant data in your custom device.