Control Panel Scripting
A Control Panel Group can run a Lua script that adds custom control logic, such as sending commands to a third-party device when a button is pressed. This applies both to a standalone Control Panel Group and to the Control Panel Group of a Managed Device.
This page describes what you set up in Cognio DesignOps to make a Control Panel Group scriptable, and the controls you use to run and monitor the script. For the Lua API that scripts use, see 3rd Party Lua Control Drivers.
Enable Scripting
Scripting is set up in the Scripting section of the Control Panel Group's properties. Select the Control Panel Group (or Managed Device) in Site View and open the Properties tab of the Modifier Panel. See CPG Properties for a description of each field.
- Turn on Enable Scripting.
- Set Script Location to your
.luafile. Use the browse button to choose the file, or the edit button to open it in an editor. - Load the script:
- Click Import Lua Script to load the script from the Script Location and restart it. Click it again whenever you edit the file.
- Or turn on Auto-Import Lua Script to have the script imported automatically.
Where the script runs depends on whether the Control Panel Group is synced:
- While the Control Panel Group is not synced, the script runs in Cognio DesignOps on your computer, so you can develop and test it without hardware.
- Once the Control Panel Group is synced, the script runs on the Smart Device that hosts it.
Connect the Script to the Signal Flow
Use Input Control Pins and Output Control Pins to set how many control signals the script exchanges with the signal flow. Each input pin appears as a destination for a Control Output module, and each output pin appears as a source for a Control Input module. A name field is shown for each pin so you can label it.
In the script, the pins are read and written through the Controls API.
Name the Controls the Script Uses
A script reaches the controls on its Control Panel Group by name, using the NamedControl API. For each control the script reads or writes:
- Select the control on the Control Panel and open its Function tab.
- Set Mode to a mode other than Parameter. Lua scripting is not available for controls in Parameter mode; use None for a control that only the script uses.
- Enter a Script/Remote Name. If you turn on Remote Enable for a control with no name, a default name such as
button1is filled in for you.
Give every control a unique name. If two controls share a name, the script uses the first one placed. Copying and pasting a control copies its name too, so rename the copy.
Choose a Button Function Type
A Button's Function Type, set in its Design tab, determines what the script sees when the button is pressed:
| Function Type | What the script sees | How the button looks |
|---|---|---|
| Latched | One change per press, toggling between off and on. | Stays on or off until pressed again. |
| Momentary | Two changes per press: on when pressed, off when released. | On only while held down. |
| Trigger | The same two changes as Momentary. | Never stays on; flashes briefly to confirm the press. |
Use a Trigger button for one-shot actions, such as turning a device on or sending a single command. Because it never shows an "on" state, the button does not suggest that something has been left on.
Monitor and Debug the Script
The Script Status and Script Statistics sections of the properties show whether the script is running, report any error, and show how much processing it uses. Use Restart, Pause, and Resume to control the script. See Script Status.
Script Status and Script Statistics are also available in Operation mode for an unlocked Control Panel Group, so you can keep watching and restarting the script while you operate the system.
To see output from the script's print statements, set a Lua Script Debug Output File. While the Control Panel Group is synced and the script runs on the Smart Device, turn on Enable Synced Debugging to have the device's debug output copied back to this file on your computer.
Share a Scripted Managed Device
When you export a Managed Device, its script goes with it. To share a Managed Device without letting others see or change its script, use Export Locked. On a locked Managed Device, the Scripting, Script Status, and Script Statistics sections are hidden. See Locked Managed Devices.