From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Use static VI Reference in Method

Hi,

 

I use LabView to connect to a Beckhoff PLC via ADS OCX (ActiveX) and poll variables into LabView. In a functional approach (described here) everything works as expected. But now I want to improve my VI to make use of a more object orientated approach. Therefore I created a class for my application and a "init" method for connection:

 

Initialize MethodInitialize Method

My problem is, when I follow the example from Beckhoff, I have to define a static VI reference (marked yellow) which (if I understood that right) handles the event when a measurement value has changed. Inside the reference, the VI checks if the data arrived matches the data I need and writes the values in a global variable. See below:

 

VI for Static ReferenceVI for Static Reference

Now I want to get rid of the global variables. I want to instantiate the variable from outside the static VI reference, as input to the "init" method. Is there a way to achieve that?

 

Kind regards

Matthias

0 Kudos
Message 1 of 3
(937 Views)

When you register a callback, the VI is called every time the event occurs.

 

You can use the User Parameter input of the register node to pass additional values to the VI and the VI can use that value. In your case, this could be a reference to an event/queue/actor/etc. which the VI will use to pass the value to where you want it.

 

Wire the relevant data to the User Parameter input, then delete the static VI reference and right click the node and you can recreate it again with the new data in it. You can then copy the new data into the original VI, or you could just add it manually to the original VI.


___________________
Try to take over the world!
0 Kudos
Message 2 of 3
(891 Views)

I'd also prefer an event driven approach, so I'd pass a user event. The callback will pass the event to the registered event structures.

 

If you make the global a private global, it might not be that bad. If the data is used as a current value (vs events), a private global might be better.

 

Events and globals solve two different problems. Events, won't give you access to the current value. If you want the last written value, a private global can be more convenient.

 

Events and queues are almost synonyms. Events provide 1-n (n=0..), while queues only have 1-1 sender-receiver relation.

 

The private global only works if you have 1 instantiation of the class. All instantiated objects will use the same private global.

 

A 3rd option is to use a DVR.

 

As 4th option, you can use (an array of) a control reference. If you set the value updates with a value signalling, you can chose if you want events. You do need a place to put those controls.

 

In summary:

 

Event -> each object triggers registered events

Global -> each object writes the same value

DVR -> each object writes it's own value.

Control references -> each object sets control values. Events are optionally. 

 

So, the good news is you have options... The hard part making an educated choice.

0 Kudos
Message 3 of 3
(882 Views)