LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Need suggestions with programming

Hi,
In programming my application, I am stuck at a point and would like some suggestions.

The application is a relatively simpe HMI, interfacing to a PLC. Because the I/O count is low, I'm doing this in regular Labview, not the DSC module. To keep the Operator Interface seperate, I have an "engine" vi running in the background acquiring the data from the PLC (either via OPC w/datasocket or dll calls). Now my question is this: What is the best way to get the data from the "engine" vi to the Operator Interface vi? I'm having a mind block here. Should I use control reference or globals? Or another way? Thanks for any suggestions.
0 Kudos
Message 1 of 7
(4,019 Views)
Hi, i prefer control refernces to globals, because it more safe. Also think about GOOP (object-oriented approach). It let you easely separate engine from GUI.
0 Kudos
Message 2 of 7
(4,019 Views)
You might also consider using the Queue Operations VIs. With a queue you will never lose data. If you've never used the Queue VIs, go to Help>>Find Examples... and search on queue. You'll find examples to get you started.

Regards,

Doug Norman
0 Kudos
Message 3 of 7
(4,019 Views)
> The application is a relatively simpe HMI, interfacing to a PLC.
> Because the I/O count is low, I'm doing this in regular Labview, not
> the DSC module. To keep the Operator Interface seperate, I have an
> "engine" vi running in the background acquiring the data from the PLC
> (either via OPC w/datasocket or dll calls). Now my question is this:
> What is the best way to get the data from the "engine" vi to the
> Operator Interface vi? I'm having a mind block here. Should I use
> control reference or globals? Or another way? Thanks for any
> suggestions.

There are obviously many ways to do this. The control reference
approach would be used to push the data into the HMI, which would then
either require the engine to know about the HMI controls, or you
would
need a way for the HMI to register themselves into arrays of interest or
similar mechanism.

If the application is small enough, and the datatypes simple enough,
like just scalars and strings, globals should work fine, but be sure to
be organized about their naming and in which VI panels they are placed.
I have seen people use the same global name like temperature on
multiple global VI panels and later really confuse themself when they
are drop the wrong one.

Another approach which will scale better, similar to what DSC does is
come up with a way for the HMI to ask for the values. LV 2 style
functional globals are a good way. Then have the VI that reads the
values block on an occurrence or an event queue. The engine can set an
occurrence or sent an event when new data should be read. The HMI has a
simple loop and reads the appropriate data and updates the indicators.
Separate loops take care of controls, or you can use a timeout on the read.

Greg McKaskle
0 Kudos
Message 4 of 7
(4,018 Views)
Hi Greg,

Thanks for the insights. Another question, though. To know when new data should be read, is that just a matter of the engine utilizing a shift register and comparing the old and new data? Also, if I need to read about 40 words form the device (in this case, a PLC), I was going to read these all in one block and parse out the individual data I needed. Do you think this is okay or should I make several, smaller reads to the PLC. Thanks!
0 Kudos
Message 5 of 7
(4,019 Views)
The reasons for using the DSC include this exact situation.

The DSC, with regards to getting data from Field Point modules (the equivalent of PLCs, I guess) runs on a server level, below LabVIEW, called the Tag Engine. The Tag Engine updates a historical database called the Citadel database. This keeps a running track of your data (depending upon the configuration.)

Where the DSC is valuable is that the data server and database are already written for you, and all you have to do is retrieve the data as needed.

In trying to simplify things by not using the DSC, you have tasked yourself with the rudimentary programming involved in retrieving and storing the data from the PLCs, and making it easily accessible by our HMI.

As is sounds as though you have already done the work to create the engine, you are now stuck with how to get your data from the engine to the HMI, something that the Tag VIs do in LabVIEW. You now have to mimic the Tag VIs somehow.

So, on to the real answer to your question (the above was presented for purely information purposes to possibly influence your decision next time...let NI do the work for you...)

I strongly recommend AGAINST both references and globals. References are intended as a way to automate the updating of front panel controls and indicators, and not as a substitute for pointers and references. Globals are just a mess, and I avoid them at all costs. Consider a few options. Your choice should be dependent upon your exact situation.

1. Simple Data Point server. This simple 'server' makes the latest data point available. It stores it in a LabVIEW 2 style global (something I like to call a data object, but which is probably not the best name for it.) Basically, you take the data from your engine, and write it to a subVI that uses an unitialized shift register to store the data. The subVI is always WRITTEN by the engine. Your HMI then READs the data. There is no time or latest data dependency, and simply put, your HMI will always be reading the latest data available. You can find a design template for this in the "Programming Designs..." topic on the main page of the web interface Developer Exchange, LabVIEW General.

2. FIFO, LIFO, or similar buffer. If you need every datapoint to be handed from your engine to the HMI, then you need to buffer the data. Just use the design model as the simple server, but instead of updating the shift register with a single point, you need to append an array for each write, and delete an element for each read. FIFO (First in First Out) buffers remove the oldest data point first, and LIFO's remove the newest on first.

There are probably other methods available. If these two don't fit your needs, please post again. Also, if you have trouble with the design pattern, please let me know. I created that design pattern, and it should be adequately documented, but if not, feel free to poke and prod.

Good luck

-Mike Du'Lyea
Message 6 of 7
(4,019 Views)
> Thanks for the insights. Another question, though. To know when new
> data should be read, is that just a matter of the engine utilizing a
> shift register and comparing the old and new data? Also, if I need to
> read about 40 words form the device (in this case, a PLC), I was going
> to read these all in one block and parse out the individual data I
> needed. Do you think this is okay or should I make several, smaller
> reads to the PLC. Thanks!

If you are talking about the engine reading from the PLC's, most of the
time these reads take place on a simple timer. They can have a
comparison as you describe to determine when they should set the
occurrence telling the HMI that newer data is available.

Greg McKaskle
0 Kudos
Message 7 of 7
(4,018 Views)