MC252 program language
An MC252 edge program is a taskfile: a text file the controller compiles and runs again and again. MC252 firmware 48 to 50 compile language version 12; this page describes firmware 50. HMI checks the source as you type, following the same rules; the device’s own compile result stays authoritative. How HMI stores and deploys programs is in MC252 edge programs.
In the program editor, hovering a word shows how it is written, a one-line description, and a Docs link to its section here.
Headings show how each item is written. Operand names in them say what goes there: variable is a
variable name; value a variable or an integer; condition a condition name; label, string
and parameter the name of one; target the variable or condition that receives a result.
Program layout
Section titled “Program layout”A program is a sequence of lines. Each line is empty, an option, a definition or an action.
;or#starts a comment that runs to the end of the line, except inside a string.- A line can start with a label, a name followed by
:.GO,CALLandTRYCALLjump to labels. A label can stand on its own line, before the action it marks. - Words are separated by spaces or tabs.
- Everything is case-insensitive except string text:
CALL,CallandcAlLare the same word, andpumpandPUMPthe same name. - A line holds at most 198 bytes before its comment; a longer one fails to compile. Comments do not count.
- An
@anywhere in a line, outside its comment, makes it an option line, so strings cannot contain@. - Integers are 64-bit signed, written in decimal (
-150) or hexadecimal (0x1F).
A name (of a definition or label) has 1 to 39 bytes of printable ASCII, does not start with a digit
or a sign followed by a digit, and contains none of :@=+-/*%><[]. It is not a reserved word: an
option, statement, command, function, type, memory source, table letter, error name, VAR, VARS,
COND, CONDS, TRUE, FALSE, LASTERROR or EMPTYSTRING. RUN and ONERROR name only
labels. A name can be defined once.
An item is defined before it is used, with these exceptions: labels and strings can be used before their definition, and variables and conditions are defined where an action first uses them (see Variables). Each kind of item (devices, parameters, strings, variables, conditions, labels) and the actions of a file are limited to 49151 each; an array counts as its size, so no array has more than 49151 items.
@PROTOCOLVERSION 12@UPDATE 10 ; run every 10 seconds
DEF sensor MBWRSINGLE 3 16 ; Modbus unit 3DEF temperature INT16 sensor H 100 ; tenths of a degreeDEF relay BIT sensor C 0DEF setpoint INT16 MEMBAT H 5000 ; kept on battery, also the controller's register 5000DEF failure "Sensor failed: *ERR(lasterror)*"
run:PUT t READ temperaturePUT limit READ setpointIF ISNOTKNOWN limitPUT limit 250 ; default while the setpoint was never writtenPUT hot GR t limitIF hotWRITE relay 1IF NOT hotWRITE relay 0EXIT OK
onerror:SYSLOG failureEXIT LASTERROROptions
Section titled “Options”An option line is @, the option and an integer value. A value that is not an integer or is out of
range fails to compile. An option sets compilation for the whole file or how its task runs.
@PROTOCOLVERSION version
Section titled “@PROTOCOLVERSION version”The language version the file is written for. Only 12 is accepted; any other value, including
11 of older examples, fails to compile. Put it first.
@UPDATE seconds
Section titled “@UPDATE seconds”The interval between two runs of the task, 1 to 2000000 seconds; default 60. The actual
interval depends on the controller’s load: parameter reads and writes and SMS make a run longer. A
run that comes due while the previous one still runs starts as soon as that one ends; when more
than one run is late, the extra runs are skipped, which can break counters that count runs.
@UPDATEDIVISOR divisor
Section titled “@UPDATEDIVISOR divisor”Divides the interval for sub-second runs: with a non-zero divisor, the interval is
UPDATE / UPDATEDIVISOR seconds. 0 (the default) keeps whole seconds. With a non-zero divisor,
the integer quotients UPDATE / UPDATEDIVISOR must not exceed 60 and UPDATEDIVISOR / UPDATE
must not exceed 500. Each option is checked against the value the other has at that line
(@UPDATE is 60 until set), so put @UPDATE first: @UPDATE 2 then @UPDATEDIVISOR 3 runs
about every 667 ms.
@PARAMLOADRATIO percent
Section titled “@PARAMLOADRATIO percent”The share of time, 1 to 100 percent, that reads and writes of device parameters may take; the
default is 25. After each device operation the task waits so that the operation took this share:
100 adds no wait, 50 waits as long as the operation took, 25 three times as long. The wait
leaves the bus to other clients. Memory parameters are not affected.
@PARAMTIMEOUT milliseconds
Section titled “@PARAMTIMEOUT milliseconds”How long a read or write of a device parameter waits for the answer, 0 to 5000 ms; default
5000. An operation that times out raises EXC_PARAM_TARGET_FAILED. Memory parameters are not
affected.
@VARBITS bits
Section titled “@VARBITS bits”The size of variables. Only 64 is accepted: variables are 64-bit signed integers.
@INDEXBITS bits
Section titled “@INDEXBITS bits”The size of item indexes. Only 16 is accepted.
@RESETDATA reset
Section titled “@RESETDATA reset”Whether variables and conditions are reset before each run: 0 (default) keeps their values in RAM
from run to run until the controller restarts or loses power; 1 makes every run start with
unknown values.
@SYNTAX syntax
Section titled “@SYNTAX syntax”Which keywords may be left out: 0 none, so commands take the prefix RE (RE RETURN) and copies
VAL; 1 (default) the command prefix and VAL; 2 also DEF and PUT. IF is always
written. Write commands without DO, which does not compile.
Definitions
Section titled “Definitions”DEF name
Section titled “DEF name”Defines name as the kind of item that follows: a string, a variable or
condition, a Modbus device or a parameter. Items a
definition refers to are defined earlier in the file. With @SYNTAX 2, DEF may be left out.
DEF name VAR, DEF name VARS count
Section titled “DEF name VAR, DEF name VARS count”A variable holds a 64-bit signed integer or is unknown (see Unknown values).
VARS defines an array of count variables, from 1 up to the
limit of a file; an array of one is a plain variable.
DEF is optional for single variables: PUT, a function operand or a string reference defines a
variable where it first appears. Define a variable first when its first use cannot tell its kind: a
plain copy (PUT a b where neither is known yet) or ISKNOWN fails to compile
otherwise. Arrays are always defined first.
LASTERROR is a predefined variable; see LASTERROR.
DEF name COND, DEF name CONDS count
Section titled “DEF name COND, DEF name CONDS count”A condition holds TRUE, FALSE, or is unknown. CONDS defines an array of count conditions,
with the same limit. As with variables, a single condition is defined where it first appears,
except where the first use cannot tell its kind.
TRUE and FALSE
Section titled “TRUE and FALSE”The two condition values. They can be copied into a condition (PUT ready TRUE) or checked
(IF TRUE); functions that take conditions, such as AND and NOT, take condition names, not
these literals.
Arrays
Section titled “Arrays”An array item is name[index], counted from 0.
- An integer index (
levels[2]) works wherever a single item does. It is checked at compile time. - A variable index (
levels[i]) compiles in fewer places: on one side of a plain copy (PUT levels[i] torPUT t levels[i], not both), as the target ofREAD,SQRT,BITSNOTandERR, and on one side ofNOT. Elsewhere it fails to compile. The index is a single variable. At run time an index outside the array raisesEXC_OUT_OF_BOUNDS; an unknown index,EXC_UNKNOWN. - On firmware 49, copying from an item by a variable index above
0(PUT t levels[i]withiof1or more) stops the run, although it compiles. Read items with an integer index, or keep one variable per item. MAX,MIN,SUM,MAXIDX,MINIDXandSELECTBYtake whole arrays.
DEF name "text"
Section titled “DEF name "text"”A string: text in double quotes, kept as written (case-sensitive). ** stands for one *; other
* pairs enclose string references filled in at run time. The text can hold
; and #, but not @. SYSLOG, SENDSMS, PARAMLOG, SMSRCVD and NOSMSRCVD take strings
and may name one defined later in the file.
A string produces at most 127 bytes of output, after references are filled in; UTF-8 letters outside ASCII take two or more bytes. The compiler accepts longer strings, but their output does not fit the device’s buffer.
EMPTYSTRING is a predefined string of zero length, for example the sender of
SMSRCVD that matches any number.
*VAR(variable)*, *ERR(variable)*, *PHONE(index)*
Section titled “*VAR(variable)*, *ERR(variable)*, *PHONE(index)*”References in a string, replaced when the string is used:
*VAR(variable)*: the variable’s value in decimal.*variable*is short for it.*ERR(variable)*: the name of the error code the variable holds, such asEXC_IO.*PHONE(index)*: the GSM phone number atindex,0to3, in the device settings.
LASTERROR works in VAR and ERR.
DEF report "Level *VAR(level)* of *VAR(limit)*, last error *ERR(lasterror)*"DEF formula "5 ** 2 = *VAR(product)*" ; prints 5 * 2 = …DEF operator "*PHONE(0)*"Modbus devices
Section titled “Modbus devices”A device definition names a Modbus unit that parameters read and write. unit is a fixed unit ID
1 to 255, * for the controller’s own unit ID, or a variable plus an offset 1 to 255
(base+1), read at run time. read and write limit the registers or coils per Modbus request,
1 to 125 each.
DEF name MBWRDENIED unit read
Section titled “DEF name MBWRDENIED unit read”A device that is only read. WRITE to its parameters fails to compile.
DEF name MBWRSINGLE unit read
Section titled “DEF name MBWRSINGLE unit read”A device written with the single-coil and single-register write functions.
DEF name MBWRMULTI unit read write
Section titled “DEF name MBWRMULTI unit read write”A device written with the multiple-coil and multiple-register write functions, at most write per
request.
DEF name MBWRANY unit read write
Section titled “DEF name MBWRANY unit read write”A device written with either the single or the multiple write functions.
DEF name MBSELF
Section titled “DEF name MBSELF”The controller’s own virtual Modbus device: the same as MBWRANY * 100 100. Use it to read and
write the MC252’s own registers, and to log its registers.
DEF name UINT16 source table address
Section titled “DEF name UINT16 source table address”A parameter: a value of a given type at a source, which READ reads into a
variable and WRITE writes. The source is a Modbus device defined earlier or a
memory source. A device parameter takes a table and an address; for a memory
parameter they are optional and map it to the controller’s own registers (see
Tables and addresses).
DEF flow F32EP2R meter H 20 ; float register pair, as hundredthsDEF counter UINT32 MEMBAT ; battery-backed, not visible over ModbusDEF mode UINT16 MEMTEMP H 5000 ; RAM, readable as the controller's register 5000Values are converted between the type and the 64-bit variable on each read and write. A value that
does not convert raises EXC_TYPE_UNKNOWN. A memory parameter that was never written reads as
unknown; a device parameter reads the device’s register.
Parameter types
Section titled “Parameter types”Byte orders: big-endian (BE, or no suffix) puts the most significant byte first; BLE reverses
all bytes; WLE puts the least significant 16-bit word first and keeps each word big-endian. For
example, 66051 (0x00010203) as INT32 is 00 01 02 03, as INT32BLE 03 02 01 00, as
INT32WLE 02 03 00 01.
DEF name BIT source table address
Section titled “DEF name BIT source table address”One bit, 0 or 1: a coil (C) or a discrete input (D). BIT takes only these tables, and the
other types only H and I. One byte in a memory source.
Integer types
Section titled “Integer types”Written like DEF name INT16 source table address.
| Type | Bytes | Registers | Range | Byte order |
|---|---|---|---|---|
UINT8 | 1 | 1 | 0 to 255 | — |
INT8 | 1 | 1 | −128 to 127 | — |
UINT16 | 2 | 1 | 0 to 65535 | BE |
UINT16BLE | 2 | 1 | 0 to 65535 | BLE |
INT16 | 2 | 1 | −32768 to 32767 | BE |
INT16BLE | 2 | 1 | −32768 to 32767 | BLE |
UINT32, UINT32BLE, UINT32WLE | 4 | 2 | 0 to 4294967295 | BE, BLE, WLE |
INT32 (INT32BE), INT32BLE, INT32WLE | 4 | 2 | −2147483648 to 2147483647 | BE, BLE, WLE |
INT64, INT64BLE, INT64WLE | 8 | 4 | 64-bit signed | BE, BLE, WLE |
INT32BE is the same as INT32.
Single-precision types
Section titled “Single-precision types”Written like DEF name F32EP1R source table address. IEEE 754 single precision, 4 bytes, two
registers: F32EPnR big-endian, F32BLEEPnR with all bytes reversed, F32WLEEPnR with the words
swapped. n is 0 to 3: the variable holds the value multiplied by 10ⁿ, so F32EP2R reads
12.34 as 1234 and writes 1234 as 12.34. See Fixed-point values.
Double-precision types
Section titled “Double-precision types”Written like DEF name F64EP1R source table address. IEEE 754 double precision, 8 bytes, four
registers: F64EPnR, F64BLEEPnR and F64WLEEPnR, with n from 0 to 6, the multiplier as
for single precision.
Memory sources
Section titled “Memory sources”Memory parameters keep values in the controller between runs, or share them between programs. The
limits apply to all programs on the device together; a parameter that does not fit fails to
compile. A parameter takes the bytes of its type: 1, 2, 4 or 8. Reads and writes of memory
parameters do not wait for @PARAMTIMEOUT or @PARAMLOADRATIO.
MEMTEMP
Section titled “MEMTEMP”RAM: 2048 bytes, fast, lost when the controller restarts or loses power.
MEMBAT
Section titled “MEMBAT”Memory powered by the clock battery: 64 bytes, kept through power loss.
MEMFILE
Section titled “MEMFILE”A file on the memory card: up to 65535 bytes, slower, needs the memory card with the programs. A
write that fails raises EXC_IO. MEMFILE parameters do not share storage between programs.
MEMFLASH
Section titled “MEMFLASH”The controller’s settings area: 800 bytes, kept through restarts, read-only for programs. WRITE
to a MEMFLASH parameter fails to compile.
Tables and addresses
Section titled “Tables and addresses”| Table | Modbus data | Types | WRITE to a device |
|---|---|---|---|
C | coils | BIT | yes |
D | discrete inputs | BIT | no |
H | holding registers | all but BIT | yes |
I | input registers | all but BIT | no |
address is the zero-based address of the first coil or register: a fixed number from 0 that
leaves room for all the type’s registers within 65535, or a variable plus an offset 0 to
65535 (base+4), read at run time. WRITE needs table C or H on a device that allows
writes, or a memory source other than MEMFLASH.
A memory parameter with a table and address is also the controller’s own register or coil at that address, readable by HMI and other Modbus clients. Memory parameters of the same source, table, address and size share storage, also across programs: one program writes the value and the others read it. A second program that writes it fails to compile, and the device skips that file. Mapped memory parameters that overlap without matching exactly fail to compile.
Actions
Section titled “Actions”Each run starts at the run label, or at the first action without one, and
performs actions in order until EXIT. Assignments (PUT) store a result, checks (IF) skip the
next action, and commands do the rest.
PUT target
Section titled “PUT target”Stores a result in target, a variable or condition, or an array item: PUT target, a
function and its operands. The function’s result has the target’s kind. Without a
function, the item after the target is copied into it (VAL): PUT copy original,
PUT limit 250, PUT flag TRUE. A target not defined yet is defined as the function’s kind. With
@SYNTAX 2, PUT may be left out.
IF condition
Section titled “IF condition”Performs the next action only when the condition is TRUE; FALSE and unknown skip it.
condition is a condition name or array item, TRUE, FALSE, or a function with a condition
result (IF GR t limit). A function with a variable result fails to compile. An IF covers one
action: use GO to skip more.
Two IFs in a row do not mean “and”. When the first condition is not TRUE, it skips the second
IF, and the action after the second one runs. HMI warns about an IF whose next action is
another IF. To require both conditions, use IF AND, with each condition stored in a
condition name first if needed (PUT warm GR t limit).
run: and onerror:
Section titled “run: and onerror:”Two labels with a fixed meaning. run marks the first action of each run; without it, runs start
at the file’s first action. onerror marks the program’s error handler: an error that no
TRYCALL handler catches jumps there, with the error code in
LASTERROR. These names cannot name other items.
An error interrupts the function it happens in and jumps to that function’s handler. With no
handler, or when the handler itself fails, the error goes to the caller’s handler, and at the top
to onerror. An error with no handler is unhandled: the device writes
Unhandled error #<code> at line <line>: <name> to its log (while device-side logging is on) and
ends the run with that error. The line is the program line of the action that failed. See
Debug programs on an MC252.
Commands
Section titled “Commands”EXIT error
Section titled “EXIT error”Ends the run. error is OK for a normal end, an error name, an integer error code, or
LASTERROR; another variable fails to compile. The task reports a code other than OK as its last
error.
CALL label
Section titled “CALL label”Runs the actions from label until RETURN, then continues after the CALL. Calls can nest; the
depth is limited by the number of RETURN actions in the file, and a deeper call raises
EXC_STACK_OVERFLOW.
RETURN
Section titled “RETURN”Ends the function started by the last CALL or TRYCALL and continues after it. Without one it
raises EXC_STACK_UNDERFLOW.
WRITE parameter value
Section titled “WRITE parameter value”Writes a variable or an integer to the parameter, converted to its type. The parameter is in table
C or H of a device that allows writes, or in a memory source other than MEMFLASH. An unknown
value raises EXC_UNKNOWN; a device that fails raises its error.
GO label
Section titled “GO label”Continues at label. With IF, it makes branches and loops; bound every loop so that a run ends
within @UPDATE.
SYSLOG string
Section titled “SYSLOG string”Writes the string to the device log (/LOGS/SYS.LOG on the memory card). It writes only while the
device’s task logging is on, in HMI the endpoint’s device-side logging
(Device log); otherwise it does nothing.
SENDSMS addressee text
Section titled “SENDSMS addressee text”Sends text as an SMS to the number addressee produces, both strings (*PHONE(0)* gives a
number from the settings). An addressee with nothing but 0 digits sends nothing. A failed send
raises EXC_IO.
TRYCALL label handler
Section titled “TRYCALL label handler”Like CALL, with its own error handler: an error in the function jumps to the label handler,
with the error code in LASTERROR.
PARAMLOGNOCOMMENT parameter
Section titled “PARAMLOGNOCOMMENT parameter”Writes the parameter’s value to the device’s data log, from which HMI records readings
(Record readings on an MC252). The log
identifies the value by its Modbus address, so the parameter needs a table and address. Log a
device parameter, using an MBSELF device for the controller’s own registers: logging a
mapped memory parameter compiles, but the write fails and stops all program logging until the
device restarts or reloads its programs. Nothing is written while the device’s task log format
setting is off.
PARAMLOG parameter comment
Section titled “PARAMLOG parameter comment”Like PARAMLOGNOCOMMENT, with the string comment stored with the value.
RAISE error
Section titled “RAISE error”Raises an error: an error name, an integer error code, or LASTERROR to pass a handled error on to
the caller’s handler. RAISE OK and RAISE 0 fail to compile.
Evaluations
Section titled “Evaluations”Functions compute the result of a PUT, and those with a condition result also the check of an
IF. A function with an unknown operand usually gives an unknown result (see
Unknown values). Where a function takes variable and value, the first is a
variable (not an integer) and the second a variable or an integer.
Arithmetic
Section titled “Arithmetic”PUT target ADD variable value
Section titled “PUT target ADD variable value”The sum, variable + value.
PUT target SUB variable value
Section titled “PUT target SUB variable value”The difference, variable - value.
PUT target MUL variable value
Section titled “PUT target MUL variable value”The product, variable * value.
PUT target DIV variable value
Section titled “PUT target DIV variable value”The integer quotient, variable / value, with the fractional part dropped. Division by zero raises
EXC_RESULT_INFINITY.
PUT target MOD variable value
Section titled “PUT target MOD variable value”The remainder, variable - (variable / value * value); it has the sign of variable. A zero
value raises EXC_RESULT_INFINITY.
PUT target SQRT value
Section titled “PUT target SQRT value”The integer square root, rounded down. A negative value raises EXC_RESULT_COMPLEX; a negative
integer fails to compile.
PUT target BITSAND variable value
Section titled “PUT target BITSAND variable value”Bitwise AND of the two values.
PUT target BITSOR variable value
Section titled “PUT target BITSOR variable value”Bitwise OR of the two values.
PUT target BITSNOT value
Section titled “PUT target BITSNOT value”The value with every bit inverted.
PUT target SHR variable value
Section titled “PUT target SHR variable value”variable shifted right by value bits, keeping the sign (arithmetic shift).
PUT target SHL variable value
Section titled “PUT target SHL variable value”variable shifted left by value bits.
PUT target BITSBIT variable bit
Section titled “PUT target BITSBIT variable bit”Bit number bit of variable, 0 or 1, counted from 0 for the least significant bit: the
same as SHR by bit followed by BITSAND with 1.
Comparisons
Section titled “Comparisons”Each also works as PUT target and the same operands, storing the result in a condition.
IF EQ variable value
Section titled “IF EQ variable value”TRUE when variable = value.
IF NE variable value
Section titled “IF NE variable value”TRUE when variable ≠ value.
IF GE variable value
Section titled “IF GE variable value”TRUE when variable ≥ value.
IF LS variable value
Section titled “IF LS variable value”TRUE when variable < value.
IF GR variable value
Section titled “IF GR variable value”TRUE when variable > value.
IF LE variable value
Section titled “IF LE variable value”TRUE when variable ≤ value.
These take condition names or array items with an integer index, not TRUE or FALSE, and also
work as PUT target.
IF AND a b
Section titled “IF AND a b”TRUE when both are TRUE. FALSE when either is FALSE, even if the other is unknown.
IF NAND a b
Section titled “IF NAND a b”The inverse of AND: FALSE when both are TRUE.
IF OR a b
Section titled “IF OR a b”TRUE when either is TRUE, even if the other is unknown.
IF NOR a b
Section titled “IF NOR a b”The inverse of OR: TRUE when both are FALSE.
IF NOT condition
Section titled “IF NOT condition”The inverse of the condition; unknown stays unknown. It takes a condition name or array item,
including one with a variable index, but not TRUE or FALSE. Also works as PUT target.
Copying
Section titled “Copying”PUT target VAL item
Section titled “PUT target VAL item”A copy of item: a variable, an integer, a condition, TRUE or FALSE, or an array item. A
variable index works on one side of the copy. The kinds of target and item match. VAL may be left
out (PUT copy original) unless @SYNTAX 0. In an IF, the item is a condition.
Parameters
Section titled “Parameters”PUT target READ parameter
Section titled “PUT target READ parameter”Reads the parameter and converts its value to a variable. A device parameter is read with a Modbus
request, subject to @PARAMTIMEOUT and @PARAMLOADRATIO; a failed read raises the device’s
error. A memory parameter that was never written reads as unknown.
Arrays of values
Section titled “Arrays of values”These take an array of variables defined with VARS and at least two items.
PUT target MAX array
Section titled “PUT target MAX array”The largest item.
PUT target MAXIDX array
Section titled “PUT target MAXIDX array”The index of the largest item, from 0 to the array size minus 1.
PUT target MIN array
Section titled “PUT target MIN array”The smallest item.
PUT target MINIDX array
Section titled “PUT target MINIDX array”The index of the smallest item, from 0 to the array size minus 1.
PUT target SUM array
Section titled “PUT target SUM array”The sum of the items.
PUT target SELECTBY array selectors
Section titled “PUT target SELECTBY array selectors”The item of array at the position of the first TRUE in selectors, an array of conditions of
the same size. Items after the first TRUE do not matter, even unknown ones.
Errors
Section titled “Errors”error is an error name or an integer code.
PUT target ERR error
Section titled “PUT target ERR error”The numeric code of the error, for example PUT code ERR EXC_IO.
IF ERREQ variable error
Section titled “IF ERREQ variable error”TRUE when the variable holds the error’s code: IF ERREQ LASTERROR EXC_PARAM_TARGET_FAILED. Also
works as PUT target.
IF ERRNE variable error
Section titled “IF ERRNE variable error”TRUE when the variable does not hold the error’s code. Also works as PUT target.
Known values
Section titled “Known values”IF ISKNOWN item
Section titled “IF ISKNOWN item”TRUE when the variable or condition item has a value, never unknown. The item is defined or
used earlier in the file. Also works as PUT target.
IF ISNOTKNOWN item
Section titled “IF ISNOTKNOWN item”TRUE when item is unknown. Use it to give a default to a memory parameter that was never
written. Also works as PUT target.
IF SMSRCVD sender text
Section titled “IF SMSRCVD sender text”TRUE when a new SMS came from a number starting with the string sender and its text starts with
the string text. EMPTYSTRING as sender matches any number. Also works as PUT target.
IF NOSMSRCVD sender text
Section titled “IF NOSMSRCVD sender text”The inverse of SMSRCVD. Also works as PUT target.
These take no operands and cannot be used in an IF.
PUT target GETUPDPERIODSEC
Section titled “PUT target GETUPDPERIODSEC”The run interval in seconds.
PUT target GETUPDPERIODMSEC
Section titled “PUT target GETUPDPERIODMSEC”The run interval in milliseconds.
PUT target GETUPDNAMEIDX
Section titled “PUT target GETUPDNAMEIDX”The first integer in the program’s file name: 3 for PUMP3.TXT. Use it as a base for addresses
so that copies of one program under different names use different registers. A file name without a
digit fails to compile.
The controller’s real-time clock, local time with daylight saving time. No operands; not in an
IF.
PUT target GETRTC
Section titled “PUT target GETRTC”The clock in seconds since the start of the base year, usually 2000.
PUT target GETYEAR
Section titled “PUT target GETYEAR”The year.
PUT target GETMONTH
Section titled “PUT target GETMONTH”The month, 1 to 12.
PUT target GETDAY
Section titled “PUT target GETDAY”The day of the month, 1 to 31.
PUT target GETHOURS
Section titled “PUT target GETHOURS”The hour, 0 to 23.
PUT target GETMINUTES
Section titled “PUT target GETMINUTES”The minutes, 0 to 59.
PUT target GETSECONDS
Section titled “PUT target GETSECONDS”The seconds, 0 to 59.
PUT target GETDOW
Section titled “PUT target GETDOW”The day of the week, 1 (Monday) to 7 (Sunday).
PUT target GETDAYTIME
Section titled “PUT target GETDAYTIME”Seconds since midnight, 0 to 86399.
PUT target GETSUNRISE
Section titled “PUT target GETSUNRISE”Today’s sunrise in seconds since midnight; -1 during polar day, 86400 during polar night.
PUT target GETSUNSET
Section titled “PUT target GETSUNSET”Today’s sunset in seconds since midnight; -1 during polar day, 86400 during polar night.
Controller
Section titled “Controller”No operands; not in an IF.
PUT target GETVOLTAGE
Section titled “PUT target GETVOLTAGE”The supply voltage in millivolts.
PUT target GETTEMPERATURE
Section titled “PUT target GETTEMPERATURE”The controller’s temperature in degrees.
Values and errors
Section titled “Values and errors”Fixed-point values
Section titled “Fixed-point values”Variables are integers. Fractions are kept as integers with a fixed multiplier, such as tenths: the
EPnR floating-point types apply one when they read and write, and many devices report scaled
integers. Addition and subtraction keep the multiplier; multiplication multiplies the multipliers,
division divides them, and a square root needs a multiplier with an even number of zeros.
Unknown values
Section titled “Unknown values”A variable or condition is unknown before it is first assigned, after a read of a memory parameter
that was never written, after a failed assignment, and at the start of each run with
@RESETDATA 1. Most functions with an unknown operand give an unknown result; AND, OR and
SELECTBY give a result when the known operands decide it. IF treats unknown as FALSE: choose
IF GR or its inverse IF LE so that the skipped branch is the safe one, and guard with
ISKNOWN.
Where an action needs a number, unknown is an error: WRITE and EXIT of an unknown variable and
an array item with an unknown index raise EXC_UNKNOWN.
LASTERROR
Section titled “LASTERROR”A predefined variable holding the code of the last error. Handlers check it with
IF ERREQ LASTERROR EXC_IO, strings print it with *ERR(lasterror)*, and EXIT LASTERROR or
RAISE LASTERROR pass it on. RAISE sets it; programs do not assign it with PUT. EXIT and
RAISE take it, but no other variable.
Error codes
Section titled “Error codes”LASTERROR, ERR, the codes EXIT and RAISE take, a task’s last error and the
Unhandled error #<code> log line use these codes. Names can be written wherever an error is
expected. These are run-time errors; compile errors have their own codes, which the program editor
explains on each problem.
| Code | Name | Raised when |
|---|---|---|
| 0 | OK | No error |
| 1 | EXC_MB_ILLEGAL_FUNCTION | The Modbus device answered with exception 1 |
| 2 | EXC_MB_ILLEGAL_DATA_ADDRESS | The Modbus device answered with exception 2 |
| 3 | EXC_MB_ILLEGAL_DATA_VALUE | The Modbus device answered with exception 3 |
| 4 | EXC_MB_SLAVE_DEVICE_FAILURE | The Modbus device answered with exception 4 |
| 5 | EXC_MB_ACKNOWLEDGE | The Modbus device answered with exception 5 |
| 6 | EXC_MB_SLAVE_BUSY | The Modbus device answered with exception 6 |
| 8 | EXC_MB_MEMORY_PARITY_ERROR | The Modbus device answered with exception 8 |
| 10 | EXC_PARAM_PATH_UNAVAILABLE | The controller has no path to the device (gateway exception 10) |
| 11 | EXC_PARAM_TARGET_FAILED | The device did not answer within @PARAMTIMEOUT (gateway exception 11) |
| 60 | EXC_TYPE_UNKNOWN | A parameter value could not be converted to or from its type |
| 61 | EXC_ACTION_UNKNOWN | The action is unknown to the firmware |
| 62 | EXC_IO | Sending an SMS, writing a MEMFILE parameter, or reading the task’s compiled file failed |
| 63 | EXC_OUT_OF_MEMORY | The controller ran out of memory |
| 64 | EXC_STACK_OVERFLOW | CALL or TRYCALL nested too deep |
| 65 | EXC_STACK_UNDERFLOW | RETURN without a CALL |
| 66 | EXC_RESULT_INFINITY | Division by zero |
| 67 | EXC_RESULT_COMPLEX | Square root of a negative value |
| 68 | EXC_OUT_OF_BOUNDS | An array index outside the array |
| 69, 70, 79 | EXC_UNKNOWN | The task or a parameter was lost while running, or a value was unknown where a number is needed |
Any other code also shows as EXC_UNKNOWN. A device that does not answer raises
EXC_PARAM_TARGET_FAILED, not EXC_IO.