WriteIO (Set Status of Digital Control Ports)

The WriteIO instruction is used to set the status of the digital control ports or universal terminals under program control. See also PortSet (Set Port).

Syntax

WriteIO ( Mask, SourceChannelType )

Remarks

By default, 5 V is applied to the port when the State is set high. Use the PortPairConfig instruction to set the output to 3.3 V.

There are 4 control ports and 12 universal terminals available on the datalogger. The WriteIO instruction is used to set these ports using a binary representation where a high port (+5 V or +3.3 V) equals to 1 and a low port (0 V) equals to 0. The terminals are represented in the order of U12, U11, U10, etc., and C4, C3, C2, C1 (reading from left to right).

This instruction is not controlled by the task sequencer, but is controlled by processing. Therefore this instruction can be placed within a conditional statement. It should be remembered that processing can lag multiple scans behind measurements. See also PortSet.

NOTE: Programs with WriteIO will compile in sequential mode unless put into pipeline mode using the PipelineMode instruction. Because WriteIO runs as a processing task, when run in PipelineMode port changes may not occur in synchrony with measurements being made. Thus in PipelineMode, the instruction should not be used to control power to sensors from which measurements are being made.

Parameters

Mask

The Mask parameter is used to select which of the ports to read or write. It is a binary representation of the ports.

If ChannelType = 0, Mask is a four bit values and the range of valid arguments includes 0 to 15, &h0 to &hF, &b0000 to &b1111. The most significant bit maps to port C4. The least significant bit maps to port C1.

If ChannelType = 1, Mask is a twelve bit value and the range of valid arguments include 0 to 4095, &h000 to &hFFF, &b000000000000 to &b111111111111. The most significant bit maps to port U12. The least significant bit maps to port U1.

ReadIO: If a port position is set to 1, the datalogger reads the status of the port. If a port position is set to 0 the datalogger ignores the status of the port (the Mask is "anded" with the port status; the "and" operation returns a 1 for a digit if the Mask digit and the port status are both 1, and a 0 if either or both is 0). CRBasic allows the entry of numbers in binary format by preceding the number with "&B".

WriteIO: If a port position in the mask is set to 1, the datalogger sets the port based on the value for that port in the Source. If a port position in the mask is set to 0 the value in the Source is ignored. Binary numbers are entered into CRBasic by preceding the number with "&B". For example, if the mask is entered as &B110 (leading zeros can be omitted in binary format just as in decimal) and the source is 5 decimal (binary 101) port 3 will be set high and port 2 will be set low. The mask indicates that only 3 and 2 should be set. While the value of the source also has a 1 for port 1, it is ignored because the mask indicates 1 should not be changed.

Type: Binary value (preceded by &B) or Integer (from 0 to 255 representing the binary value)

Source

The name of the Variable that is the input for the instruction. Right-click the parameter to display a list of defined variables.

Type: Variable

For the WriteIO instruction, the Source parameter is a constant or the variable that holds the value for setting the control ports. The Source value is interpreted as a binary number and the ports are set accordingly.

ChannelType

An optional parameter used to specify whether to apply the mask to the control ports or to the universal terminals. Enter 0 or leave blank for control terminals or 1 for universal terminals.

If this parameter is omitted, control ports are used by default.