VeriStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Using global variables in a custom device

Solved!
Go to solution

Hi everyone,

 

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!

 

Thanks,

Mitch

Download All
0 Kudos
Message 1 of 8
(5,396 Views)
Solution
Accepted by topic author MitchD319

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.

Vuk Obradović
Technical lead / Senior R&D Engineer at Noffz Forsteh technologies d.o.o.
Message 2 of 8
(5,368 Views)

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?

0 Kudos
Message 3 of 8
(5,355 Views)

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. 

Vuk Obradović
Technical lead / Senior R&D Engineer at Noffz Forsteh technologies d.o.o.
0 Kudos
Message 4 of 8
(5,345 Views)

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.

0 Kudos
Message 5 of 8
(5,332 Views)
Solution
Accepted by topic author MitchD319

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.

0 Kudos
Message 6 of 8
(5,322 Views)

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.

0 Kudos
Message 7 of 8
(5,315 Views)

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.

0 Kudos
Message 8 of 8
(5,310 Views)