State Machine

State Machine是一个在工控中常用的程序构架。adeStateMachine 封装于LVOOP Class,不但提供常用的功能,而且有像延时,循环等高级功能,更重要的一点是它支持异步程序操作(Asyncronized Operation)。这些功能在工控中常用,因此使用这样的程序结构和这个State Machine就可以基本上满足90%以上的应用场景。在我们20年的工作经验中,首先想到的就是使用这个。

更重要的一点是这个使用adeStateMachine的结构还具有可扩展功能,因此几乎百分百的程序开始使用的都是这个结构。我们将在后面介绍如何在这个结构上进行扩展,使程序无限制的扩大,使多个人可以同时为一个程序工作。目前让我们先熟悉这个使用adeStateMachine 的程序结构吧。请下载源程序,它包含使用说明书,范例,模板等。

Download link: files.cnblogs.com/files/adetech/adeStateMachineBasic.zip  (adeStateMachineBasic.zip)

 

adeStateMachine and adeScriptEngine

The state is written in the native LabVIEW OO and it resembles JKI’s state machine, but it has a lot more power. The package comes with a sample architecture main vi which is powerful enough and therefore can be used as the starting point for many applications.

adeScriptEngine is inherited from adeStateMachine.  It has full features of the state machine and it has more.  It tends to load a script from a file together with instructions to users and it has more program flow control such as “goto”.

Object Name

adeStateMachineBasic

 

  • Command>>parameter
  • Multiple commands are to be separated by carriage return
  • // can be used to comment out a command line
  • The main loop has to have an “Idle” case (default)
  • When there is an error, state case = Error Handler
  • Timeout should NOT be -1 if the full set of build-in commands are to be utilized

 

Methods

INIT

To be called once and input startup states

GetCommand

Get the current command and parameter from the object

AddCommands

Push multiple commands into the object, can be on top of the queue or/and appended to the end

Internal

Commands

ade_Clear

Reset the object and then the command queue

Used to stop all command execution

It does not clear Commands associated to ade_Lock

 

ade_Dwell>>time

Program will stay on this command for given period of time.  The timeout should not be 0 to use it.  Actual dwell time is a little more than the given.

 

ade_asynDwell>>time

This command should always be used in pair:

ade_asynDwell>>1000

command …..

ade_asynDwell

 

Kick off dwell timer but continue to run commands followed.  Program will evaluate the elapsed time at the second ade_asynDwell command then wait or continue

 

ade_Pause>>timeout

It is normally used to pause the program and wait for an event where ade_Continue is called to continue the program flow.  timeout <= 0 is equivalent to 2 hours.

 

If timeout occurs, program goes to Error Handler with parameter = ade_Pause_Timeout.  This should be handled in customer program accordingly.

 

This command can also be used to pause a script or sequence it is running.  Use ade_Continue to resume program flow.

 

ade_Continue

This is used to remove ade_Pause or ade_Dwell to resume program flow.

 

 

ade_Lock>>Option

When Lock is on, the state machine will not register any command except specified Exception commands and internal command starting with “ade_”.

 

Option = 0:  Unlock

Option = 1:  Lock

Option = cmd1,cmd2,…  :register exception commands

 

ade_Clear will clear the lock but not exception commands.

 

This is useful when the program is running a sequence, at which time, program does not want to be disturbed by some manual commands.

 

ade_Log>>Option

Option = 0: Do not log

Option = 1: Do log

Option = -1: Delete the log file

 

Log file is adeLog.txt in user/tmp directory.  This logging facility is extremely useful for debugging purpose, so it should always be turn on until formal software release.

posted on 2017-05-04 05:33  ade-tech  阅读(208)  评论(0编辑  收藏  举报