Make your first Custom Component
This tutorial adds a Custom Component named Hello.
Download the Hello component pack
Unzip the pack, then attach the files in the steps that follow.
The pack includes a DBC file so this path can bind a CAN signal.
It also includes firmware files so the component can show an Output Limit field.
A Custom Component does not need a DBC file or firmware files.
At the end the component publishes a count tag, lists a Temperature message, shows those values on its page, has Connect / Disconnect in the menu, and shows an Output Limit firmware field.
The path takes about 20 minutes.
What you need
- Profinity 2.3 running, with an active profile.
- A Desktop, Server, or Enterprise licence, which includes Custom Plugins and Scripting. Refer to Licensing.
- The Modify components, View tags, View firmware, Modify firmware, and Allow firmware actions permissions. Refer to Roles and permissions.
- Scripting enabled on the Application Config tab of System Configuration.
Scripts run with application permissions
A script runs inside Profinity with the same operating system permissions as the application, so review any script before running it.
Add the component
To add the component:
- Select ADD COMPONENT in the side menu.
- Select Custom Component.
- Enter
Helloas the Name. - Select ADD COMPONENT.
The component appears in the side menu and opens its starter dashboard.
Add a DBC file
A DBC file names the CAN messages the component can decode. This example uses a DBC file. A Custom Component does not need one.
-
Create a file named
hello.dbcthat contains this DBC:VERSION "" NS_ : BS_: BU_: Sensor BO_ 256 Temperature: 8 Sensor SG_ Value : 0|16@1+ (0.1,0) [0|150] "C" Vector__XXXThe file describes one message named
Temperaturewith one signal namedValue. -
On the Hello dashboard, select the three bar icon at the top right to open the settings.
- Select the Pack files tab.
- Set Upload DBC File (Optional) to
hello.dbc. - Select SAVE.
The component menu includes Messages and Signals and Edit DBC File.
Add the main script
A main script is a long-running service that publishes tags for the component.
-
Create a file named
scripts/hello.pythat contains this Python:import time _run_count = 0 def on_start(): global _run_count _run_count = 0 return True def run(): global _run_count while not Profinity.ScriptCancelled: _run_count = _run_count + 1 Profinity.Tags.SetValue("count", _run_count) time.sleep(1) return TrueThe script publishes a tag named
countunder the component once a second. -
Open the settings from the three bar icon.
- Select the Scripts tab.
- Set Main Script (Optional) to
scripts/hello.py. - Turn on Auto Start Main Script.
- Select SAVE.
Profinity starts the main script because Auto Start Main Script is on.
Select TAG UTILITIES in the side menu to open the Tag Explorer, expand Hello, and find count.
The value increases once a second.
Add a dashboard
The dashboard is the component's page.
This file binds count from the main script and DBC/Temperature/Value from the DBC file.
-
Create a file named
hello.yamlthat contains this dashboard:version: "2.3" dashboard: items: - row: direction: vertical items: - group: class: statscontainer items: - pill: icon: image: IbmWatsonKnowledgeStudio items: - pillgroup: items: - value: label: COUNT precision: 0 bind: - target: value source: count - value: label: TEMPERATURE precision: 1 bind: - target: value source: DBC/Temperature/Value -
Open the settings from the three bar icon.
- Select the Pack files tab.
- Set Upload Dashboard (Optional) to
hello.yaml. - Select SAVE.
The Hello page shows COUNT updating once a second. TEMPERATURE stays empty until a CAN frame for that message arrives.
Add menu actions
actions.yaml adds items to the component menu.
This file adds Connect / Disconnect for the main script.
-
Create a file named
actions.yamlthat contains this YAML: -
Open the settings from the three bar icon.
- Select the Pack files tab.
- Set Actions YAML file (Optional) to
actions.yaml. - Select SAVE.
The Hello menu includes Connect / Disconnect.
Add firmware
A firmware map adds firmware fields on the component.
The load and save scripts are named in firmware.yaml.
Refer to Firmware actions.
This example uses a firmware map and firmware scripts.
A Custom Component does not need them.
-
Create a file named
firmware_map.yamlthat contains this YAML: -
Create a file named
scripts/load_firmware.pythat contains this Python: -
Create a file named
scripts/save_firmware.pythat contains this Python: -
Copy the
scriptsfolder into the Hello folder undercomponentsin the active profile. The profile sits in theprofilesfolder of the artefacts directory. -
Create a file named
firmware.yamlthat contains this YAML: -
Open the settings from the three bar icon.
- Select the Pack files tab.
- Set Firmware Map YAML file (Optional) to
firmware_map.yaml. - Set Firmware Actions YAML file (Optional) to
firmware.yaml. - Select SAVE.
The settings show a Limits tab with Output Limit at 100. On Firmware Utilities, select LOAD SETTINGS. Output Limit changes to 80.
Next steps
- Change the dashboard in the visual editor, as described in How to create a custom dashboard.
- Replay CAN traffic so TEMPERATURE shows a value, as described in How to replay CAN bus logs.
- Write
component_metadata.yamland pack the folder so another installation can add it by name. The file is described in Component metadata, and the commands are on Component Pack CLI. The downloaded pack already includessettings_map.yamlandcomponent_metadata.yaml.