- Reference
Script reference
The scripting feature in the ezeio allows the user to implement advanced custom logic and control functionality on the ezeio. For most common applications, scripting...
ezeio script programming - the PAWN language#
The scripting feature in the ezeio allows the user to implement advanced custom logic and control functionality on the ezeio. For most common applications, scripting is not necessary.
The ezeio uses a powerful script language called PAWN. The syntax is very similar to JavaScript, and should be easily understood by anyone working with programming in similar languages.
The scripting feature of the ezeio is intended for those with previous experience in programming. This manual does not attempt to teach you to write programs. If you have a specific feature that you need help with, please contact eze System.
We strongly recommend reading the following documents to get introduced to the PAWN language:
ezeio script administration#
When working with ezeio scripts, you will edit your code on the userscript screen. When clicking “Commit”, the script is compiled on the servers, and automatically downloaded into the ezeio, where it will start to run as soon as the download completes.
Only one user defined script can run at the same time, but the editor allows you to have multiple scripts saved on the servers, and easily switch between them. The currently running script is marked with a checkmark.
If a script fails to compile due to a syntax error, the script will not be sent to the ezeio. If a previous version of the script, or a different script, was running, this will continue to run.
Script resources#
The user script can occupy up to 128kB code (compiled bytecode), and up to 16kB RAM.
The estimated requirements for a script is displayed when compiling.
Programming pattern#
Although the user script runs in a sandboxed runtime engine, the recommended programming pattern is similar to cooperative multitasking.
This means that you should avoid long-running loops, and instead make use of system callbacks provided in the function library.
The following system callback functions are defined:
@Tick | Called at a regular interval, set by SetTickInterval() |
@Timer | Called when one of the millisecond timers expire, see SetTimer() |
@Action | Called when an action is triggered due to an alarm event |
@Key | Called when a button is pressed on a connected terminal device |
@Scan | Called when a code is received from a scanner device |
Some examples#
The program below will print out “Hello” on the debug console.
main()
{
PDebug("Hello");
}The following example adds the values of field 1 and field 2 together, and writes the result to field 3.
// This example adds the value of field 1 and 2 and writes the sum to field 3
// The value of field 3 is updated every 500ms (twice per second)
main()
{
SetTickInterval(500); // Make sure the @Tick function is called twice per second
}
@Tick(uptime)
{
new f1, f2; // declare local variables
f1 = GetField(1); // set f1 to the value of field 1
f2 = GetField(2); // set f2 to the value of field 2
SetField(3, f1+f2); // set the value of field 3 with the sum of f1 and f2
}The example below illustrates the use of a global variable, the use of the main() function to initialize the values, and the @Tick(uptime) call. The program will use field number 1, and count from 100 down to 50, and then starting over.
// A simple demo program, counting down from 100 to 50, and then starts over
new myCounter; // Declare a 'global' variable
main() // The main() function will run on startup, once
{
SetTickInterval(1000); // Make sure the @Tick function is called once every 1000ms (1s)
myCounter = 100; // Initialize the counter with value 100
}
@Tick(uptime) // The @Tick function will be called once per second
{
myCounter = myCounter - 1; // Count down the counter with 1
if(myCounter <= 50) { // If we reached 50 (or lower)
myCounter = 100 // ..then set it back to 100
}
SetField(1, myCounter); // Update field 1 with the counter value
}The example below will run a 3-speed fan based on the input from a temperature sensor on field 1. Output 1 is used for low speed, output 2 is medium speed, and output 3 is high speed. The speed is selected based on how much the temperature exceeds a given setpoint (here set to 20.5 degrees C)
new @Speed;
main()
{
SetTickInterval(5000); // Update every 5s (5000ms)
}
@Tick(uptime)
{
new Float:temp, Float:diff; // Declare "float" variables to handle fractions
new sp = 0; // Use sp to find the resulting speed
temp = GetFieldFloat(1); // Fetch the current temperature from Field 1
diff = temp - 20.5; // 20.5 is our setpoint. diff is the differece
if(diff > 0.0) { // Over setpoint?
SetOutput(1, 100); // ..yes, so enable low speed
sp++; // count up our speed result
}
else
SetOutput(1, 0); // ..no, so shut off
if(diff > 2.0) { // 2 degrees or more over setpoint?
SetOutput(2, 100); //..yes, so enable mid-speed
sp++; // count up our speed result
}
else
SetOutput(2, 0);
if(diff > 6.0) { // 6 degrees or more over setpoint?
SetOutput(3, 100); //..yes, so run full speed
sp++; // count up our speed result
}
else
SetOutput(3, 0);
@Speed = sp; // Make the speed available to expressions as "@Speed".
}State machines#
A common programming pattern in control applications is to use state machines. PAWN and the ezeio implements strong support for state machines. The following is a typical pattern showing the startup sequence of an engine. Note that there are three @Tick handlers; one for each state. Also note the “entry” and “exit” functions. For more detail, refer to the PAWN language guide.
new count = 0;
main()
{
SetTickInterval(100); // set tick interval to 100ms (0.1s)
state WAITING; // start in the waiting mode
}
@Tick(uptime) <WAITING>
{
if( GetField(1) < 100 ) // condition to start up the process
state IGNITION;
}
// ***** the IGNITION state
entry() <IGNITION>
{
SetOutput(1, 100); // Turn on the ignition switch
count = 0;
}
@Tick(uptime) <IGNITION>
{
if( GetField(2) > 100 ) // Did the engine start?
state RUNNING; // yes - we're running
if(count++ > 50)
state WAITING; // didn't start in 5s? Give up and go back to waiting.
}
exit() <IGNITION>
{
SetOutput(1, 0); // Turn the ignition switch off
}
// ***** the RUNNING state
@Tick(uptime) <RUNNING>
{
if( GetField(2) < 100 ) // Check if the engine stopped
state WAITING; // ..go back to waiting
}
In this section
- ABSMacro that will return the absolute value
- AdjustFieldAdjust the value of a field.
- AllocRegistersReserve registers for a device driver
- BufDecDecode a part of a buffer into a scalar
- C2FHelper function to convert from Celsius degrees to Farenheit
- CLAMPMacro that will return a value limited to a given range
- CSVtoIntExtract a single parameter from a CSV formatted string.
- CSVtoStrExtract a single parameter from a CSV formatted string.
- DewpointHelper function to calculate dewpoint from temperature and relative humidity
- DoAlarmTrigger activation of an alarm.
- DoRestoreTrigger restore of an alarm.
- EvalEvaluates the supplied string using the expression parser
- F2CHelper function to convert from Farenheit degrees to Celsius degrees
- facosFind the arc-cosine of a value
- fasinFind the arc-sine of a value
- fatanFind the arc-tangent of a value
- fatan2Find the 2-argument arc-tangent
- fcosFind the cosine of a value
- flogFind the logarithm of a value
- ForceAlarmForce activation of an alarm.
- ForceRestoreForce restore of an alarm.
- fpowReturn a value raised to an exponent
- froundReturn a float value rounded off to an integer
- fsinFind the sine of a value
- fsqrtFind the square root of the given value
- fstrvalEvaluate a string to a float value
- ftanFind the tangent of a value
- GetAlarmInfoReturn the current information about the alarm
- GetAlarmStateReturn the current state of the alarm
- GetBitHelper function to read the state of a single bit in a byte-buffer.
- GetCellBitHelper function to read the state of a single bit in a cell.
- GetDeviceStatusFetch the Comm / Op / App status of a given device (or aggregate status)
- GetField/GetFieldFloatGet the value of a field
- GetFieldLogGet the value of a field from the log data
- GetInputModeGet the input mode on a native ezeio input.
- GetInputValueFetch the value of a hardware input.
- GetOutputGet the state of an output
- GetRegisterGet the value of a register
- GetRegisterStatusGet status of a register
- GetSystemItemFetch the value of a given system parameter
- GetTimerGet the current state of a timer
- GetValGet value of a user-defined memory cell
- ispackedTests a string for how it is stored.
- K2CHelper function to convert from Kelvin degrees to Celsius degrees
- K2FHelper function to convert from Kelvin degrees to Farenheit degrees
- LinfitLinear regression. Attempt to find best fit y=ax+b function given multiple x/y points.
- localtimeSplit Unixtime into components
- MAXMacro that will return the larger of two values
- MBRTU_ReadRead a single register from a Modbus/RTU device
- MBTCP_ReadRead a single register from a Modbus/TCP server
- memcpyCopy the source string to dest , starting at the index byte in dest, and counting length bytes.
- MINMacro that will return the smaller of two values
- mktimeConvert time and date into Unixtime value
- ModbusPortConfigConfigure the RS485 port Modbus/RTU settings
- PDebugPrint to the debug terminal
- PID-functionsSet of helper functions to initiate and update a PID control loop
- PingSends an ICMP (Ping) to another Ethernet connected device
- RegDirtyFind if a register value has been written to by any external process
- requestHibernateRequest from the ezeio to enter a hibernation cycle
- SetBitHelper function to set the state of a single bit in a byte-buffer.
- SetCellBitHelper function to set the state of a single bit in a cell value.
- SetDeviceStatusSet the device status
- SetDriverNoSystem function to capture the driver number from the script
- SetField/SetFieldFloatSet the value of a field
- SetInputModeSet the input mode on a native ezeio input.
- SetModbusTimeoutSet the bus timeout for Modbus/RTU communication
- SetOutputDirectly set the value/state of a native ezeio output. The output value is always in percent , 0-100. For digital outputs, any value 50 and higher will set the output...
- SetRegisterSet the value of a register
- SetSystemItemChange value of a given system parameter
- SetTickIntervalSet the rate of the calls to @Tick.
- SetTimerSet a timer or interval
- SetValSet value of a user-defined memory cell
- sleepPause script for a short duration
- strcatCopy the string source to the end of dest .
- strcmpCompare string1 and string2
- strcopyCopy the source string to dest .
- strdelRemove bytes from a string
- strfindSearches a string for a substring
- strformatFormats a string with placehoders
- strinsInsert a substring in a string
- strlenFind the lengths of a string
- strmidCopy a subsection of a string
- strpackCreate a packed copy of a string
- strunpackCreate an unpacked copy of a string
- strvalFind the numeric value of a string.
- SunPositionHelper function to calculate the sun's position at a given time and position on the earth.
- UpdateDeviceStatusUpdate the status of a given device
- uudecodeDecode an UU-encoded string
- uuencodeDecode an UU-encoded string
- valstrConvert an integer to a string
Last updated Jan 23, 2026