07-25-2019 11:24 PM - edited 07-25-2019 11:32 PM
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?
Thanks in advance
07-25-2019 11:50 PM
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.
07-26-2019 06:32 AM
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.
07-26-2019 07:28 AM
I am not talking about the run mode. In development mode itself, I am not able to unbundle indexes.
07-26-2019 07:36 AM
07-26-2019 07:42 AM - edited 07-26-2019 07:42 AM
@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. ??
07-26-2019 07:45 AM - edited 07-26-2019 07:47 AM
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.
07-26-2019 07:49 AM - edited 07-26-2019 07:52 AM
@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
07-26-2019 08:06 AM
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.
07-26-2019 08:11 AM