Documentation Home Page RT-LAB Home Page
Pour la documentation en FRANÇAIS, utilisez l'outil de traduction de votre navigateur Chrome, Edge ou Safari. Voir un exemple.

Examples

API Interactions Using Generic Functions

Before any API function is called, the Controller is not yet running and therefore does not contain any objects. Before an active project is chosen, you can call GetActiveProjects() to list the current projects, or use NewProject() to create a new project or OpenProject() to open a project that was previously saved to disk or to connect to an active project. For more details on the arguments required for generic API calls see OP_COMMAND. After a call to NewProject(), the Controller will contain the objects shown in Figure 6. The project will contain the attributes shown in Figure 6.

The project that has just been created will have a specific reference ID. This ID will be returned by the NewProject function call. It can then be used to issue Generic API commands directly to the project. For example, the GetAttributes function can be used to retrieve the values of the project’s attributes. The attributes that the project will contain are illustrated in Figure 7.

New project attributes

Once the project has been created, the next step would be to add a model to the project. This can be done with the project ID and the CMD_ADD command, specifying the path to the model file (.mdl, .sbd or .ecf) or the model settings file (.llm) via the attribute ATT_FILENAME. Figure 8 shows the resulting controller. Since ATT_AUTOSAVE is false by default for projects, it may be a good idea to save the project manually via the SaveProject command.


At this point, or at any point after creating a new project or opening an existing project, it is possible to close the connection with the Controller. This can be done with the CloseProject command.


When it is required to connect to an existing project, the OpenProject command should be used. If the project is not currently open a new Controller will be created. If the project is already active in another Controller, a new connection to that same Controller is established and control is shared between clients.

When navigating through the Controller object tree, the GetChildren function comes in very handy. Its purpose is to list all the objects or lists that are direct children of the specified object or list. For example, if GetChildren was called with the project ID, a set of objects/lists containing the Model List’s ID would be returned.

Controller after first AddModel command

Other Examples

There are various examples available for the different supported languages. These examples can be found under RT-LAB_ROOT\Examples\Api (where RTLAB_ROOT is the directory where you installed RT-LAB).

Each directory contains a readme.txt file which describes the sub-folders as well as provides a description of the example.

OPAL-RT TECHNOLOGIES, Inc. | 1751, rue Richardson, bureau 1060 | Montréal, Québec Canada H3K 1G6 | opal-rt.com | +1 514-935-2323