LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Requesting single value from DAQ input on button press

You should NOT have a loop INSIDE of your state machine.  In the logging loop, you have a While Loop that runs until the Stop button is pressed.  That loops should not be there.  Your state machine is already set up correctly to come back into the Logging state.


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 11 of 21
(1,530 Views)

Ah, ok that makes sense. It must be that while loop that's interfering with the state machine operation. The purpose of that loop was to have the data write to the spreadhseet file at user definied intervals that were much slower than the running of the outer while loop. Is it possible to do this in the state machine (log every 10 seconds for example) without using an extra loop? If I set the main while loop to run every 10,000 ms, then surely it will take that long to switch between states and register button presses etc?

 

I'm VERY new to LabVIEW and obviously making a lot of beginner mistakes. I appreciate any help I can get.

0 Kudos
Message 12 of 21
(1,512 Views)

@MattEff wrote:

Is it possible to do this in the state machine (log every 10 seconds for example) without using an extra loop?


I normally have an "Idle" state that I use to check if any messages have been recieved and/or UI events (like button presses).  You can set the timeout of the Event Structure or Dequeue Element, etc to set the timing of your logging.  So you will go to the Log state, then to the Idle State with a timeout of whatever you need.  If the timeout happens, you just go back to the Log state and repeat.  You can even have the Idle state handle the pressing of the "Stop Logging" button and cause the Stop Logging state.


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 13 of 21
(1,502 Views)

Thanks for the quick reply. Would it be possible for you to show me an example of how that idle state would work with the timeout etc? Can the timeout be set by the user on the front panel?

 

 

0 Kudos
Message 14 of 21
(1,494 Views)

Hopefully this is enough to give you the idea.  I store what the timeout is supposed to be in a shift register so that any state can set the timeout.


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 15 of 21
(1,478 Views)

Thanks 🙂

 

I'm not 100% sure what's going on there but I'll have a play around tomorrow and see if I can get it working.

0 Kudos
Message 16 of 21
(1,468 Views)

Thanks so much for taking the time to show me how to do that. I've got it working now with the timeout event structure, however the 'stop logging' button press is not instant. It doesn't register until the timout is completed. I tried moving the button outside the event structure but that didn't seem to work. How can I make changes so that the 'stop logging' button press is recognised instantly?

 

 

0 Kudos
Message 17 of 21
(1,443 Views)

You have to "split up" the waiting into smaller chunks, like 50 mseconds. Bounce between a "Wait for timeout" and a "Check if time has elapsed" states in your state machine.

Message 18 of 21
(1,429 Views)

I have attached a zip, containing a small State Machine example, which i have made for educational purpose for students. So take it only as an example base, also this solution does not use Event Structure, but for small DAQ projects it is not really necessary...

Anyway, play and experiment with this project (first unzip the folder, and open the project file: "state_machine_2.lvproj", so you can see how I store the subVIs and type definied clusters inside a project). The "MAIN.vi" obviously the one which you need to run. 

Here I use type definied enums for the state machine, but you can also use strings, both are totally OK.

 

If you have questions, post them here, I (or someone from the forum) will try to help. It will be also useful if you attach your actual VI, and point out where you got problems during the development...

Good luck!

Message 19 of 21
(1,414 Views)

@MattEff wrote:

Thanks so much for taking the time to show me how to do that. I've got it working now with the timeout event structure, however the 'stop logging' button press is not instant. It doesn't register until the timout is completed. I tried moving the button outside the event structure but that didn't seem to work. How can I make changes so that the 'stop logging' button press is recognised instantly?


Did you make an event in the Event Structure for Stop Logging: Value Change?  I'm thinking you did not.


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 20 of 21
(1,403 Views)