LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Producer/consumer acquisition - consumer timing & stopping

Simple Data Acquisition Program

 

Producer – Poll instrument for all available data (3-4 seconds to cycle through all Modbus addresses (17 addresses at 8bits = 136 elements))

Consumer – Plot the data to chart & update visual indicators + write to csv. (UI interaction will be minimal, changing Y scales, clear chart etc.)

 

Requirements - The user should be able to select how many ‘seconds per sample’ to chart. 1s, 5s, 10, 1minute, 1 hour etc.

 

Problem – Because the producer takes 3-4seconds to complete, the consumer can only run as fast as it receives the data (queue). So the fastest the chart can plot is 1 every 4s. Also, when clicking the ‘stop’ button, the program seems to take 5-7 seconds to stop (double the time of producer?). This feels a bit sluggish (What if the user selects 1hour sample rate, the loop will wait 1hour for the next iteration before stopping?).

 

Desired behaviour – If the user selects 1s per sample, the chart should plot every second (even though the data is only updated every 4 seconds). Ideally, I want it to just write the same value again every second until it changes (receives next value from queue). What would be the best way to achieve this behaviour?

 

Also when the user clicks stop, I would like it to stop immediately, as it will be polling for data that is no longer required by the user. I assume this is not possible, because the loop must finish its current job before stopping. Is there a better way to achieve this solution? I cannot speed up the loop timing, because the producer loop timing is decided by the time to acquire from the hardware (3-4s as mentioned above).

 

Any thoughts on this situation would be appreciated.

 

Thanks

0 Kudos
Message 1 of 12
(3,213 Views)

@labview_user123 wrote:

If the user selects 1s per sample, the chart should plot every second (even though the data is only updated every 4 seconds). Ideally, I want it to just write the same value again every second until it changes (receives next value from queue). What would be the best way to achieve this behavior?


You can, but not really desirable in any situation I have been in.  You could use the timeout on the queue and just use the previous value (stored in a shift register or feedback node) in the situation where you have a timeout.  But this could also add problems where the producer was just barely late and you will therefore get two data points really close together.  My suggestion is to have the update rate be no less than 5 seconds.

 


@labview_user123 wrote:

Also when the user clicks stop, I would like it to stop immediately, as it will be polling for data that is no longer required by the user. I assume this is not possible, because the loop must finish its current job before stopping. Is there a better way to achieve this solution? I cannot speed up the loop timing, because the producer loop timing is decided by the time to acquire from the hardware (3-4s as mentioned above).


I am assuming you are using a FOR loop for the acquiring of data from the Modbus.  You can move your stop button to be inside of the FOR loop and abort the loop early.  This can then trigger the outer loop to stop (just pass the last value out of the FOR loop and to the stop conditional of the While loop).  When this loop stops, send a message to the consumer to stop.


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
Message 2 of 12
(3,199 Views)

Hi 123,

 

set a timeout for the Dequeue function!

WHEN timeout THEN use previous data
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 12
(3,197 Views)

>Any thoughts ..

Are you asking for a quotation?

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

wiebe@CARYA wrote:

>Any thoughts ..

Are you asking for a quotation?


since this is more like a requirement specification then a question...

0 Kudos
Message 5 of 12
(3,179 Views)

Thanks for the replies, I will experiment with the timeout function and see if it is really necessary to use this method. I was thinking I need to integrate a shift register into this somehow.  I've always just left the timeout empty. Yes I could set a wait m/s to 5000 and have the minimum plot time as 5s. Then in multiples of 5 after that.

I am not using a for loop for modbus, but I assume I should be? I am still fairly new to this ! I just have all the addresses in a while loop. I have attached a picture. However, the forloop stop sounds like what I need to achieve. How would I modify this to use that instead?

 

0 Kudos
Message 6 of 12
(3,158 Views)

Hi 123,

 

use a loop with just one Modbus function inside.

Supply the needed parameters (register, count?) with an array each.

Use autoindexing of the loop…

Simple example:

check.png

(Provide parameters in an array, do something in the loop, provide an output array.)

You can enable a stop condition for FOR loops to implement a "break" feature (as suggested before)…

 

"Log start time" and "Log end time" should be read outside of the loop (before/after), no need for those case structures!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 7 of 12
(3,151 Views)

your time loggings and wait are not defined when they will run

here is an example to define exactly when these will be run

while-example.png


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
Download All
0 Kudos
Message 8 of 12
(3,149 Views)

@labview_user123 wrote:

Problem – Because the producer takes 3-4seconds to complete, the consumer can only run as fast as it receives the data (queue). So the fastest the chart can plot is 1 every 4s. Also, when clicking the ‘stop’ button, the program seems to take 5-7 seconds to stop (double the time of producer?).


This is to be expected by the Principle of Data Flow.  Look at your While Loop -- you have code that takes about 4 seconds to complete, plus a Stop Control wired to the While's Stop Indicator.  By Data Flow, your 4-second process and reading the Stop Control take place more-or-less at the same time, i.e. when the 4-second loop starts.  You now push the Stop button (say, after 1 second has passed), but its value has already been read (as False) and wired to the Stop indicator.  So that loop finishes, does not stop, and the next loop begins, now with the Stop Control = True.  So after 4 seconds, it stops.  Thus the "stopping time" is 4 seconds + however much time was left in the loop when you pushed Stop (on average, 2 seconds).

 

Bob Schor

0 Kudos
Message 9 of 12
(3,138 Views)

Thanks for the suggestions, you have greatly improved my code already.

The for loop and break were exactly what I needed.

I had an issue with the dequeue waiting indefinitely when i pressed stop, due to no timeout. I have added some logic to that, which I found from another thread on here: if stop = true > timeout = 50ms > else timeout = -1

Is this what you meant by reading start/stop time before/after loop?

Thanks again,

0 Kudos
Message 10 of 12
(3,090 Views)