# Functions code
This page holds the functions custom script that allows you to execute.
# Side panel
The configured function are listed on the left, with their name. The icon and the label take on color
- blue, to identify the functions currently selected and displayed in the view;
- file_upload when function is editted but not saved.
- green, when function is turned on.
# Add a function
Adding a new function is done by clicking on the button labeled "ADD function", which opens a modal with the following elements
- Name, the descriptive label to be assigned to the function, which must comply with the Plexus nomenclature criteria
# Re-ordering the functions
It is done by clicking on the "Edit Order" button at the bottom of the function list; note that the button is shown only when there are at least 2 functions configured.
When clicked, a modal window is displayed that allows you to drag the rows and, if necessary, save the new order in order to see the list with the desired structure.
# Include Function
Include function is a function that allows you to create your static function(global function) if you wish to use multiple functions to make things tidier.
# Command the status of the function
Each function has a switch next to the name, which controls its status.
When a function is turned off (gray switch) its status is stopped shown on the top bar.
When a function is turned on (green switch) the following conditions may occur in the view top bar.
- State in Running function is currently running;
- State in Stopped, status indicating that the function has stopped.
# Function Top Bar
Every function have a function top bar that allows user to perform various actions on the functions.
|find_in_page||Search Variable||A action that allows user to search specific variables in all of your functions; non-case-sensitive|
|calendar_view_day||Fold / Unfold Code||An action that allows you to minimized the code|
|save||Save||An action that save the code after you edit. Function won't run in the newest code until you uploaded it even though you saved.|
|upload||Upload||An action that upload the code after you saved. Function won't run in the newest code until you uploaded it even though you saved.|
|remove_red_eye||Debug View||An action that allows user to read error message. Similiar like console log.|
|list||API List||A library of API List function to use.|
|info_outline||Info||Allow user to edit the function name and delete it.|
# Writing and Executing Functions
You can refer our API Shortcut List to quickly execute code that you want to.
There are Four steps to write and execute your functions
- Write your code
- Save the function
- Upload the function
- Turn on the function
# Rules of Functions
- Code are in PHP Syntax.
- Writing functions script must be comply with the Plexus nomenclature criteria.
- While loop will cause the code to crash due to Ladder Logic.
- Using variable that you created from Section page does not require '$'
- Functions are execute from top to bottom order , functions that are below will overwrite any functions that are on top if they write towards the same variable for example.
- Turning off functions does not revert back value that have being set!
Notice the variable FOO is overwritten by Function Two to become 1 instead of 100. Due to Function Two is below Function One order wise.
Do note, in order to read and write specific device channels, devices have to be turned ON.
# Functions Library API
if / Read
if / Read / Write
write_val_delay('var_name', $value, $msDelay)
write_val_period('var_name', $value1, $value2, $ms1, $ms2)
write_val_ramp('var_name', $rampValueStart, $rampValueEnd, $msRampDuration)
write_val_at_time('var_name', $value, '16:20')
write_val_at_time_range('var_name', $value, '16:20', '16:30')
set_alarm_delay('alarm_name', 'message', $msDelay)
List of each Functions API in detail are available here.