LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Write to Single Cluster Element

Hey,

 

This is kind of a basic question, but is it possible to write to only a single cluster element and what is the best way to do it?

 

The picture below demonstrates what I mean:

 

test.png

 

 

I guess it's kind of wishful thinking to want this code to end up with 10 and 20 in the Cluster, and obviously it doesn't. But I'm curious if there is some method for accessing individual cluster elements.

 

Thanks,

Kevin

 

 

0 Kudos
Message 1 of 8
(4,340 Views)

The way of accessing the element is correct but instead I would use a shift register inplace of Locals. You will not get what you expected at the end because both the data flow starts at the same time to travel do even if you have delay it would not effect so what you have to so is you should read the 2nd only when the 1st completes.

-----

The best solution is the one you find it by yourself
0 Kudos
Message 2 of 8
(4,338 Views)

Obviously, the way it's setup is to guarantee that it happens in that order to illustrate the problem. Imagine there are two loops executing in parallel with the cluster and they don't write to the same element. I'd like to be able to write to an individual element so no locking mechanism is required.

0 Kudos
Message 3 of 8
(4,329 Views)

So what you are trying to achieve with this am trying to understand. Are you trying to explain the racing condition?.

-----

The best solution is the one you find it by yourself
0 Kudos
Message 4 of 8
(4,325 Views)

Yes, and I'd like to be able to avoid it by simply writing to a single element instead of the entire cluster.

0 Kudos
Message 5 of 8
(4,319 Views)

Look at Ben's Action Engine Nugget.  It encapsulates the cluster data and will prevent the race condition that is happening on your data now.

 

You'd have at least two states:  Update Numeric and Update Numeric 2.  There will also be an initialize state that would preload the data into the cluster stored int he shift register at the beginning of your program.

Message 6 of 8
(4,312 Views)

@kevin.key wrote:

I guess it's kind of wishful thinking to want this code to end up with 10 and 20 in the Cluster, and obviously it doesn't. But I'm curious if there is some method for accessing individual cluster elements.


You have a typical race condition due to overuse of local variables. Both local variables read the original cluster immediately and place it on their wire. Later each bundle operation acts on the original cluster data, stepping on each other.

 

I don't have FPGA at the moment, but all you need is something like the following two alternatives. Modify as needed.

0 Kudos
Message 7 of 8
(4,305 Views)

If you want to code it "flat", you need the local variables if the cluster indicator should be updated live. I think your main problem is that you did not see that the two inner sequence structures execute in parallel. (LabVIEW does not execute left to right or top to bottom).

 

Here's a simple draft that seems to do what you want:

 

 

0 Kudos
Message 8 of 8
(4,298 Views)