First of all, why use registers?
You may use global and local variables for data that will be known only to your program. Registers are your program's means of getting data to and from the outside world.
Data placed in registers by your program may do any of the following:
(a) Control actuator hardware
(b) Be read by an external Modbus device, external server, etc.
(c) Be logged to a data log file
(d) Interact with the real time scheduler
(e) Cause preformatted email messages to be sent
(f) Generate an SNMP trap or other even notification
Data taken from registers by your program may do any of the following:
(a) Read a sensor
(b) Provide data from an external Modbus device, external server, etc.
(c) Interact with the real time scheduler
... and probably more.
You may read any of the local registers using the get functions (procedures), and write them using the set functions. There are two forms of each, one for integer register contents, and one for floating point register contents. Syntax is:
<var> = geti ( <int reg> );
<var> = getf ( <float reg> );
seti ( <int reg> , <var> );
setf ( <float reg> , <var> );
Consider the following examples:
myData = geti (22);
seti (24, myData);
yourData = getf (1015);
setf (1017, yourData);
The above example will read the integer contents of register #22 into the variable myData, then write the value of myData to register #24. The example will then read the floating point contents of register #1015 into the variable yourData, then write the value of yourData to register #1017. Variables may be used in place of the literal constants used to identify registers in the above example.
INDIRECT REGISTER ACCESS
The co-processor's direct access to registers is limited to the first 60 each of integer registers and floating point register pairs. However, indirect access to all registers known to the server is available. To perform indirect access, you write the desired register number to the request pointer register, and wait for the acknowledge register to match the request. These special pointer registers start at 4001.
Reading a server register from the co-processor using indirect access:
Register 4001:The register number you wish to read (1, 1001, etc) is written into 4001 by your program.
Register 4002: Cleared when you write 4001, will contain same register number as found in 4001 when the read cycle is complete.
Register 4003/4004: Register 4003 contains the integer data read, or the 4003/4004 pair contains the floating point data read.
Writing a server register from the co-processor using indirect access:
Register 4007/4008: Write integer data to 4007 or floating point data to the register pair starting at 4007.
Register 4005: The register number you wish to write (1, 1001, etc) is written into 4005 by your program.
Register 4006: Cleared when you write 4005, will contain same register number as found in 4005 when the write cycle is complete.
Be sure to write data to 4007 before writing the register number to 4005 since writing 4005 starts the write process. Note that the 400x registers are virtual registers useful primarily in the co-processor PL/i program; however, they are functional on the server to allow testing of co-processor programs on the server.