LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

auto create local variables

Solved!
Go to solution

Hi,

 

I have a feeling that the idea I have is probably not possible but I figured it wouldn't hurt to ask.  I am logging CAN data using a cRIO and NI 9853 using the frame to channel convertion vi's.  I have a case selector in which the message id dictates the case.  Within each case, the frame data is converted and sent to arrays for the channel name and data.  Then, in a separate loop, I bring in the data and channel name with local variables every tenth iteration and save it on a TDMS file.  I am currently using local variables for each array in the case selector.  While this works nicely, I am trying to simplify it and make it such that if someone else wanted to add more CAN signals for logging, and thus more cases within the case selector, they could do so with as little work as possible.  In essense, I need to make it dummy proof.  The idea I have is trying to find a way to automatically create a local variable and reference a specific indicator as soon as a case is created.  Is that at all possible or am I asking to much of labview?  Thank you.

 

 

0 Kudos
Message 1 of 30
(4,256 Views)

Why not create a single queue that has a cluster containing the following:

  1. Message ID
  2. Channel Name
  3. Data

Now every case should process the data then put the data in the queue along with the message ID. The data save loop still runs at the period you specify and dumps the queue and saves with the appropriate information. Global/Local variables are GENERALLY a bad idea, a queue is much more suited to this type of task.

Charles Chickering
Architecture is art with rules.

...and the rules are more like guidelines
Message 2 of 30
(4,248 Views)

I'm still not sure that would solve the problem of auto creating more queues for any extra cases later created.  Currently I have a .ncd file with message IDs 1, 2, and 3.  So I have cases 1, 2, and 3 which means I have three indicators for data and three from the channel name, each corresponding to their respective case.  I have a local variable for each indicator which I then feed to a insert into array block for data and for the channel names.  The problem is that if somene else has a database file with 100 messages, they would have to go to the case selector and duplicate a case until they have 100 cases with each case specifying a message ID.  Thus, they would then have to add local variables for each case.  My assumption, is that the same would be true using queues.  I know that I could have everything feed into one que for data and one for channel but, if my uderstanding of queues is correct, queues work by storing the data and then dumping it on a FIFO basis.  I am only concerned with logging every 10th iteration so I do not need all of the data sent to be logged.  So, with all this said, is there a way to auto populate local variables or queues and have the proper reference everytime a new case is made?  This would greatly reduce the user interference with the VI and eliminate any user error.  I hope all that makes sense.

0 Kudos
Message 3 of 30
(4,192 Views)

I don't believe you can do something like this with local variables.  It is possible using property nodes however.  Use propery nodes to gain access to the list of controls/indicators http://forums.ni.com/t5/LabVIEW/list-of-controls-and-indictors/m-p/2298644/highlight/true#M724077.  The list returned is in the tab order of the front panel objects.

 

Wire the control reference to a Value property node to read/write it's value.  A for loop will run through all of your indicators. 

 

you can use string mathing of indicator name to only process the indicators you want (use an array constant created by the user to select them) all with the corresponding message.  (receive message ID 3, update indicator "voltage"  for example).  This way, whenever someone adds indicators, all they need to do is update the array constant (a lookup table).  This info could also be stored as a 2 column text file for easy user access.  

 

Utilizing the code I linked to will run through every control/indicator  and you will check whether it sould be updated.  I'm hoping their is an easier way (such as create reference given a control name) but I am not experienced enough to know this.

 

EDIT: Come to think of it, use the provided code to create a lookup table of reference/indicator name when the code starts (initialization).  Then, you have your user lookup table of indicator name / Message ID.  Now any incomming message only needs two string matches to determine the necessary control reference to update.

0 Kudos
Message 4 of 30
(4,183 Views)

@SRamirez wrote:

I'm still not sure that would solve the problem of auto creating more queues for any extra cases later created.  Currently I have a .ncd file with message IDs 1, 2, and 3. So I have cases 1, 2, and 3 which means I have three indicators for data and three from the channel name, each corresponding to their respective case.



Whenever you have "1, 2, and 3" items, you have a list.

Whenever you have data and channel names, you have a cluster.

So, combine it to an array of cluster and you can expand it as much as you like.

 

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 5 of 30
(4,148 Views)

Yamaeda,

 

That's actually a great idea but the problem comes in that I am needing some sort of sample and hold feature.  Is there any way of using clusters as you said while still having a sample and hold feature.  Thank you.

 

 

0 Kudos
Message 6 of 30
(4,125 Views)

You can update the items of a cluster separately, in this case cluster(X).data=Sample (approximatly)

The items in the array will be handled with index and replace array item, and with bundle/unbundle you'll handle the cluster parts.

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 7 of 30
(4,109 Views)

Just one small comment.

 

Once your program on the cRIO is running outside the development system, then the program has not front panel. 


The use of local variables/property nodes should be avoided. It will hit you once you build it to a .rtexe

0 Kudos
Message 8 of 30
(4,096 Views)

Could you explain that a bit further?  My working knowledge of labview is still not what it should be but if I understood correctly, I should have the data in each case feed into an index array block and then into a replace array block and finally, bundle to cluster.  Correct?  

0 Kudos
Message 9 of 30
(4,077 Views)

@dkfire wrote:

The use of local variables/property nodes should be avoided. It will hit you once you build it to a .rtexe


This is only half correct; local variables and property nodes are not the same thing. Local variables work correctly even without a front panel. Property nodes that reference front-panel items do not work when there is no front panel.

0 Kudos
Message 10 of 30
(4,060 Views)