Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

State Machine Starting Point

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

0 Kudos
Message 1 of 5
(4,082 Views)

Which versions of Visual Studio and Measruement Studio are you using? Also, what language are you working in?

Message Edited by EadieU on 03-20-2009 06:44 PM

Mark E.
National Instruments

0 Kudos
Message 2 of 5
(4,059 Views)

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. 

 


Mark E.
National Instruments

0 Kudos
Message 3 of 5
(4,053 Views)

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

0 Kudos
Message 4 of 5
(4,024 Views)

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?


Mark E.
National Instruments

0 Kudos
Message 5 of 5
(4,001 Views)