Knowledge Base
Welcome to OPAL-RT’s Knowledge Base
OPAL-RT offers a repository of support information for optimal use of its technology.
Please note that OPAL-RT knowledge base is not fully optimized for mobile platforms.
For optimal experience, use a desktop computer.
Reference Number: AA-01651// Views: AA-01651// Created: 2019-05-16 04:36:03// Last Updated: 2021-12-08 18:48:07 HowTo How To Export and Import IO Connections
As of RT-LAB version 11.3.4, there is a new Python API function that will allow you to export/import all the IO connections in your project using a CSV file. This How To guide will show you how to do this using the project IEC 61850 found in the example project directory. This example project has 104 connections. If you were to reuse the Simulink model in another project, it would be time consuming to make each individual connection. The purpose of this new function is to automate that process.
Let’s start by creating a new project. We will call it
exportConnections:
Once you click Next you can select from a list of template
projects. Select the model IO > _Generic_ > IEC_61850, and then click
finish. As you can see from the Configuration, this project has 104
connections between the IEC 61850 IO Interface and the model. Now to use the new Python API function, we need to create a
script. This can be done in RT-LAB or by using an external interpreter. In
RT-LAB, right-click on the project name and select New > File. Then name
your file with the extension .py
Now the script will be open in the project explorer. To use this function, or any API call, a few things need to be in the script: 1. Import the RtlabAPI module so that you can access the API functions 2. Call the functions OpenProject (which takes the
file path to the .llp project configuration file as input), and CloseProject to
let the API connect and disconnect from the project. When you open a project
with an API call, all the subsequent calls in that script will be performed on
that project. For an introduction on how to use the Python API, you can
watch a tutorial video here: https://www.opal-rt.com/opal_tutorial/video-tutorial-1-test-automation-using-the-python-api/ After you have the basic structure in your script to use the
RT-LAB API, you only need to use one function, ExportConnections(). This
function needs one input, the file name of the CSV file that you want to create to write
the IO connections to. Export Connections:import RtlabApi PROJECT = 'C:\\Users\USERNAME\\OPAL-RT\\RT-LABv202X.X2_Workspace\\PROJECT_NAME\\PROJECT_NAME.llp' def Main(): RtlabApi.OpenProject(PROJECT) RtlabApi.ExportConnections(filename='Connections.csv') RtlabApi.CloseProject() if __name__ == "__main__": Main() Import Connections:import RtlabApi PROJECT = 'C:\\Users\USERNAME\\OPAL-RT\\RT-LABv202X.X2_Workspace\\PROJECT_NAME\\PROJECT_NAME.llp' def Main(): RtlabApi.OpenProject(PROJECT) RtlabApi.ImportConnections(filename = None) RtlabApi.CloseProject() if __name__ == "__main__": Main() To run the script in RT-LAB, press Ctrl + F11. A new CSV file will appear in your project folder. As seen below, this file will be structured with columns that describe the connections in your project. The first column tells the connection type, this can be Model to IO, Model to Panel, or IO to Panel. The remaining columns describe details for Datapoints 1 and 2. You can edit this CSV file to add or remove connections or change the path if you change subsystems or the naming convention for example. Note: If you edit the file, be careful to ensure the accuracy of each entry, as a
one character mistake will cause an error when you try to import it. To demonstrate how to use this file, create a new project,
and this time select an empty template. With that new project open, right-click on models and select
Import > Existing RT-LAB Model. Then choose the iec_61850.mdl model in the previous project
you created. Make sure to only import the .mdl file so we have a clean start
and don’t import the other project settings. Now that you have the model in the same project, we need to
compile the model. During the compilation process, RT-LAB will create a list of
the signals and parameters in the model, which is needed to make the
connections to. Since this example uses the IEC 61850 IO connections, we
need to add that interface to the project. Select new I/O Interface here:
Then choose IEC 61850 from the list. Note that in this example project, both the GOOSE Publishers
and Subscribers have two messages, but the IO Interface only comes with one
default. This is important to show because if the connections in the
CSV file are not present in the project, both on the model, IO Connection, or
Panel side, you will get an error when you run the script naming one specific
connection that is missing, and this error will cause none of the connections
to be made. So we need to add a second message to both the Publisher and
Subscriber. To do this, select the + button to add a message, then choose the
icd61850.icd file. After it is loaded, select the GOOSE ID, and choose the
desired message: Once you do this for both the Publisher and Subscriber, all
the connections are now available in the project. Make sure to save the changes
to the IEC 61850 IO Interface. Now that your new project is set up, you can create a python
script for this project, or can use the old one and change the path to the
correct project: Using the ImportConnections() function, you can either
specify a file name, or set that variable to None. By setting the variable to
None, when you run the script, a window will open allowing you to select the
file from the previous project: After you select the file, all the connections will be made
to the script.
|