Overview
In this third example, we’ll read an array of integer values from the Scratch Pad area of the OptoMMP memory map.
The goals of this example are:
- The client will connect and stay connected if there are any errors.
- Five elements of the Integer 32 Scratch Pad will be read into an integer array.
- The read requests will trigger five seconds after the previous one is finished.
This example assumes you have basic familiarity with creating and running an application in the CODESYS Development System. It also assumes you’ve read the Hello, world! and Write an Integer examples.
Continuous Function Chart
The variables for this example are:
PROGRAM MMP_READ_SCRATCH_PAD
VAR
mmpClient: OPTO.MmpClient;
mmpReadBlock: OPTO.MmpClientReadBlock;
audiValues: ARRAY[0..5] OF UDINT;
tonReadDelay: TON;
END_VAR
The implementation is quite similar to the previous examples:
Important details:
- The memory address of where the data will be stored must be passed into the
pData
input. TheADR
operator is used to get the memory address of theaudiValues
array of integers. - The number of bytes to read is passed into the
uiCount
input. TheSIZEOF
operator can be used to get the number of bytes used for a variable’s storage. - Like with the Write Integer example, the
xBusy
output of the request block is negated and wired into thexExecute
input. - To limit how often the values are updated, a
TON
turn-on delay function block is used to between the negatedxBusy
output and thexExecute
input.- When a request is triggered and the
xBusy
output turns TRUE, the value is negated to FALSE and the TON block will detect a falling edge on theIN
input and reset the timer. - When a request is finished and the
xBusy
output turns FALSE, the value is negated to TRUE and the TON block will detect a rising edge on theIN
input and start the timer.
- When a request is triggered and the
Ladder Logic
This example in Ladder Logic (LD) is very similar. Here’s one way it could be written:
Structured Text
This example in Structure Text (ST) is very similar. Here’s one way it could be written: