# Functions code

This page holds the functions custom script that allows you to execute.

functions
Functions

# 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.
  • otherwise
    • 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

# 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.

# View

# Function Top Bar

Every function have a function top bar that allows user to perform various actions on the functions.

2IUKk2DFzWMZqPB5NK7FAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAaJo3ADH2NPkMaQUAAAAASUVORK5CYII=
Function Top bar
Icon Name Information
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

Important Rules

  • 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!
ladder_logic
Ladder Logic Example

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.

WARNING

Do note, in order to read and write specific device channels, devices have to be turned ON.

# Functions Library API

General APIs
  • if / Read
  • if / Read / Write
  • Comment Title
  • Comment Small
  • debug_message('Message')
  • info_message('Message', 'INFO')
Variable APIs
  • read_val('var_name')
  • read_future_val('var_name', $seconds_future)
  • read_average_val('var_name', $seconds_past)
  • write_val('var_name', $value)
  • write_val_delay('var_name', $value, $msDelay)
  • reset_val_delay('var_name')
  • write_val_period('var_name', $value1, $value2, $ms1, $ms2)
  • reset_val_period('var_name')
  • write_val_ramp('var_name', $rampValueStart, $rampValueEnd, $msRampDuration)
  • reset_val_ramp('var_name')
  • write_val_at_time('var_name', $value, '16:20')
  • write_val_at_time_range('var_name', $value, '16:20', '16:30')
  • disable('var_name')
  • enable('var_name')
Timers APIs
  • start_timer('timer_name')
  • reset_timer('timer_name')
  • pause_timer('timer_name',1)
  • timer_running('timer_name')
  • read_timer('timer_name')
  • set_timer_duration('timer_name', $duration)
Alarms APIs
  • set_alarm('alarm_name', 'message')
  • set_alarm_delay('alarm_name', 'message', $msDelay)
  • reset_alarm('alarm_name')
  • alarm_active('alarm_name')
  • any_alarm_active()
Stepper APIs
  • start_step('step_name')
  • read_step('step_name')
  • set_step('step_name', $value)

List of each Functions API in detail are available here.

Last Updated: 8/3/2021, 1:02:24 PM