Learn to interact with global data in a RapidScript program.
- Warning
- This is a sample program to assist in the integration of the RMP motion controller with your application. It may not contain all of the logic and safety features that your application requires. We recommend that you wire an external hardware emergency stop (e-stop) button for safety when using our code sample apps. Doing so will help ensure the safety of you and those around you and will prevent potential injury or damage.
The sample apps assume that the system (network, axes, I/O) are configured prior to running the code featured in the sample app. See the Configuration page for more information.
📜 Running a RapidScript Program Asynchronously
The code snippet below demonstrates how to run a RapidScript program asynchronously. The sequencer.Run()
waits for the RapidScript program to finish execution, but sequencer.RunAsync()
will return regardless of the program's execution status. In this case, the program being run does not terminate, so RunAsync()
is used in order to allow the rest of the code in the sample application to execute.
string rmpPath = TestContext.CurrentContext.TestDirectory;
sequencer.
Compile(samplesDirectory +
"BasicGlobalData.sq",
"main");
Thread.Sleep(1000);
📜 RapidScript Program with Global Data
The code below is an example RapidScript program with global values.
global int32 globalInt = 2;
global double globalDouble = 0.0;
void main()
{
while (globalDouble == 0.0)
{
ControllerSampleWait(10);
}
print("global double value: " + globalDouble);
}
📜 Getting a Global Value
The example code below demonstrates how to obtain an integer value from a RapidScript program.
string globalIntName = "globalInt";
int expectedIntValue = 2;
{
int intValue = globalInt.Value;
Assert.That(intValue, Is.EqualTo(expectedIntValue));
}
The example code below demonstrates how to obtain a double value from a RapidScript program.
{
double doubleValue = globalDouble.Value;
Assert.That(doubleValue, Is.EqualTo(expectedDoubleValue));
}
📜 Setting a Global Value
The example code below demonstrates how to set a global double value in a RapidScript program.
string globalDoubleName = "globalDouble";
double expectedDoubleValue = globalInt.Value * 3.14159;