### Install pip if unknown Source: https://docs.plexim.com/tsp/rtbox-demos/toolsconnectivity/rlc-network-scripting If the pip module is not recognized, install or upgrade pip first. This command is for Windows. ```bash py -3 -m pip install -U pip ``` -------------------------------- ### Start RT Box Real-Time Simulation Source: https://docs.plexim.com/tsp/rtbox-demos/toolsconnectivity/automated-testing-robot-framework Starts the real-time simulation on the RT Box. The optional _waitForTrigger_ argument can delay the start until a trigger is received over SFP, useful for synchronization. ```robotframework rtBoxStart _'waitForTrigger'_ ``` -------------------------------- ### Install Robot Framework using pip (Python 3) Source: https://docs.plexim.com/tsp/rtbox-demos/toolsconnectivity/automated-testing-robot-framework Use this command to install the Robot Framework for Python 3 on Windows. ```bash py -3 -m pip install -U robotframework ``` -------------------------------- ### Start RT Box Simulation Source: https://docs.plexim.com/tsp/rtbox/latest/scripting Starts the execution of the real-time simulation on the RT Box. ```python server.rtbox.start() ``` -------------------------------- ### Install Robot Framework using pip (Python 3) Source: https://docs.plexim.com/tsp/rtbox-demos/toolsconnectivity/automated-testing-robot-framework Use this command to install the Robot Framework for Python 3 on macOS. ```bash python3 -m pip install -U robotframework ``` -------------------------------- ### Install matplotlib using pip Source: https://docs.plexim.com/tsp/rtbox-demos/toolsconnectivity/rlc-network-scripting Install or upgrade the matplotlib library using pip. This command is for Windows. ```bash py -3 -m pip install -U matplotlib ``` -------------------------------- ### Load, Start, Stop, and Reboot Simulation Source: https://docs.plexim.com/tsp/rtbox/latest/scripting Commands to manage the lifecycle of a real-time simulation on the RT Box. This includes loading an executable, starting its execution, stopping it, and rebooting the RT Box. ```APIDOC ## rtbox.load(binaryObject) ### Description Loads a new executable (ELF file) onto the RT Box. The `binaryObject` must be a base64 encoded RPC binary object or an XML-RPC Binary object. ### Method XML-RPC ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **binaryObject** (bytes or string) - Required - The ELF executable file content, encoded as a base64 string or an XML-RPC Binary object. ### Request Example ```python # For XML format with open("TestModel_codegen/TestModel.elf", "rb") as f: server.rtbox.load(xmlrpc.client.Binary(f.read())) # For JSON format import base64 with open("TestModel_codegen/TestModel.elf", "rb") as f: server.rtbox.load(base64.b64encode(f.read()).decode()) ``` ## rtbox.start() ### Description Starts the execution of the currently loaded real-time simulation. ### Method XML-RPC ### Parameters None ## rtbox.stop() ### Description Stops the execution of the real-time simulation. ### Method XML-RPC ### Parameters None ## rtbox.reboot(reboot_command) ### Description Stops the execution of the real-time simulation and reboots the RT Box. ### Method XML-RPC ### Parameters - **reboot_command** (string) - Required - Must be the string 'reboot'. ``` -------------------------------- ### Install matplotlib using pip on Mac Source: https://docs.plexim.com/tsp/rtbox-demos/toolsconnectivity/rlc-network-scripting Install or upgrade the matplotlib library using pip. This command is for macOS. ```bash python3 -m pip install -U matplotlib ``` -------------------------------- ### Setup RT Box Server Connection Source: https://docs.plexim.com/tsp/rtbox-demos/toolsconnectivity/automated-testing-robot-framework Establishes an XML/JSON-RPC communication channel to the RT Box, identified by its hostname. ```robotframework rtBoxSetupServer 'rtBoxName' ``` -------------------------------- ### UDP Client Data Reception Example Source: https://docs.plexim.com/tsp/rtbox-demos/toolsconnectivity/data-logging This output shows data received by the UDP client script. Each line represents a data point streamed from the RT Box. ```text UDP received data: (4.7505016142600914e-14,) UDP received data: (0.5877852439880371,) UDP received data: (0.9510565400123596,) UDP received data: (0.9510565400123596,) UDP received data: (0.5877852439880371,) UDP received data: (-4.7505016142600914e-14,) UDP received data: (-0.5877852439880371,) UDP received data: (-0.9510565400123596,) UDP received data: (-0.9510565400123596,) UDP received data: (-0.5877852439880371,) UDP received data: (4.7505016142600914e-14,) UDP received data: (0.5877852439880371,) ... ``` -------------------------------- ### Upload Executable and Initialize Server Source: https://docs.plexim.com/tsp/rtbox-demos/toolsconnectivity/rlc-network-scripting Uploads the generated .elf file to the RT Box and initializes the XML-RPC or JSON-RPC server connection based on the selected method. ```Python if METHOD == "JSON": import jsonrpc_requests import collections.abc # to make jsonrpc_requests usable for Python 3.10+ collections.Mapping = collections.abc.Mapping server = jsonrpc_requests.Server(HOST_ADDRESS) elif METHOD == "XML": import xmlrpc.client server = xmlrpc.client.Server(HOST_ADDRESS) with open("rlc_network_scripting_codegen/" + MODEL_NAME + ".elf", "rb") as f: print("Uploading executable") server.rtbox.load(base64.b64encode(f.read()).decode()) ``` -------------------------------- ### Initialize RT Box Connection Parameters Source: https://docs.plexim.com/tsp/rtbox-demos/toolsconnectivity/rlc-network-scripting Sets up the hostname, IP address, and communication method for connecting to the RT Box. Ensure the HOST_NAME is updated to your RT Box's actual hostname. ```Python import socket import time import base64 HOST_NAME = "rtbox-123.local" ip = socket.gethostbyname(HOST_NAME) HOST_ADDRESS = "http://" + ip + ":9998/RPC2" MODEL_NAME = "rlc_network_scripting" METHOD = "XML" # choose "XML" or "JSON" ``` -------------------------------- ### Running Robot Framework Test Source: https://docs.plexim.com/tsp/rtbox-demos/toolsconnectivity/automated-testing-robot-framework Execute the automated test by running the `boost_converter.robot` file using the `robot` command in the console. Ensure the terminal is in the current working directory. ```bash robot boost_converter.robot ``` -------------------------------- ### Get RT Box Hostname Source: https://docs.plexim.com/tsp/rtbox-demos/toolsconnectivity/automated-testing-robot-framework Returns the hostname of the RT Box as a string. ```robotframework rtBoxGetHostname ``` -------------------------------- ### Matlab Script: Initialize and Upload Executable Source: https://docs.plexim.com/tsp/rtbox-demos/toolsconnectivity/rlc-network-scripting Initializes the JSON-RPC server and uploads the compiled .elf executable to the RT Box. Requires the matlab-jsonrpc client. ```matlab %Initialize server and load executable server = jsonrpc(HOST_ADDRESS); f = fopen('rlc_network_scripting_codegen/' + MODEL_NAME + '.elf', 'rb'); fprintf("Uploading executable\n"); server.rtbox.load(matlab.net.base64encode(fread(f, '*uint8'))); fclose(f); ``` -------------------------------- ### Executing a Robot Framework Test File Source: https://docs.plexim.com/tsp/rtbox-demos/toolsconnectivity/automated-testing-robot-framework This command shows how to run a single Robot Framework test file from the console. ```bash robot filename.robot ``` -------------------------------- ### Get RT Box Application Log Source: https://docs.plexim.com/tsp/rtbox/latest/scripting Retrieves log messages from the running simulation on the RT Box. ```python rtbox.getApplicationLog() ``` -------------------------------- ### Get Programmable Value Blocks Source: https://docs.plexim.com/tsp/rtbox/latest/scripting Returns a list of all Programmable Value blocks in the current model, including their paths. ```python rtbox.getProgrammableValueBlocks() ``` -------------------------------- ### Get Data Capture Blocks Source: https://docs.plexim.com/tsp/rtbox/latest/scripting Returns a list of all Data Capture blocks in the current model, including their paths. ```python rtbox.getDataCaptureBlocks() ``` -------------------------------- ### Load Model with Robot Framework Source: https://docs.plexim.com/tsp/rtbox-demos/toolsconnectivity/automated-testing-robot-framework Use this keyword to open a model defined by its relative path in the current working directory. ```robotframework plecsLoadModel 'path' ``` -------------------------------- ### Robot Framework Variables Configuration Source: https://docs.plexim.com/tsp/rtbox-demos/toolsconnectivity/automated-testing-robot-framework Configure essential variables in the `boost_converter.robot` file to match your specific RT Box setup, including host name, type, host PC IP address, and RPC method. ```robotframework *** Variables *** ${RTBOX}= RTBox.local ${RTBOX_TYPE}= PLECS RT Box 1 ${HOST_PC_IP_ADDRESS}= 255.255.255.255 ${RPC_METHOD}= XML ```