03-19-2009 12:36 PM
Hi,
I have a fairly limited set of measurements I need to make with a few different Network Anlyzers: Snn and Snm type measurements, the full range of possible calibrations available on each instrument, data display controls, and data retrieval. I had the instrument control working fine until our UI changed and I realized we were operating sequentially and tied to ModalDialog - DialogResults statements to force, in effect, the instrument to wait until the operator wanted to continue the sequence. Poor design, I know.
I'm looking for a good starting point for implementing a state machine with measurement studio and window form in a standalone app. I understand the theory of state machines but rumaging through the tubes the examples / implementations of state machine vary greatly in complexity and scope and examples with on/off switches are only so helpful. Being as I'm building a state machine around a Network Analyzer and using NI tools for instrumentation control I thought I'd ask the kind folks at this forum.
General and specific help appreciated.
Thanks,
pete
03-20-2009 06:41 PM - edited 03-20-2009 06:44 PM
Which versions of Visual Studio and Measruement Studio are you using? Also, what language are you working in?
03-20-2009 06:53 PM
Finite State Machine code developed in Visual Studio .NET 2003* from An Introduction to Finite State Machines. I recommend reading that article so you have the context for that code. If nothing else, it's a good intro to finite state machines.
Note: this code is not done with Measurement Studio, but this should get you started working with a state machine in Visual Studio.
03-23-2009 12:42 PM
Hi Mark,
Thanks for the info, I'm using C#, VS 2005 and Meas. Studio 8.6. I can't say c++ is my strong suit but I'll see if there is anything I can glean.
Here's my current model. Does this seem reasonable? Is there anything you would add / subtract / change?
*NetworkAnalyzer : State Machine
properties
- CurrentState
- Initialized
methods
- Next (calls current state's next method)
- Back
- Cancel
- Initialize
- GetData
- ChangeState
event handlers
- this handles Perform events and issues instrument specific commands
*NWAState : abstract base state
methods
- Next (virtual method)
- ChangeState(sets NetworkAnalyzer current state)
- Cancel (sends NetworkAnalyzer to cancel state)
events
- ShowInstructions (to inform UI when to show instructions to the operator)
- Perform (to inform SM to issue instrument commands)
-- specific states
*ThruState : NWA derived state
*OnePortAState : NWA derived state
*OnePortBState : NWA derived state
*OnePortCState : NWA derived state
*InitializedState : NWA derived state
*NotInitializedState : NWA derived state
*CancelledState : NWA derived state
*MeasurementState : NWA derived state
*MeasurementCompleteState : NWA derived state
-
Thanks so much,
peter
03-24-2009 02:17 PM
Without understanding your overall application, I am unable to comment on your architecture. However, a couple questions you should ask yourself are
1) Do the state transitions match your flowchart? If you haven't drawn a flowchart, you need to. It is what you should test your code against to verify that your code does what you want it to do.
2) Are all possible cases handled such that your code doesn't stick in an endless loop or that you don't crash out in unhandled errors?