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.
  1. To develop a process simulator logic
  2. Create the ProcessVariableSimulator object:
    1. In
      Project view
      , right-click
      Model
      and select
      New
      Object
      .
    2. Hover-over the object, select
      Edit
      , and enter
      ProcessVariableSimulator
      .
    3. In
      Properties
      , add four variables by selecting
      Add
      and selecting
      Variable
      .
    4. Rename the variables by hovering-over each variable, selecting
      Edit
      and entering:
      • IsRunning
      • Message
      • Step
      • Value
    5. Next to
      IsRunning
      , select
      Int32
      and select
      Boolean
      .
    6. Next to
      Message
      , select
      Int32
      and select
      String
      .
  3. Develop the ProcessVariableSimulatorLogic script:
    1. Right-click
      ProcessVariableSimulator
      and select
      New
      Runtime NetLogic
      .
    2. Hover-over the NetLogic, select
      Edit
      , and enter
      ProcessVariableSimulatorLogic
    3. Double-click the NetLogic.
      The external code editor opens.
    4. 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; }
    5. Save the code.
  4. Convert the ProcessVariableSimulatorLogic object into an object type:
    1. In
      Type view
      , double-click
      Model
      .
    2. Drag
      ProcessVariableSImulator
      from
      Project view
      into
      Type view
      .
  5. Create the ProcessVariableSimulator1 object by dragging
    ProcessVariableSImulator
    from
    Type view
    into the
    Model
    folder in
    Project view
    .
  6. Configure the ProcessVariableSimulator1 object:
    1. In
      Properties
      , set
      IsRunning
      to
      True
      .
    2. Set
      Step
      to
      1
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.