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.
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.
03-03-2021 06:51 AM
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:
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:
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
03-04-2021 02:20 AM
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.
03-04-2021 03:27 AM
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.