LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Queue initialization problem

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 ???

0 Kudos
Message 1 of 9
(1,421 Views)

and exactly why are you not using an event structure.  Look at the producer-consumer loop (Events) shipping example

1!.PNG

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)

Add Occurence state to queue_BD.png


"Should be" isn't "Is" -Jay
0 Kudos
Message 2 of 9
(1,406 Views)

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).


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 9
(1,400 Views)

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.

 

0 Kudos
Message 4 of 9
(1,374 Views)

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 terminalsSmiley Wink  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)


"Should be" isn't "Is" -Jay
0 Kudos
Message 5 of 9
(1,370 Views)

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.

0 Kudos
Message 6 of 9
(1,366 Views)

@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 terminalsSmiley Wink  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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 9
(1,357 Views)

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...

0 Kudos
Message 8 of 9
(1,335 Views)

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...

0 Kudos
Message 9 of 9
(1,315 Views)