04-09-2013 11:43 AM
Hi all,
I have some queue initialization issues I can't figure out:
In my source code I have a similar structure like in the attached VI, "Code example.vi".
- A queue is constantly enqueued\dequeued according to a boolean combination in the input of the "processing VI".
- The VI is run as an .exe file with the value of "CTRL 4" as a parameter to this exe file.
The problem is as follows:
CTRL1, CTRL 2 and CTRL 3 are all initialized as FALSE.
CTRL4 is initialized as "True" when sending the command to the exe file.
I expect to get an empty array in "elements 1" and "elements 2" and a combination of "F,F,F,T" in the boolean "Array".
In this example "elements 2" array should always be empty.
strangely, when I run the exe file I get THREE similar elements in "elements 2" only ("elements 1" remains empty), all having the output value of the "last queue element" (4 in this case).
The Array indicator is still showing the correct combination (F,F,F,T) but the queue "powers up" with 3 elements. I don't understand how is this possible and of course it causes unwanted states later on...
If I replace the build array with a constant of F,F,F,T to simulate the controls action and compile the exe file again, everything works fine ("elements 2" is also empty).
I'd be grateful for any help on this.
Any idea ???
04-09-2013 12:41 PM
and exactly why are you not using an event structure. Look at the producer-consumer loop (Events) shipping example
This would be the preferable design for doing what you are trying to explain. (I think)
But in this case you want to replace the replace array elements with build arrays (or use conditional tunnels if you have 2012)
04-09-2013 01:11 PM - edited 04-09-2013 01:12 PM
Actually, we can reduce that subVI quite a bit (if you only care about the acting on the queue and not all of the status stuff that you will never see).
04-10-2013 12:47 AM
Hi guys,
Thanks for your prompt reply.
I agree with Jeff that the consumer/producer structure might have been more adequate for this case.
I guess the processing vi could have been better written as well.
Unfortunately the example is a part of a much bigger code, not written by me, and it would be very hard to change it at the moment.
But, the main question still remains - why "elements 2" array is initialized with three elements on power up (when the exe file is run), and how to overcome this.
04-10-2013 01:13 AM
As I said you have a problem with the replace array functions that should be build array functions or conditional termanals. The increment is really messing with your mojo since arrays are zero based, just like loop iteration terminals we wont speak of the loop output terminal with no sink - it doesn't effect anything (possibley, purists will point out the optomizer has to take a few machine cycles to scub that dead code out of the compiled code but thats going too far)
04-10-2013 02:25 AM
Hi Jeff,
I'm not sure I completely understand what you mean by "a problem with the replace array functions that should be build array functions or conditional termanals. The increment is really messing with your mojo since arrays are zero based".
Could you please elaborate some more or point the problematic points on the source code?
Thanks in advance.
04-10-2013 05:53 AM
@JÞB wrote:
As I said you have a problem with the replace array functions that should be build array functions or conditional termanals. The increment is really messing with your mojo since arrays are zero based, just like loop iteration terminals we wont speak of the loop output terminal with no sink - it doesn't effect anything (possibley, purists will point out the optomizer has to take a few machine cycles to scub that dead code out of the compiled code but thats going too far)
I'm not seeing a replace array element function. I am seeing an Insert Array.
I'm still thinking reducing the logic is the way to go. This code is extremely complicated for doing something so simple. I find complicated code will have weird cases and almost always mess up in ways nobody would expect.
04-10-2013 12:18 PM
Jeff,
I tried replacing the "Insert into array" with "Build array" inside the vi, but got the same result.
However, I'm not sure this is what you meant...
Crossrulz,
I'll your suggested structure for the vi later on and see how it works...
04-11-2013 01:57 AM
Hi Crossrulz,
I tried reducing the logic like you suggested but unfortunatly the problem still remains.
I'm starting to think the queue is initialized with 3 elements due to real inputs.
Maybe I'm missing something in my state machine when runing the exe file...