> For the complete documentation index, see [llms.txt](https://help.qtech.co.nz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.qtech.co.nz/datran/datran-vi-scada/datran-dlp-ide/instruction-reference/program-structure.md).

# Program structure and initialisation

PROGINIT, PROGSTART, PROGEND, TELINP, TELOUT, EQU, EQULAB, INITANL, INITDIG, CPANL, CPDIG, COSMASK and NCOSMASK.

These instructions lay out the DLP, name points, set starting values, connect real and telemetry I/O, and choose which inputs send change-of-state (COS) messages. Most go in the initialisation section, between `PROGINIT` and `PROGSTART`, which runs once when the RTU starts.

## PROGINIT

**Syntax:** `PROGINIT`

This instruction is used at the beginning of the DLP program to indicate the start of the Initialisation. The initialisation part of the DLP is only executed once upon startup or reset; allowing variables to be initially set to a predetermined value.

## PROGSTART

**Syntax:** `PROGSTART`

This instruction is used at the end of the initialisation code, and denotes beginning of the DLP program. The RTU will continuously run the code that follows.

## PROGEND

**Syntax:** `PROGEND`

`PROGEND` denotes the end of the DLP program. This instruction tells the RTU to stop executing. The RTU goes back to `PROGSTART`.

## TELINP

**Syntax:** `TELINP`

The `TELINP` instruction uses no parameters and when used, disconnects the Real Inputs from the Telemetry Inputs. The Real Inputs will no longer be transferred to the Telemetry Inputs for transmission to the base, nor will they cause Change of State messages (COS). This instruction can be used when real world inputs are to be modified and manipulated by the DLP before results and calculations are subsequently transmitted to the base.

{% hint style="warning" %}
`TELINP` and `TELOUT` are indiscriminate and will sever the link to all IO. There is no way of just specifying a few points, so we need a way of reconnecting the points we don't want to modify. That's where `CPDIG` (Copy Digitals) and `CPANL` (Copy Analogs) come in. For how real, telemetry and notional points work, see the XL4 Plus [data table](https://help.qtech.co.nz/datran/datran-telemetry/datran-xl4-plus-rtu/configure.md#how-the-data-table-works).
{% endhint %}

## TELOUT

**Syntax:** `TELOUT`

The `TELOUT` instruction uses no parameters and when used, disconnects the Real Outputs from the Telemetry Outputs. The outputs controlled from the base will no longer be actioned. This instruction can be used when outputs are to be modified or manipulated by the DLP before results and calculations are subsequently connected to the real world.

## EQU

**Syntax:** `EQU Value Identifier`

The programmer can name specific I/O instead of using the nominal I/O identification, making programming easier. This instruction is not sent in the DLP.

```
EQU  RDIN1    MarkOne    ; MarkOne can now be used instead of RDIN1
EQU  RDOUT22  PumpRun1   ; PumpRun1 can now be used instead of RDOUT22
EQU  NAIN20   SetPt_1    ; SetPt_1 can now be used instead of NAIN20
```

It is advisable not to use dashes/hyphens in the identifier (new name of the point), as this will cause errors in the compiler.

## EQULAB

**Syntax:** `EQULAB Label Symbol`

The programmer can name specific labels instead of using the nominal label identification (`Label1` to `Label255`), making programming easier. This instruction is not sent in the DLP. It is advisable not to use dashes/hyphens in the symbol (name of the label), as this will cause errors in the compiler.

## INITANL

**Syntax:** `INITANL AnalogRegister, AnalogConstant`

Use this instruction to initialise analogue registers to preset values. The value must be in the decimal range of 0 to 65535.

```
INITANL  Anl_1, 2345   ; Put 2345 into Anl_1 at the start of the program
```

A section of code that contains commands that will always execute, such as `INITANL` or `INITDIG`, can be skipped with a jump statement.

## INITDIG

**Syntax:** `INITDIG DigitalRegister, DigitalConstant`

Use this instruction to initialise a digital register to a preset value, either True or False.

```
INITDIG  Dig_1, True   ; Set Dig_1 true at the start of the program
```

If not initialised, the Digital value will default to False. It is important to initialize parameters at the start of the DLP to put the memory locations in a known state. As delivered, the memory locations used by DLP variables are in the random state from when the IC was manufactured. See [Unexpected COS messages, or outputs that chatter](https://help.qtech.co.nz/datran/datran-vi-scada/datran-dlp-ide/troubleshooting/unexpected-cos-chatter.md).

## CPDIG

**Syntax:** `CPDIG DigitalRegisterSrc, DigitalRegisterDst, Count`

Copy the values of selected digital registers. This instruction is used after `TELINP` or `TELOUT` to copy a selected number Real Inputs to Telemetry Inputs, or Telemetry Outputs to Real Outputs. `DigitalRegisterSrc` is the first Digital I/O to be copied. `DigitalRegisterDst` is the first Digital I/O to which values are sent. `Count` is the number of subsequent digitals to be copied. `Count` must be a number greater or equal to 1.

```
CPDIG  RDIN3, TDIN3, 6     ; Copy RDIN3 to RDIN8 to TDIN3 to TDIN8
CPDIG  TDOUT1, RDOUT1, 8   ; Copy TDOUT1 to TDOUT8 to RDOUT1 to RDOUT8
```

## CPANL

**Syntax:** `CPANL AnalogRegisterSrc, AnalogRegisterDst, Count`

Copy the values of selected analogue registers. This instruction is used after `TELINP` or `TELOUT` to copy a range of selected Real Inputs to the Telemetry Inputs or Telemetry Outputs to the Real Outputs. `AnalogRegisterSrc` is the first Analogue I/O to be copied. `AnalogRegisterDst` is the first Analogue I/O to which values are sent. `Count` is the number of subsequent analogs to be copied. `Count` must be a number greater or equal to 1. It's also how you move a result out of the analogue accumulator:

```
CPANL  RAIN1, TAIN1, 6     ; Copy all 6 analogue inputs to the telemetry inputs
CPANL  ANLACC1, NAIN1, 1   ; Copy an arithmetic result to NAIN1
```

## COSMASK

**Syntax:** `COSMASK ModuleIndex [, COSIndex ]...`

Selects specific Telemetry Digital Inputs to cause COS messages. All inputs are initially set for COS operation. This means COS is enabled for all inputs by default. `COSMASK` overwrites the COS configuration set up in Q90 and is carried out every time the INIT section of the DLP is executed.

* **ModuleIndex** is the base index, a number from 0 to 10. Index 0 is the first 24 digital inputs (TDIN1 to TDIN24), index 1 is the second 24 digital inputs (TDIN25 to TDIN48), and so on.
* **COSIndex** is a comma separated list of all the inputs (1..24) that should cause a COS message. If the input is not in this list, then it will not cause a COS.

```
COSMASK 0  3,6,7     ; TDIN3, TDIN6 and TDIN7 send COS
COSMASK 1  1,3       ; TDIN25 and TDIN27 send COS
```

The reason for the indexed addressing is that original DATRAN product range only had digital input cards available in multiples of 24 digital inputs, and the main QRTUs also had 24 digital inputs. Nowadays the product range is more comprehensive and modules with digital input counts of 24, 16 and 8 inputs are commonly in use. This makes the indexing system a bit more confusing to use, but it has to remain for legacy support.

{% hint style="info" %}
It is not always desirable to allow ALL digital inputs to be able to trigger COS messages. A flow pulse input into an RTU, for example, may be pulsing often enough to cause the RTU to send a continuous stream of COS messages over the radio network, causing massive overloading and communications problems for all other sites using the same radio channel.
{% endhint %}

### Extended COSMASK

If the **Extended Point Count Support** option is enabled (**Tools > Compiler Options**) then an alternative syntax is available. The RTU must be running firmware version 7.0 or greater to support this command.

**Syntax:** `COSMASK DigitalRegister, Count, State`

The `COSMASK` instruction will set or clear a specified count of the COS enable bits starting from a given Digital Register. Several `COSMASK` instructions can be used together to produce the required overall COS mask configuration. The `DigitalRegister` type can be a Telemetry Digital Input or a Notional Digital Input.

```
COSMASK TDIN1, 8, true    ; COS on for TDIN1 to TDIN8 (the default)
COSMASK TDIN5, 1, false   ; COS off for TDIN5
```

The result is that COS will be enabled for the first 8 Telemetry Digital Inputs but not TDIN5.

## NCOSMASK

**Syntax:** `NCOSMASK [, COSIndex ]...`

Selects specific notional digital inputs to cause COS packets. The syntax for the `NCOSMASK` statement is very similar to `COSMASK` except there is no index, and the comma separated list goes all the way up to 255. All notional digital inputs are initially set for COS operation. This means COS is enabled for all notional digital inputs by default.

```
NCOSMASK 1,2,3, ,5,6,7   ; NDIN1 to NDIN3 and NDIN5 to NDIN7 send COS. NDIN4 and NDIN8 upwards don't.
```

{% hint style="warning" %}
The `NCOSMASK` command is only supported in firmware version v5.20 and above. If a DLP containing the `NCOSMASK` command is transmitted into an RTU with a lower version of firmware, the DLP will be rejected by the RTU. This may mean that the base continually tries to transmit the DLP until the user intervenes.
{% endhint %}

If the Extended Point Count feature is enabled, then it is possible to use the `COSMASK` instruction instead. If the **Automatically disable all NDIN change of state** check box is checked, NDIN change of state is automatically disabled if there is no use of the `NCOSMASK` instruction in the ASM/LDR file. This is done by inserting the `NCOSMASK` instruction into the DLP file compiled from the ASM/LDR file.
