12-13-2012 12:47 PM - edited 12-13-2012 12:50 PM
Hello,
I have a producer consumer architecture with a queue to pass values. I want to push a new value onto the array using "Insert into Array" when a button is pressed, but when I do the previous value is being read the first time and the correct value on the second press.
I'm self taught and it's my first time using the queue so maybe something I'm not seeing/thinking about there?
Version 8 VI Attached.
Do this to see the problem:
1. Run
2. Click "Master Read"
3. Change "Value"
4. Click "Master Read"
5. Click "Master Read"
Any help is appreciated including block diagram critique.
Thanks!
Solved! Go to Solution.
12-13-2012 01:00 PM
As far as I can tell, the code is doing exactly what you are telling it to. Each time you click the Read button the new version is inserted into the array at element 0 and the rest are pushed down. This happens first time and every time. What behavior are you wanting?
Mike...
12-13-2012 01:18 PM - edited 12-13-2012 01:19 PM
What I am seeing is:
Start:
Value = 0
Array = empty
Click Master Read
Value = 0
Array = 0
Change: Value = 1
Click Master Read
Value = 1
Array = 0,0 I would expect this to be Array = 1,0 as Value = 1 when I clicked Master Read
Click Master Read
Value = 1
Array = 1,0,0 I would expect this to be Array = 1,1,0 as Value = 1 when I clicked Master Read both times
12-13-2012 01:22 PM
Yup, that's exactly what I am seeing...
Mike...
12-13-2012 01:25 PM
You're seeing what I expect to be seeing? but not what I am actually seeing?
12-13-2012 01:26 PM
Just had a thought. Do your test again and after you change the value of the value input click outside the control somewhere before you click on the button. Does that make a difference?
Mike...
12-13-2012 01:27 PM
Yes I saw what you were expecting.
Mike...
12-13-2012 01:30 PM
"Just had a thought. Do your test again and after you change the value of the value input click outside the control somewhere before you click on the button. Does that make a difference?"
Yes now it works. But why?
12-13-2012 01:35 PM
It all depends on how you change the value of "Value". If you use the increment and decrement buttons it works as you expected.
If however, you type in a new value and click the button without clicking somewhere else first, it doesn't work - and here's why:
When you type in a value that modified value doesn't show up in the code untill the control loses "key focus". The problem is that clicking the button does cause the numeric input to lose key focus but only after the code has responded to the mouse up event.
To fix the problem put a property node in the mouse down event to set the numeric's KeyFocus property to false before the value is enqueued.
Mike...
12-13-2012 01:41 PM
That works, I still find it strange (I'll have to go read up on key focus) but it works. Thank you!