Show / Hide Table of Contents

Loading Module

This example provides information on loading a module into RobotStudio. An active station is needed for this example.

The module name filepath should be passed as a parameter. To check the result of the Add-In, ensure that the module is loaded in RobotStudio by browsing to RAPID tab -> Controller view -> Program Modules.

Note

In the robot controller, a module is a building block of RAPID code that can be either a system module or a program module. System modules handle robot installation tasks like equipment management and calibration. Program modules contain task-specific code for the robot's operations. A program is a collection of these modules, representing a complete set of tasks for the robot.

Solution

  1. Get the active task.

    // Get the active task from the station
    RsTask task = Station.ActiveStation.ActiveTask;
    
  2. Get virtual controller object based on RsIrc5Controller's object SystemID.

    // Get the RsIrc5Controller and connect to the controller
    RsIrc5Controller rsIrc5Controller = (RsIrc5Controller)task.Parent;
    Controller controller = Controller.Connect(new Guid(rsIrc5Controller.SystemId), ConnectionType.RobotStudio);
    
  3. Request mastership from controller to modify RAPID.

    // Request mastership to ensure exclusive access to the controller  
    using (Mastership.Request(controller))
    
  4. Load module if RAPID execution state is stopped.

    if (controller.Rapid.ExecutionStatus ==
               ABB.Robotics.Controllers.RapidDomain.ExecutionStatus.Stopped)
    {
        // Load the module if the Rapid execution state is stopped  
        ABB.Robotics.Controllers.RapidDomain.Task rapidTask = controller.Rapid.GetTask(task.Name);
        loaded = rapidTask.LoadModuleFromFile(filePath,
                          ABB.Robotics.Controllers.RapidDomain.RapidLoadMode.Replace);
        System.Threading.Thread.Sleep(1000);
    }
    
    Note

    Use LoadProgramFromFile to load a program instead of a module.

Example

This example provides information on loading a module into RobotStudio.

private static bool LoadModuleFromFile(string filePath)
{
    bool loaded = false;
    Project.UndoContext.BeginUndoStep("LoadModuleFromFile");

    // Check for existance of Module
    if (File.Exists(filePath))
    {
        try
        {
            // Get the active task from the station
            RsTask task = Station.ActiveStation.ActiveTask;

            // Get the RsIrc5Controller and connect to the controller
            RsIrc5Controller rsIrc5Controller = (RsIrc5Controller)task.Parent;
            Controller controller = Controller.Connect(new Guid(rsIrc5Controller.SystemId), ConnectionType.RobotStudio);
            
            if (controller != null)
            {
                // Request mastership to ensure exclusive access to the controller  
                using (Mastership.Request(controller))
                {
                    if (controller.Rapid.ExecutionStatus ==
                               ABB.Robotics.Controllers.RapidDomain.ExecutionStatus.Stopped)
                    {
                        // Load the module if the Rapid execution state is stopped  
                        ABB.Robotics.Controllers.RapidDomain.Task rapidTask = controller.Rapid.GetTask(task.Name);
                        loaded = rapidTask.LoadModuleFromFile(filePath,
                                          ABB.Robotics.Controllers.RapidDomain.RapidLoadMode.Replace);
                        System.Threading.Thread.Sleep(1000);
                    }
                }
            }
        }
        catch
        {
            Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
            throw;
        }
        finally
        {
            Project.UndoContext.EndUndoStep();
        }
    }
    return loaded;
}

Required Namespaces

System.IO

ABB.Robotics.RobotStudio

ABB.Robotics.RobotStudio.Stations

ABB.Robotics.Controllers

See Also

  • Saving Program
In this article
Back to top Copyright © 2025 ABB