LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

event structure with local variable

Solved!
Go to solution

Hi, everybody .. I have been trying to do a simple program with event structure in Labview.
I need to show a value in a chart, only when a external signal changes its value. (I have read many threads and many documents and I dont get the trick... sorry)
I mean I'm obtaining a temperature value from a sensor in a PLC, this sensor works in a asyncronous mode, so the sensor obtains a new value in diferent sample rate.
So the PLC program changes the state of a simple boolean variable wich indicates to Labview, that there is a new data (newdatareceived ----> 1,0,1,0,1,0....)
I need that Labview draw the value (valuereceived) in a chart only when this variable (newdatarecived) changes.
My problem is that the chart always puts a value according to the cycle time in its loop, and repeats values... (I have tried it, with dynamics events and with Signaling value... and I have got the same result... It don't works properly).
Thanks in advanced.mode1

And in other way:

mode2.PNG

Thanks for your time again.

0 Kudos
Message 1 of 12
(4,596 Views)

I think you may want a case structure.  When newdatareceived is true, write to the chart.  When it is false, do nothing.  Simple.

 

You can probably get rid of all the local variables with a little thought.  I cannot be sure since you only show a small portion of your program.

 

Lynn

0 Kudos
Message 2 of 12
(4,589 Views)

The first trick is not to put any wait function in the while loop containing your event structure (I recommend your second approach). The event structure has a timeout case by default, which in your case will not be activated if you keep the value -1 connected to the timeout input as you are doing currently (or nothing, which is the same). In this case, the loop iterates only when there is an event (Stop button pressed or boolean value change). Of course you have to handle the "Stop pressed" as an event, as I show on the attached VI.

The second trick is to CHECK what the value of "Data Received" is when you receive info that its value has "changed". Indeed, the way you have written the DAQ loop forces a "value change" every 300 ms even if the boolean value is really exactly the same as during the previous 300 ms. This is probably not how your actual DAQ loop will look like, but anyway...

You may want to look into a queue structure to pass data from one loop to the other.

HTH.

 

 

 Edit: Just noticed that Lynn beat me to the finish line...

0 Kudos
Message 3 of 12
(4,588 Views)

A better way would be to use user events. Do a search on user events and check out the documentation.

 

[Edit: Ooops - you were using Val(SIgnaling). It will fire each time you write to it even if it is the same value. It is not a ValChanged(Signaling) property. X and Lynn beat me to it]

=====================
LabVIEW 2012


0 Kudos
Message 4 of 12
(4,583 Views)

Since your data is presumably not spaced equally in time, it makes little sense to use a chart. To retain time information on the x-axis, you should probably use an xy graph instead.

 

I also don't think you even need an event structure for all this. Overall, you seems to have 5x too much code for this simple task. 😉

 

If you only want to chart a value if it is different from the previous value, all you need is a feedback node where you compare current and previous and then conditionally add the data to the chart based on the comparison. Having the additional "newdatareceived" boolean seems redundant and only makes sense if you also want to graph successive values even if they are equal.

 

Cah you show us the code where the data is received?

0 Kudos
Message 5 of 12
(4,571 Views)
"
Download All
0 Kudos
Message 6 of 12
(4,545 Views)

Thanks

I have been making a little test with xygraph and the example now works (Thanks!!!) but I have a doubt, Is this the correct method or is there a better way?

 

 

 

 

 

Download All
0 Kudos
Message 7 of 12
(4,527 Views)

X.

Thanks, I'm reading again your response (sorry but my english is not too good)

 

"The second trick is to CHECK what the value of "Data Received" is when you receive info that its value has "changed". Indeed, the way you have written the DAQ loop forces a "value change" every 300 ms even if the boolean value is really exactly the same as during the previous 300 ms. This is probably not how your actual DAQ loop will look like, but anyway...

You may want to look into a queue structure to pass data from one loop to the other."

 

Ok the reason why the system doesn't works its because I cant use the signaling value property in this way, due to the event will be fired every loop althought the signal value not changes (correct?) , you suggest me that I must use queue structure... is this the same that state machine?

(I'll find information about it... thanks)

0 Kudos
Message 8 of 12
(4,512 Views)
0 Kudos
Message 9 of 12
(4,495 Views)
Solution
Accepted by topic author sruedat

sruedat wrote:

I have been making a little test with xygraph and the example now works (Thanks!!!) but I have a doubt, Is this the correct method or is there a better way?


No, this code makes no sense. You are writing new (mostly the same!) points to the xy graph with every iteration (actually at twice the speed that data can actually arrive:100ms vs 200ms!), taxing the system unecessarily and growing internal data structures like crazy.

 

All you need is a single loop with a single case structure that goes true if the boolean is different from the previous iteration. At this time, you would add a point (elapsed time for X, value for Y ) to the xy graph. Here's a quick draft. (You can either use the elapsed time or the counter for X, depending on your needs, so modify as needed).

 

Events are primarily for user interaction to prevent the loop from spinning unless needed. Here you are already spinning a loop to query the instrument and you can easily have the graph ride the same loop. Right?

 

You should also be aware that execution order is determined by dataflow, and not by horizontal position. If it matters which of the OCX nodes executes first in an iteration, you need to create a proper data dependency (e.g. with the error wire). Offsetting them horizontally has no effect. Also the sequence structure on the left has no function, so why is it there?

Message 10 of 12
(4,489 Views)