ModRtuRead
(FB)
FUNCTION_BLOCK ModRtuRead EXTENDS AbbLConCA
Function block ModRtuRead reads n data of the Modbus server device via Modbus RTU. The number of data to be read is specified at the input Nb. The first address is specified at the input Addr. The values of the data is stored in the PLC memory area, defined at the input Data. The values in the PLC memory area are updated when the read job is performed without error. This is indicated by JobDone = TRUE, ModMastErrorAct = FALSE and WarnAct = FALSE.
As long as the input Enable = TRUE a new read job is requested each time the previous job is terminated.
The Modbus job is started from the ModRtuToken function block which is connected to the same ServData variable. To trigger the read job user must Enable the ModRtuToken function block with the same ServData IN_OUT configured.
The Modbus server address of the device from which the data is to be read is specified at this ModRtuToken function block.
If the input values are valid, a request to perform a Modbus RTU job is send to the ModRtuToken function block via the ServData variable.
The ModRtuRead function block does only change the values at the Data input if the Modbus job was executed without errors. If the function block is not enabled or the connection to the ModRtuToken function block is not ok, these values are not updated and retain their previous values. This is also the case for the internal aiValue array.
When the function code is 1 or 2 the address inputted at the Addr input would be taken in bits and similarly when the function code is 3 or 4 the address inputted at the Addr input would be taken in word.
Note
The function block must be used in same PLC task than other function blocks using the same variable on IN_OUT ServData.
- InOut:
Scope
Name
Type
Initial
Comment
Inherited from
Input
Enable
BOOL
FALSE
A rising edge (Enable = TRUE) starts the operation, the output Busy goes to TRUE. All other inputs are read and considered continuously. A falling edge (Enable = FALSE) aborts the operation. During Aborting the Busy is still TRUE. Afterward all outputs are reset.
AbbLConCA
Output
Busy
BOOL
FALSE
Operation is running (while output Error is FALSE)
AbbLConCA
Error
BOOL
FALSE
Operation is stopped with error (while output Busy is FALSE). This output is TRUE for at least one cycle or until Enable is set to FALSE. The output ErrorID gives more details about the error.
AbbLConCA
Input
Prio
BOOL
FALSE
2: Reserved - not used.
Fct
BYTE
3
3: Modbus function code. 1 or 2 = read n bits; 3 or 4 = read n words. valid range is 1..4
Nb
UINT
1
4: Number of variables to be read. valid range is: 1 .. 2000
Addr
UINT
0
5: Address from where to read in modbus server device. valid range is 0..65535
Data
DWORD
0
6: First operand address of an operand area in the AC500, to which data read by the modbus server should be stored. Use ADR operator to connect the input.
Inout
ServData
7: Modbus server device reference variable to connect to all Modbus server function blocks.
Output
ErrorID
4: Error codes
ModMastErrorAct
BOOL
FALSE
5: Active error in ModRtuMast. Operation is running with error . This output is TRUE for at least one cycle or until Enable is set to FALSE. The output ModMastErrorIDLast gives more details about the last error.
ModMastErrorIDLast
6: Error code of last active error in ModRtuMast, For error code description, refer to error codes in ERROR_ID.
WarnAct
BOOL
FALSE
7: Active warning. Operation is running with warning . This output is TRUE for at least one cycle or until Enable is set to FALSE. The output WarnIDLast gives more details about the warning.
WarnIDLast
8: Warning code of last active warning
JobDone
BOOL
FALSE
9: Read job finished
JobBusy
BOOL
FALSE
10: Read job active