LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Structuring Code For Manual, Record, Play Mode

Solved!
Go to solution

Sorry, I guess there was some confusion about how state machines work.  But no worries, I think with a little patience and explanation you'll come to like this architecture and realize its full potential. Basically, the concept is based off a flow chart of your program.  If you can draw a flow chart, you can make a state machine. Thus, I cleaned up your code a bit and re-attached.

 

First, I don't have the Arduino Toolkit or an Arduino for testing on this comp, so I don't know error 5003.  You may want to ask the Arduino guys about this. For future reference, please post some text or a screen shot if you need help with your errors.  The more information, without assumptions, the better.

 

Second, I can understand why Playback doesn't work.  Like I commented inside the Playback case, you're going to need to split the Playback section into different pieces if you want to continue to use this particular state machine architecture.  See the loop you have inside the Playback case?  The waveform graph indicator on the front panel is not inside this loop - it's inside the outer most loop - thus it will only get updates when the state "Playback" finishes.  I don't have your data set, but I bet you see a data "dump" all at once when you run this case, rather than individual data points one-at-a-time.

 

The only difference in my implementation of Manual Mode and Record Mode was based off what you originally described those two cases as, namely, that Manual Mode started reading data right away and until the user said stop and that Record Mode waited for the user to click a button and start the acquisition. This is the reason why both modes use the same "Acquire" state, because eventually both states do just that, acquire data.  More importantly, they acquire it in the exact same way which is why we can re-use the Acquire state. If you notice in the "Wait for User" case, when the user says Manual Mode > Go, you immediately initialize the instrument and start acquiring, whereas when the user says Recod Mode > Go you will go to the "Wait for Record Start" state to wait for the user to click the Start button.

 

Lastly, I had intended on you putting the Arduino Init and Close VI's inside the "Instr Init" and "Instr Close" cases and use a shift register to hold the reference to the Arduino between various states.  You could technically put the VI's in the "VI Init" and "VI Close" case, as you did, but for this particular code there is a tiny bit of modification needed and the shift register was still missing.

 

When in doubt, use Highlight Execution to see the flow of your program. Then you'll know that your logic is either correct or flawed and can debug from there.

 

You should be able to run my attached code without an Arduino (just so you can see the flow of the program and avoid error 5003) by clicking "Simulate Arduino?" on the FP.

Message 11 of 14
(495 Views)
Solution
Accepted by Carlr

Oops, did I forget to attach the modified files to the last 2010.zip attachment? Try this one instead...

0 Kudos
Message 12 of 14
(475 Views)

Thanks for all your help with this. I have amnaged to get something together which is working. I had to add an extra state in the initiate the Arduino for the record function. I'm sure there are more elegant ways of doing this fix, but my code is now working. The code is attached.

0 Kudos
Message 13 of 14
(451 Views)

Nice work, Carl. One last suggestion --> don't forget to close the text file reference (Close File.vi) in the Acquire state after writing the string value to it.  It's probably not going to make much difference for your application now, but if it'd ever scaled and got to the point where you were running long-time acquisitions, you could run into memory or performance issues by continually opening references without closing them. Anyhoo, just a heads up.

0 Kudos
Message 14 of 14
(439 Views)