LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Collecting substantial no of variables

Solved!
Go to solution

I am trying to create a vi which represents the insertion of data into a database from 38 generators. Each generator has 22 variables.

 

As there will be 836 variables in the code, I am looking for ways to collect the variables to make the code more readable. I created a sub-vi containing 22 control variables for a generator. I plan to use this vi as the case for all 38 generators so I changed the settings to a preallocated clone re entrant vi to allow multiple executions in parallel.

 

When I insert the sub-vi into the main VI the the variables show up as a sink rather than source? But they are set as controls in the sub-vi. How do I make this work? Is it possible to collect the variables in this way or is it better to use a cluster?

 

 

0 Kudos
Message 1 of 17
(3,287 Views)

Look at a functional global variable or action engine.

Action Engine Nugget

 

You may also want to look at Current Value Table you can find here Current Value Table (CVT) which is intended for situations such as yours.

Message 2 of 17
(3,266 Views)

Well, your code certainly isn't readable (by us) now.  If you post your code (as a VI -- no pictures, please), we can comment on its readability and make suggestions appropriate to your level of expertise.

 

Bob Schor

0 Kudos
Message 3 of 17
(3,243 Views)

Hi Bob,

Attached is my current vi. I clustered 22 variables for each generator (38 in total) and in case use a sub-vi which formats the values into a string ready to insert into the database. I am working with PostgreSQL 9.6.

I'm sure there's a better way of doing it, but this is all I've come up with so far.

Thanks for your time.

Lisa

0 Kudos
Message 4 of 17
(3,228 Views)

Thanks I will look into it!

0 Kudos
Message 5 of 17
(3,225 Views)

Make an Array of generators and loop it in parallell, it'll clean up the code a lot.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 6 of 17
(3,202 Views)

Thanks for your suggestion. When you say make an array of the generators, list the values for all 38 generators in the array to begin with? or to convert from the cluster? I'd like to have controls so i can change the values and know what variable they refer to. Also with the loop- if it's in parallel this would require 38 separate loops?

0 Kudos
Message 7 of 17
(3,195 Views)

Thanks for your suggestion. When you say make an array of the generators, list the values for all 38 generators in the array to begin with? or to convert from the cluster? I'd like to have controls so i can change the values and know what variable they refer to. Also if in parallel, would this require 38 separate loops?

 

Lisa

0 Kudos
Message 8 of 17
(3,194 Views)

Thank you for posting your code.  I agree with Yamaeda that an array of Clusters would be much simpler.  I also think I see where the Control/Indicator confusion might arise.

 

So some basic questions.  

  • You mention "Generators" and "inserting data into a Database".  Can we assume that you have 38 "pieces of equipment" (or other programs) that send you a TimeStamp, Gen_ID, Engine Start, and the remaining Variables of mixed type similar to the Controls shown on your Front Panel?
  • Are these data coming from LabVIEW routines?  How are you getting them?
  • Whenever working with large Clusters, you should always build a TypeDef for it and use the TypeDef whenever you need the Cluster.  When you build the TypeDef, it may be more convenient (and certainly a bit neater) to build it as an Indicator (you won't have the Increment/Decrement controls).  Also, try to get rid of extra spaces to make it "neater".  [For one of my routines, I have a Cluster with maybe 100 elements, for which all the labels are hidden as I only use it as a "data element"].
  • I've taken the liberty of creating such a Cluster for you, and am attaching it here as a Snippet.  Open LabVIEW 2016 and drag this Generator Control onto a blank Block Diagram, then look at the Front Panel.  I re-ordered some controls (to keep all the Booleans together, for instance, and put the Time Stamp first) and shortened a few names (long text wastes space).  Remember, you don't really want 38 of these on your Front Panel -- use an Array of Generators (ooh, I'll add one of those, but with only 5 Generators, and a Scroll Bar to "see them all").Generator and Array of Generators.png
  • Once you have an Array, dealing with each Array Element using a For Loop simplifies the rest of your code.  Inside the For Loop, put your "Format Into String (Gen Variables) VI, "feeding" it an Array element of the Array of Clusters (i.e. it gets a single Cluster).  The output goes into a Shift Register that is initialized with INSERT INTO gen_test VALUES and is wired to the Initial String input.  Each (single) string gets the format "(%s), ", and the only "problem" is you'll have an extra comma at the end (which you can remove, if necessary).

Bob Schor

0 Kudos
Message 9 of 17
(3,186 Views)

Bob thank you so much for your detailed help.

 

  1. The variables we will be using from the generators have not been finalised, but the controls on the front panels are examples of what may be included (taken from the generator signals list). The data types are mixed. What is confirmed is that there are 38 generators and 22 variables for each. This data will be inserted into a database for monitoring.
  2. In the VI I created I just put controls so I could change the values, but actually the data will be coming from the generator controllers to a cRIO. This is where the VI I am working on comes in - where the data received on the cRIO is written onto a local PostgreSQL database so that it can be then transferred across a network and removed from the cRIO to clear space.
  3. So you create the initial cluster, make it a typedef and use that cluster to make the array of clusters? Does this prevent variables in copy clusters from being accidently deleted?
  4. I'm a bit confused with the last step. Now that the data is set to an indicator, rather than control, how can I feed it into the format into string? And doesn't an array of clusters have to be converted in order to go into a format into string? How do I go from the 1D array to string?

Thanks again, your assistance is much appreciated!

 

Lisa

0 Kudos
Message 10 of 17
(3,156 Views)