LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Initializing shift register while using loops & using Array of cluster converter

In state machine or in normal usage of the shift register, I will be Initializing shift register in two ways 

1. Inside Loop

2. Outside Loop

When I Initialized shift register outside loop I am unable to access other indexes using Array to cluster convertor during development time.

Can anyone tell logic for why this is happening?

 

Initializing shift register.png

Thanks in advance

0 Kudos
Message 1 of 19
(4,848 Views)

I suspect it is your use of Array to Cluster.  By default, it turns an array of however many elements, into a cluster of only 9 elements.

 

There are very few cases where the use of Array to Cluster makes sense.

 

When you want to index elements of an array, you should be using Index Array.  When you want to get to elements of the cluster, you would use Unbundle or Unbundle by Name.

 

In both cases you show below, the 0th element of the array is faded out which means there is no element to actually get data from.

 

There might be some compilation and datatype propagation rules that are affecting how the items coming out from the Array to Cluster look.  Others more familiar with the inner workings of LabVIEW could explain better.  But it really doesn't matter because as I stated above, the way you are accessing the data is just wrong.

0 Kudos
Message 2 of 19
(4,825 Views)

In your screenshot the loops only run once. For the bottom loop you are reading from an uninitialized shift register. In a state machine you might have an initialization state from which you would initialize the shift register inside the loop - but you would not read from that shift register until a later iteration of the loop. After the first iteration the two methods will give the same results. I usually have an initialization state in my state machines, but sometimes just initialize shift registers outside the loop when those values are just constants.

0 Kudos
Message 3 of 19
(4,782 Views)

I am not talking about the run mode. In development mode itself, I am not able to unbundle indexes.

0 Kudos
Message 4 of 19
(4,773 Views)

Hi Chythanya,

 

when you have problems with your specific code/VI then you should attach your code/VI.

Until now all we got is an image…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 19
(4,766 Views)

@Chythanya wrote:

I am not talking about the run mode. In development mode itself, I am not able to unbundle indexes.


You haven't replied to my comment about why you are using Array to Cluster.  ??

0 Kudos
Message 6 of 19
(4,758 Views)

OK. I was able to reproduce the problem. It looks like a bug to me, though one that I would never have caught because of the odd data structure, including the array to cluster.


0 Kudos
Message 7 of 19
(4,754 Views)

@johntrich1971 wrote:

In your screenshot the loops only run once. For the bottom loop you are reading from an uninitialized shift register. In a state machine you might have an initialization state from which you would initialize the shift register inside the loop - but you would not read from that shift register until a later iteration of the loop. After the first iteration the two methods will give the same results. I usually have an initialization state in my state machines, but sometimes just initialize shift registers outside the loop when those values are just constants.


Not exactly.

 

One method initializes the shift register with an empty array, and it will always maintain that value since it is wired straight across.

 

The other method does not initialized the shift register, so it will have the default value of an empty array.  Also.  Once the first run as occurred, then the shift register receives a value.  But it is also being fed an empty array.

 

So both methods will give the same result of an empty array in the shift register before the run or after is has run.

 

The question here is why the unbundling of the cluster is giving different elements.  But it is a pointless question because the construct of turning an array into a cluster is just bad design.

 

Recently I read a thread where someone was comparing a boat and a car.  In this case, it is like asking why does my car sink when I drive it into a lake, but doesn't sink completely when I drive it into a river.  Does it matter?  You shouldn't be driving a car into water either way!  https://forums.ni.com/t5/LabVIEW/Putting-USB-8452-into-Standby-mode/m-p/3345075#M982709

0 Kudos
Message 8 of 19
(4,747 Views)


Not exactly.

 

One method initializes the shift register with an empty array, and it will always maintain that value since it is wired straight across.

 

The other method does not initialized the shift register, so it will have the default value of an empty array.  Also.  Once the first run as occurred, then the shift register receives a value.  But it is also being fed an empty array.

 

So both methods will give the same result of an empty array in the shift register before the run or after is has run.

 

I agree. I had made an assumption that the OP was not feeding an empty array in his real program.

 

The question here is why the unbundling of the cluster is giving different elements.  But it is a pointless question because the construct of turning an array into a cluster is just bad design.

 

Recently I read a thread where someone was comparing a boat and a car.  In this case, it is like asking why does my car sink when I drive it into a lake, but doesn't sink completely when I drive it into a river.  Does it matter?  You shouldn't be driving a car into water either way!  https://forums.ni.com/t5/LabVIEW/Putting-USB-8452-into-Standby-mode/m-p/3345075#M982709


I also agree with this. Yes, I think it's a bug, but one that should be inconsequential since you should never encounter it.

0 Kudos
Message 9 of 19
(4,739 Views)

s.png

0 Kudos
Message 10 of 19
(4,733 Views)