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-02290// Views: AA-02290// Created: 2024-03-20 13:56:32// Last Updated: 2024-03-20 15:10:54 HowTo How to Automate IO Connections using Python Script This process can be used to automate the connection from
OpInputs and OpOutputs defined on the Simulink model with the corresponding IO
connection. This can be used with Opal-Boards or with communication protocols. Here it is the step-by-step of the
process:
1 – In your the model, configure the
OpInput and OpOutput blocks mask like this: In this way, the RT-LAB alias will
be the same as the name block.
2 – Save and Build the model
3 – Configure the I/O interface according
to your usage, for IOs and/or Communication Protocols
3.1 - Set the general configurations
3.2 - Enable the channels or add the number of registers
that will be used.
4 – Create a python script file on the project folder where you can find the
.llp file.
4.1 – To create a pyhton script you can simply create a text file and change the extension to .py. This should automatically convert it to a Python file:
5 – Open the python script directly
in RT-LAB. You will be able to find it inside of your project folder: 6 – Edit your python script:
6.1 – Start by importing the RtlabApi library: 6.2 – Add the command to open your
project. Change the Project path to the llp file of the corresponding project:
6.3 – Create the lists of points to connect, it
should have a list for the datapoints from the Simulink model (OpInputs/Opoutputs)
and another list for the datapoints from the IO driver. To fill the lists, it can be done
manually or you can create loops which will make the process easier. In this case, using the “same name +
number” format would be helpful for doing multiple connections at the same
time, where the number can come from the created loop. Example:
For the model_datapoint path you can find the information on the
corresponding OpInput/OpOutput block, right-click, Properties:
For the drive_datapoint variable,
the corresponding information should be the path of the channel that will be from
the driver For the drivers datapoint, you have
to get it from the driver structure:
Example for the communication
protocol: Path: DNP3
Slave/Slaves/Slave_1/Binary inputs/Binary input 1 Example on Opal-Board: Path: OPAL-RT Board/Slot1A - Digital
bi-directional/Channels0 - 7 (input)(Static)
7 – After the list creation, enter
the command to create the connections. You can use a try/except structure to
check if an error happens:
8 – Save the python script (Ctrl+S)
9 – Run the Python Script 10 – Check in the Configurations if
the connections were created properly.
|