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

C#
Sequencer Script
Output
C#
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();
}
}
}
Sequencer Script
script/samplescript.sq
void main()
{
for(int32 i=0; i<5; ++i)
{
print(""+i);
}
}
Output
Console
Compile Success!
14:26:24.802 - 0
14:26:24.803 - 1
14:26:24.803 - 2
14:26:24.803 - 3
14:26:24.803 - 4
Press any key to continue . . .

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

RapidSequencer

RapidSequencer.Create(string _nodeName, Platform _Platform)

Create a connection object to communicate with the RapidSequencer process.

RapidSequencerState

ProcessStateGet()

Returns a state of RapidSequencer process.

bool

ProcessStart(string _workingDir, string _rmpNodeName, uint _waitTimeMs)

Starts a RapidSequencer process.

bool

Compile(string _sequencerScriptPath, string _mainFunctionName)

Compiles a given RapidSequencer script.

bool

Run(string _sequencerScriptPath, string _mainFunctionName)

Compiles and runs a given RapidSequencer script.

string

ConsoleOutputGet()

Returns the output of RapidSequencer's console.

bool

StopThreads()

Stops all running threads. Does NOT shutdown the sequencer.

bool

ProcessShutDown()

Shutdown the RapidSequencer process.