LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Why does this keep duplicating values?

Hi, I have this sub vi that reads opc values(addresses) from a server across a local network. It uses a data socket read within a for loop to pass these values into an array. The problem i have is every so often it duplicates the same value rather than just reading the exact address in the opc array.

 

e.g.

 

123      123

103      103

110      103

121      110

 

Which may values that i save in a spread sheet out of sequence. Anyone knows whats wrong here?

 

Stuart

0 Kudos
Message 1 of 6
(3,505 Views)

Your code has a lot of issues.

 

First do a block diagram cleanup, you have a lot of wires with unnecessary bends and sections of code scattered all over the place.

 

Why do you have 13? stop buttons.  Then proceed to crash your code by wiring the real Stop button to a Stop LabVIEW stop sign?  That is like hitting the abort button on the toolbar.  Not a good way to stop a program.

 

I think you are seeing the effects of a race condition caused by the use of local variables.  You are writing to an indicator on one loop and reading from its local variable in another loop.  Depending on where each independent parallel loop is in its execution, you could read duplicate values (i.e., the indicator was not updated in between), or miss a value (indicator updated twice without being read.)  You should be using a producer/consumer architecture with queues to pass data if you want to avoid this problem.

 

I would suggest spending more time on the forums reading up on race conditions, queues, and the LabVIEW style guide.

Message Edited by Ravens Fan on 01-28-2010 11:24 AM
0 Kudos
Message 2 of 6
(3,496 Views)

Hi Ravens fan, yeah i know my code is a bit messy a the mo. I do all my tidying up later. As for the stops, it suited my testing situation at the time.

 

As for the locals you talk about, i tested the the VI with the datasocket in. independently of the main program and it has the same problem. So it cant be the locals you suggest. But thanks for your suggestion Smiley Happy

 

Stu

0 Kudos
Message 3 of 6
(3,475 Views)

stu22 wrote:

 

As for the locals you talk about, i tested the the VI with the datasocket in. independently of the main program and it has the same problem. So it cant be the locals you suggest. But thanks for your suggestion Smiley Happy

 


Yes, it can.  It is not actually the locals that are causing the race condition, it is the way you are using them.  Swapping locals for datasockets will cause the same race condition if you don't do anything to correct the architecture.

0 Kudos
Message 4 of 6
(3,457 Views)
Hi, yes i now i understand what you mean. Thanks Much appreciated Smiley Happy Its the first time ive come across this and ive been doing it 10 years now lol Any tips on how i can get around this??
0 Kudos
Message 5 of 6
(3,434 Views)

You can use the producer/consumer archutecture as ravens fan suggested and pass values via a queue's

 

there are examples of this found in the example finder

Message Edited by Harold Timmis on 01-29-2010 05:09 AM
Harold Timmis
htimmis@fit.edu
Orlando,Fl
*Kudos always welcome:)
0 Kudos
Message 6 of 6
(3,425 Views)