Show / Hide Table of Contents

RsGenericDataDeclaration Properties Example

This example creates two DataDeclarations, one as a string and one as a num, and synchronizes them to the virtual controller.

Compiling the Code

Note

You need a running VC for this example to work.

Example

Project.UndoContext.BeginUndoStep("RsGenericDataDeclarationProperties");
try
{
    // ***This example requires a running VC***
    Station station = Station.ActiveStation;

    // Create a GenericDataDeclaration, representing a string value.
    RsGenericDataDeclaration myGenDDString = new RsGenericDataDeclaration("myString", "string");

    // Set the InitialExpression of the DataDeclaration.
    myGenDDString.InitialExpression = "\"some_value\"";

    // Set the module name the DataDeclaration should be syncronized to.
    myGenDDString.ModuleName = "myModule_1";

    // Define the DataDeclaration as variable.
    myGenDDString.StorageType = RapidStorageType.Variable;

    // Make sure the DataDeclaration is synchroinized when the task is.
    myGenDDString.Synchronize = true;

    // Add the DataDeclaration to the ActiveTask.
    station.ActiveTask.DataDeclarations.Add(myGenDDString);

    // Syncronize the DataDeclarations to the VC.
    System.Collections.Generic.List<SyncLogMessage> syncLog_1 = new System.Collections.Generic.List<SyncLogMessage>();
    await station.ActiveTask.SyncDataAsync(myGenDDString.ModuleName + "/" + myGenDDString.Name, SyncDirection.ToController, syncLog_1);

    // Create a genric DataDeclaration, representing a 3-dimensional matrix
    // where each dimension has 3 entries.
    int[] dimensions = new int[3] { 3, 3, 3 };
    RsGenericDataDeclaration myGenDDMatrix = new RsGenericDataDeclaration("myMatrix", "num", dimensions);

    // Set the InitialExpression of the DataDeclaration.
    myGenDDMatrix.InitialExpression = "[[[1,0,1],[0,0,1],[1,1,2]],[[1,2,1],[1,2,2],[1,1,3]],[[1,4,1],[1,1,2],[1,1,3]]]";

    // Set the module name the DataDeclaration should be syncronized to.
    myGenDDMatrix.ModuleName = "myModule_2";

    // Define the DataDeclaration as persistent.
    myGenDDMatrix.StorageType = RapidStorageType.TaskPersistent;

    // Make sure the DataDeclaration is synchroinized when the task is.
    myGenDDMatrix.Synchronize = true;

    // Add the DataDeclaration to the ActiveTask.
    station.ActiveTask.DataDeclarations.Add(myGenDDMatrix);

    // Syncronize the DataDeclarations to the VC.
    System.Collections.Generic.List<SyncLogMessage> syncLog_2 = new System.Collections.Generic.List<SyncLogMessage>();
    await station.ActiveTask.SyncDataAsync(myGenDDMatrix.ModuleName + "/" + myGenDDMatrix.Name, SyncDirection.ToController, syncLog_2);
}
catch
{
    Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
    throw;
}
finally
{
    Project.UndoContext.EndUndoStep();
}

See Also

  • RsGenericDataDeclaration
  • RapidStorageType
  • RobotStudio Community
In this article
Back to top Copyright © 2025 ABB