01-28-2010 10:02 AM
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
01-28-2010 10:21 AM - edited 01-28-2010 10:24 AM
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.
01-28-2010 12:11 PM
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
Stu
01-28-2010 12:56 PM
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
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.
01-29-2010 03:34 AM
01-29-2010 04:08 AM - edited 01-29-2010 04:09 AM
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