1. Configuration Task
This is the 'blueprint' of the system, which must be loaded before any application task to define global resources and hardware mappings, and it does not execute itself. The key statements include:
TASK: Define the names, types, CPU slots, and priorities (4-11) of all tasks (BASIC, PC, or control block tasks) in the system.
MEMDEF/NVMEMDEF: Define global variables (COMMON variables) that can be accessed by all tasks inside the chassis. The variables defined by NVMEMDEF can maintain their values after power failure and restart, and are suitable for process parameters that require persistence.
IODEF/NETDEF/RIODEF/MODDEF/RNETDEF/ABDEF: This series of "DEF" statements is used to map physical I/O addresses (local, remote, network, Modbus, AutoMate, Allen Bradley, etc.) to symbolic variable names, achieving software and hardware decoupling.
2. Application Task
This is the main body of the program that implements specific control logic. All variables must be defined before use:
LOCAL: Define local variables that are only used within this task, including simple variables, arrays, and adjustable variables. Adjustable variables allow operators to adjust parameters (such as PID gain) within a preset range (HIGH/LOW) at a specified step size (STEP) through the terminal during runtime, but the program can only read its value, enhancing the flexibility and safety of the system.
COMMON: Declare the global variables defined in the configuration task that will be used for this task.
3. Process control and subroutines
GOTO/ON GOTO: Implement unconditional or integer expression based conditional jumps.
GOSUB/ON GOSUB/RETURN: Used to call subroutines, supports nesting.
IF-THEN: Conditional judgment and execution based on Boolean expressions.
FOR-NEXT: Build a counting loop that supports nesting and stride (STEP) settings.
4. Program documentation
Support REM (compile time discard) and! Two formats of comment statements are available for easy code maintenance, which can be downloaded with the task and uploaded for viewing.
Advanced enhancements: multitasking, real-time, and I/O
1. Multi task enhancement
The system decomposes different control functions into independent tasks and achieves "concurrent" execution through priority scheduling. The key synchronization mechanisms include:
EVENT: Define software or hardware events. Hardware events can be associated with the interrupt status register of a specific I/O card and timeout protection can be set.
SET/WAIT: One task triggers an event with SET, and another or more tasks wait for the event with WAIT ON to achieve synchronization and communication between tasks.
OPEN CHANNEL: Establish a typed (I-integer, D-double integer, R-real, S-string, B-boolean) data channel between two tasks. The task reads and writes data to the channel through PRINCT # and INPUT #. If the channel is full/empty, the task is suspended, naturally achieving synchronization in the producer consumer mode.
2. Real time enhancement
DELAY: Suspend the task for a specified time (unit: TICKS [5.5 milliseconds] SECONDS、MINUTES、HOURS)。
START EVERY: Set the periodic execution of tasks. After the task is executed to the END statement, it sleeps and is reactivated by the operating system after the specified cycle. It starts executing from the START statement and is suitable for implementing a fixed speed control scan loop.
3. Powerful I/O capability
OPEN/CLOSE: Allocate and release logical devices (such as serial port PORTA).
INPUT/PRIMT: Read data from or output data to a device. PRIMT USING supports rich formatted outputs (left/right/center alignment, leading zeros, decimal control).
GET/PUT: Perform single character input/output.
Read/DATA/STORE: Read preset values from the internal data area of the program, which is more efficient than INPUT.
IOWRITE statement and IOREAD% function: designed specifically for accessing "peripheral" I/O cards that do not comply with DCS standards (such as byte only access or write only), allowing direct read and write operations to specific hexadecimal addresses, providing maximum hardware access flexibility.
Rich built-in function library
The function library covers mathematical operations, string processing, bit operations, BCD code conversion, screen control (VT100 terminal), and system level operations:
Mathematical functions: SIN, COS, TAN, ATN, LN, EXP, SQRT, ABS, etc.
String functions: CHR $, ASC%, LEN%, STR $, LEFT $, RIGHT $, MID $, VAL%, VAL, etc.
Bit and logic functions: BIT_SET @, BIT_CR @, BITVNet @, SHIFTL%, SHIFTR%, ROTATEL%, ROTATER%.
Industrial application functions: BCD_OUT%, BCD_IN% are used for data conversion of digital tubes or dip switches; BLOCKVNet @ is used for batch data transfer between variables and network I/O; GATEWAY_CMD-OK @ with VARPTR! Implement batch reading and writing of registers through gateways such as Modbus.
Error handling and system robustness
ON ERROR GOTO/RESUME: Allow programs to define runtime error handling routines. The predefined variables ERR% and ERL% provide error codes and error line numbers, respectively.
Error log: All non fatal errors are recorded in the task error log for easy diagnosis.