LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

State machine: continuous data logging every X seconds ?

Hello community,

 

currently I am learning the state machine concept. What I fail to understand is how I would set up a continous data logging without the user pressing some button?

 

I want to have my hardware buffer read every 0.5 seconds. So my cycle should be something like this:

 

Initialize > Wait > 0.5s elapsed > Aqcuire > Analyse > Log > Wait

 

But how would I implement the "wait 0.5 s" event and how would I still have it responsive to user interactions?

 

Thank you for your advice

Martin

0 Kudos
Message 1 of 8
(1,662 Views)

Hi mw,

 

you can check user actions after each state is executed. In this case reaction to user input may be delayed by 0.5s when there is a state like "wait(500ms)". Is this acceptable for your users?

 

Another option is to have a state "wait(100ms)" and call this state 5 times to realize a delay of 0.5s.

 

Third option is to have a state "wait(500ms)", but have a loop in this state which stops after 500ms or earlier, when a specific user action is detected.

 

There are so many options…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 8
(1,660 Views)

@mw42 wrote:

Hello community,

 

currently I am learning the state machine concept. What I fail to understand is how I would set up a continous data logging without the user pressing some button?

 

I want to have my hardware buffer read every 0.5 seconds. So my cycle should be something like this:

 

Initialize > Wait > 0.5s elapsed > Aqcuire > Analyse > Log > Wait

 

But how would I implement the "wait 0.5 s" event and how would I still have it responsive to user interactions?

 

Thank you for your advice

Martin


How about a "Timer" or "wait" state? 

 

s1Capture.PNG

 

The state waits for the scan interval to elapse and it also checks the day of the year.

IF the day of the year is not equal to the last time it checked go to the "Close File" state

Else go to "Measure" state

 

This is because I needed new file to be created every day. So when the day changes it closes the current data file opens a new one and then takes a measurement

 

Now polling a timer in a loop is probably not the best way, as you can't really do anything else at the same time.

 

But for simple data loggers it works fine.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 3 of 8
(1,636 Views)

Thank you both for your advice. I will try and implement all those suggestions and see if they work for me.

0 Kudos
Message 4 of 8
(1,591 Views)

I have tried to modify the "event-drive state machine pattern" from the "LabView Core 2" course. Unfortunately it failed so far.

 

What I fail to understand is why my Streamchannel won't change the status of my "Time elapsed OUTPUT" indicator (in the screenshot, the indicator is outside of the event structure but this was only for testing, since it didn't work at either location)

 

My idea was to have a second while loop (as suggested for "elapsed time" purposes). Was my idea correct or does it have design flaws in it?

 

I've made two screenshots and attached my code.

 

Part of the codePart of the codeFrontpanelFrontpanel

0 Kudos
Message 5 of 8
(1,541 Views)

Writing to a terminal will not cause an event.  So your event structure is not seeing any events.  Try using a User Event.


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
0 Kudos
Message 6 of 8
(1,527 Views)

A stream channel seem a bit overkill for this application...

 

Try a Value(Signaling) Property Node for your Time Elapsed Output indicator and writing to that in your timer loop.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 7 of 8
(1,521 Views)

I think that I now understand the problem and have been able to fix it.

 

Attached is my working solution (the program adds "+1" every 0.5 seconds and there are "minus 1" and "plus 1" buttons for user interaction).

 

Any further advice on my design?

0 Kudos
Message 8 of 8
(1,488 Views)