Develop a process simulator logic
    Develop a logic that will simulate a long-running task.
Prerequisites
Set the default external code editor. See Set the default code editor.
- To develop a process simulator logic
 - Create the ProcessVariableSimulator object:
- InProject view, right-clickModeland select .
 - Hover-over the object, select, and enter
ProcessVariableSimulator. - InProperties, add four variables by selectingand selecting
Variable. - Rename the variables by hovering-over each variable, selectingand entering:

- IsRunning
 - Message
 - Step
 - Value
 
 - Next toIsRunning, selectInt32and selectBoolean.
 - Next toMessage, selectInt32and selectString.
 
 - Develop the ProcessVariableSimulatorLogic script:
- Right-clickProcessVariableSimulatorand select .
 - Hover-over the NetLogic, select, and enter
ProcessVariableSimulatorLogic - Double-click the NetLogic.The external code editor opens.
 - Replace the existing code with the following code:using System.Threading; using UAManagedCore; public class ProcessVariableSimulatorLogic : FTOptix.NetLogic.BaseNetLogic { public override void Start() { var owner = (ProcessVariableSimulator)LogicObject.Owner; valueVariable = owner.ValueVariable; stepVariable = owner.StepVariable; messageVariable = owner.MessageVariable; isRunningVariable = owner.IsRunningVariable; increment = true; periodicTask = new PeriodicTask(IncrementDecrementTask, 500, LogicObject); periodicTask.Start(); longRunningTask = new LongRunningTask(MessageTask, LogicObject); longRunningTask.Start(); } public override void Stop() { periodicTask.Dispose(); periodicTask = null; longRunningTask.Dispose(); longRunningTask = null; } [FTOptix.NetLogic.ExportMethod] public void StartMethod() { periodicTask.Start(); isRunningVariable.Value = true; } [FTOptix.NetLogic.ExportMethod] public void StopMethod() { periodicTask.Cancel(); isRunningVariable.Value = false; } public void IncrementDecrementTask() { int currentValue = valueVariable.Value; int step = stepVariable.Value; if (increment) { currentValue += step; if (currentValue >= 100) { currentValue = 100; increment = false; } } else { currentValue -= step; if (currentValue <= 0) { currentValue = 0; increment = true; } } valueVariable.Value = currentValue; } public void MessageTask() { Thread.Sleep(2000); messageVariable.Value = "PHASE 1"; Thread.Sleep(2000); messageVariable.Value = "PHASE 2"; Thread.Sleep(2000); messageVariable.Value = "PHASE 3"; Thread.Sleep(2000); messageVariable.Value = "PHASE 4"; } private IUAVariable valueVariable; private IUAVariable stepVariable; private IUAVariable messageVariable; private IUAVariable isRunningVariable; private bool increment; private PeriodicTask periodicTask; private LongRunningTask longRunningTask; }
 - Save the code.
 
 - Convert the ProcessVariableSimulatorLogic object into an object type:
- InType view, double-clickModel.
 - DragProcessVariableSImulatorfromProject viewintoType view.
 
 - Create the ProcessVariableSimulator1 object by draggingProcessVariableSImulatorfromType viewinto theModelfolder inProject view.
 - Configure the ProcessVariableSimulator1 object:
- InProperties, setIsRunningtoTrue.
 - SetStepto1
 
 
Provide Feedback