Usage

C# project with RapidSequencer Library

Requirement

  • RapidCode library

  • Need Administrator privilege to run Visual Studio

  • INtime node must be running

Setup

  • Create a C# project

  • Add RapidSequencerAPI.NET.dll as a reference to the project

Usage

Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RSI.RapidSequencerAPI;
using System.IO;

namespace SampleApp.Net
{
  class Program
  {
    static void Main(string[] args)
    {
      const string sequencerNodeName = "NodeA";
      const string rmpNodeName = "NodeA";
      const uint waitTimeMs = 10000;
      string workingDir = System.IO.Directory.GetCurrentDirectory();
      const string sequencerScriptPath = "script/samplescript.sq";
      const string mainFunctionName = "main";

      RapidSequencer rsq = RapidSequencer.Create(sequencerNodeName, RapidSequencer.Platform.Windows);

      // Check RapidSequencer is Running
      RapidSequencer.RapidSequencerState sqState = rsq.ProcessStateGet();
      if (sqState != RapidSequencer.RapidSequencerState.Running)
      {
        // this will block for WaitTime duration. Starting Processes take times, especially on Platform.INtime.
        rsq.ProcessStart(workingDir, rmpNodeName, waitTimeMs);
      }

      // Check VirtulMachine is Operational
      VirtualMachineState vmState = rsq.VirtualMachineStatusGet().state;
      if (vmState != VirtualMachineState.Operational)
      {
        // exit. Recheck dependencies to make sure everything is properly setup. or Restart
        System.Environment.Exit(-1);
      }

      // Clear compile status before you compile or run program
      rsq.ClearCompileStatus();
      rsq.Run(sequencerScriptPath, mainFunctionName);

      // Wait for Program to be compiled
      while (rsq.CompileStatusGet().state == CompileState.Compiling)
      {
        System.Threading.Thread.Sleep(100);
      }
      if (rsq.CompileStatusGet().state == CompileState.Failure)
      {
        Console.WriteLine("Compile Failed!");
        System.Environment.Exit(-1);
      }

      // Wait for Program to be run and completed
      while (rsq.SequencerStatusGet().state == ThreadState.Running)
      {
        System.Threading.Thread.Sleep(100);
      }
      if (rsq.SequencerStatusGet().state != ThreadState.Idle)
      {
        Console.WriteLine("Run Failed!");
        System.Environment.Exit(-1);
      }

      // Get Output from RapidSequencer
      String output = rsq.ConsoleOutputGet();
      Console.WriteLine(output);

      // Shutdown RapidSequencer
      rsq.ProcessShutdown();
      rsq.Dispose();
    }
  }
}

RapidSequencer API functions

All the RapidSequencer API functions are documented details in this link. The most important functions are described in the below table.

Return

Function

Description

Create a connection object to communicate with the RapidSequencer process.

Returns a state of RapidSequencer process.

bool

Starts a RapidSequencer process.

bool

Compiles a given RapidSequencer script.

bool

Compiles and runs a given RapidSequencer script.

string

Returns the output of RapidSequencer's console.

bool

Stops all running threads. Does NOT shutdown the sequencer.

bool

Shutdown the RapidSequencer process.

Last updated