Programsare complex Functionsin a Serveror underlying system that can be invoked and managed by a Client. Programscan represent any level of functionality within a system or process in which Clientcontrol or intervention is required and progress monitoring is desired. Figure 2illustrates the model.

image005.png

Figure 2– Program illustration

Programsare stateful and transition through a prescribed sequence of states as they execute. Their behaviour is defined by a Program Finite State Machine (PFSM). The elements of the PFSM describe the phases of a Program’s execution in terms of valid transitions between a set of states, the stimuli or causes of those transitions, and the resultant effects of the transitions.

Since Programscan be used to perform advanced control algorithms or other actions, their use should be restricted to personnel with appropriate access rights. It is recommended that AuditUpdateMethodEventsare generated to allow monitoring the number of running Programsin addition to their execution frequency.

The states, transitions, causes and effects that compose the Program Finite State Machineare listed in Table 1and illustrated in Figure 3.

Table 1– Program Machine

No.

Transition name

Cause

From state

To state

Effect

1

HaltedToReady

Reset Method

Halted

Ready

Report Transition 1 Event/Result

2

ReadyToRunning

Start Method

Ready

Running

Report Transition 2 Event/Result

3

RunningToHalted

Halt Method or Internal (Error)

Running

Halted

Report Transition 3 Event/Result

4

RunningToReady

Internal

Running

Ready

Report Transition 4 Event/Result

5

RunningToSuspended

Suspend Method

Running

Suspended

Report Transition 5 Event/Result

6

SuspendedToRunning

Resume Method

Suspended

Running

Report Transition 6 Event/Result

7

SuspendedToHalted

Halt Method

Suspended

Halted

Report Transition 7 Event/Result

8

SuspendedToReady

Internal

Suspended

Ready

Report Transition 8 Event/Result

9

ReadyToHalted

Halt Method

Ready

Halted

Report Transition 9 Event/Result

image006.png

Figure 3– Program states and transitions

A standard set of base states is defined for Programs as part of the Program Finite State Machine.These states represent the stages in which a Programcan exist at an instant in time as viewed by a Client. This state is the Program’s current state. All Programsshall support this base set. A Programmay or may not require a Clientaction to cause the state to change. The states are formally defined in Table 2.

Table 2– Program states

State

Description

Ready

The Programis properly initialized and may be started.

Running

The Programis executing making progress towards completion.

Suspended

The Programhas been stopped prior to reaching a terminal state but may be resumed.

Halted

The Programis in a terminal or failed state, and it cannot be started or resumed without being reset.

The set of states defined to describe a Programcan be expanded. Programsubstates can be defined for the base states to provide more resolution of a process and to describe the cause and effect(s) of additional stimuli and transitions. Standards bodies and industry groups may extend the base Program Finite State Modelto conform to various industry models. For example, the Halted state can include the substates “Aborted” and “Completed” to indicate if the Function achieved a successful conclusion prior to the transition to Halted. Transitional states such as “Starting” or “Suspending” might also be extensions of the Running state, for example.

A standard set of state transitions is defined for the Machine. These transitions define the valid changes to the Program’scurrent state in terms of an initial state and a resultant state. The transitions are formally defined in Table 3.

Table 3– Program state transitions

Transition no.

Transition name

Initial state

Resultant state

1

HaltedToReady

Halted

Ready

2

ReadyToRunning

Ready

Running

3

RunningToHalted

Running

Halted

4

RunningToReady

Running

Ready

5

RunningToSuspended

Running

Suspended

6

SuspendedToRunning

Suspended

Running

7

SuspendedToHalted

Suspended

Halted

8

SuspendedToReady

Suspended

Ready

9

ReadyToHalted

Ready

Halted

The stimuli or causes for a Program’sstate transitions can be internal to the Serveror external. The completion of machining steps, the detection of an alarm condition, or the transmission of a data packet are examples of internal stimuli. Methodsare an example of external stimuli. Standard Methodsare defined which act as stimuli for the control of a Program.

Clients manage a Programby calling Methods.The Methodsimpact a Program’sbehaviour by causing specified state transitions. The state transitions dictate the actions performed by the Program. This standard defines a set of standard Program Control Methods. These Methodsprovide sufficient means for a Clientto run a Program.

Table 4lists the set of defined Program Control Methods. EachMethodcauses transitions from specified states and shall be called when the Programis in one of those states.

IndividualPrograms can optionally support any subset of the Program Control Methods. For example, somePrograms may not be permitted to suspend and so would not provide theSuspend andResume Methods.

Programs can support additional user defined Methods. User definedMethods shall not change the behaviour of the base Program Finite State Machine.

Table 4– Program Control Methods

Method Name

Description

Start

Causes the Programto transition from the Ready state to the Running state.

Suspend

Causes the Programto transition from the Running state to the Suspended state.

Resume

Causes the Programto transition from the Suspended state to the Running state.

Halt

Causes the Programto transition from the Ready, Running or Suspended state to the Halted state.

Reset

Causes the Programto transition from the Halted state to the Ready state.

All Program Control Methodsare defined with their BrowseNameon the ProgramStateMachineTypewith the OptionalPlaceholder ModellingRule. As defined in OPC 10000-3, this rule allows the inclusion of Argumentsto these Methods on sub-types or on instances.For example, a Start Methodmay include an options argument that specifies dynamic options used to determine some program behaviour. The Method Callservice specified in OPC 10000-4defines a return status. This return status indicates the success of the Program Control Methodor a reason for its failure.

A Program’s state transition generally has a cause and also yields an effect. The effect is a by product of a Programstate transition that can be used by a Clientto monitor the progress of the Program. Effects can be internal or external. An external effect of a state transition is the generation of an Eventnotification. Each Programstate transition is associated with a unique Event. These Eventsreflect the progression and trajectory of the Programthrough its set of defined states. The internal effects of a state transition can be the performance of some programmatic action such as the generation of data.

Result data is generated by a running Program. The result data can be intermediate or final. Result data may be associated with specific Program state transitions.

Intermediate result data is transient and is generated by the Program in conjunction with non- terminal state transitions. The data items that compose the intermediate results are defined in association with specific Programstate transitions. Their values are relevant only at the transition level.

Each Programstate transition can be associated with different result data items. Alternately, a set of transitions can share a result data item. Percentage complete is an example of intermediate result data. The value of percentage complete is produced when the state transition occurs and is available to the Client.

Clientsacquire intermediate result data by subscribing to Programstate transition Events. The Eventsspecify the data items for each transition. When the transition occurs, the generated Eventconveys the result data values captured to the subscribed Clients. If no Clientis monitoring the Program, intermediate result data may be discarded.

Terminal result data is the final data generated by the Program as it ceases execution. Total execution time, number of widgets produced, and fault condition encountered are examples of terminal result data. When the Programenters the terminal state, this result data can be conveyed to the Clientby the transition Event. Terminal result data is also available within the Program to be read by a Clientafter the program stops. This data persists until the ProgramInstance is rerun or deleted.

Clientscan monitor the activities associated with a Program’sexecution. These activities include the invocation of the management Methods, the generation of result data, and the progression of the Programthrough its states. Audit Eventsare provided for Method Callsand state transitions. These Eventsallow a record to be maintained of the Clientsthat interacted with any Programand the Programstate transitions that resulted from that interaction.

Programs can havedifferent lifetimes. Some Programs may always be present on a Serverwhile others are created and removed. Creation and removal can be controlled by a Clientor may be restricted to local means.

A Programcan be Clientcreatable. If a Programis Clientcreatable, then the Clientcan add the Programto the Server. The Object Create Methoddefined in OPC 10000-3, is used to create the Programinstance. The initial state of the Programcan be Halted or Ready. Some Programs, for example, may require that a resource becomes available after its creation and before it is ready to run. In this case, it would be initialized in the Halted state and transition to Ready when the resource is delivered.

A Programcan be Clientremovable. If the Programis Clientremovable, then the Clientcan delete the Programinstance from the Server. The DeleteNodes Servicedefined in OPC 10000-4is used to remove the ProgramInstance. The Programshall be in a Halted state to be removed. A Programmay also be auto removable. An auto removable Programdeletes itself when execution has terminated.

Programscan be multiple instanced or single instanced. A Servercan support multiple instances of a Program if theseProgram Instancescan be run in parallel. For example, the Programmay define a Start Methodthat has an input argument to specify which resource is acted upon by its Functions. Each instance of the Program is then started designating use of different resources. The Clientcan discover all instances of a Programthat are running on a Server. Each instance of a Programis uniquely identified on the Server and is managed independently by the Client.

Programscan be run once or run multiple times (recycled). A Programthat is run once will remain in the Haltedstate indefinitely once it has run. The normal course of action would be to delete it following the inspection of its terminal results.

Recyclable Programsmay have a limited or unlimited cycle count. These Programsmay require a reset step to transition from the Halted state to the Ready state. This allows for replenishing resources or reinitializing parameters prior to restarting the Program. The Program Control MethodReset”triggers this state transition and any associated actions or effects.