ModRtuReadWrite23 (FB)

FUNCTION_BLOCK ModRtuReadWrite23

Function block ModRtuReadWrite23 reads and writes n data to the Modbus server device via Modbus RTU with Modbus function code FCT = 23. This function block internally calls ModRtuWrite to execute Read Write job with FCT = 23, used along with structure COM_MOD_FCT23_TYPE.

The number of data to be read is specified at the input NbRead. The first address for Read operation is specified at the input AddrRead. The values of the data is stored in the PLC memory area, defined at the input DataRead. The number of data to be written is specified at the input NbWrite. The first address for write operation is specified at the input AddrWrite. The values of the data that should be written must be stored in the PLC memory area, defined at the input DataWrite.

The values in the PLC memory area are updated when the Read Write job was performed without error. A successful Read Write operation is indicated by JobDone = TRUE, ModMastErrorAct = FALSE and WarnAct = FALSE

To initiate a Read Write job the Execute input must be given a rising edge. (FALSE -> TRUE). The values at the inputs will not in any case be stored in the moment of the rising edge of the Execute input. The input values will be stored, when the corresponding ModRtuToken function block has the modbus line token and the instance of this ModRtuReadWrite23 block has the internal server token. If the rising edge of Execute is given e.g. with the JobDone output of the previous programmed ModRtuRead or ModRtuWrite block or ModRtuReadWrite23 function block, these events occur in the same time and the values are stored immediately. The values that should be written must be kept stable for one more PLC cycle in the same PLC memory area, defined at the input DataWrite.

After termination of this job, even if it was not successful, a next Read Write job can only be started with a rising edge at Execute input. If the Execute input is kept to TRUE the outputs Done, JobDone, any Warning or Error message be kept until the Execute input is set to FALSE.

The Modbus job is started from the ModRtuToken Function Block which is connected to the same ServData variable. To trigger the read write job user must Enable the ModRtuToken function block with the same ServData IN_OUT configured.

The Modbus server address of the device to which the Read Write job is to be sent 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.

If at least 1 input is invalid, no job is generated and the error is displayed at the outputs Error and ErrorID instead.

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

Input

Execute

BOOL

FALSE

1: A rising edge starts the operation, the output Busy goes to TRUE. In the first cycle all other inputs are read and stored, afterwards they are ignored. A falling edge does not stop the operation. After Done = TRUE or Error = TRUE and Execute = FALSE all outputs will be reset.

Prio

BOOL

FALSE

2: Reserved - not used.

NbRead

UINT

1

3: Number of variables to be read. valid range is: 1 .. 125 - see general description, about when the value is stored in the function block.

AddrRead

UINT

0

4: Address from where to read in modbus server device. valid range is 0..65535 - see general description, about when the value is stored in the function block.

DataRead

DWORD

0

5: 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.

NbWrite

UINT

1

6: Number of variables to be written. valid range is: 1 .. 121 - see general description, about when the value is stored in the function block.

AddrWrite

UINT

0

7: Address to write to in modbus server device, valid range is 0..65535 - see general description, about when the value is stored in the function block.

DataWrite

DWORD

0

8: First operand address of an operand area in the AC500, from which data should be written to the modbus server - see general description, about when the data written. Use ADR operator to connect the input.

Inout

ServData

ModRtuGenDevDataType

9: Modbus server device reference variable to connect to all Modbus server function blocks.

Output

Done

BOOL

FALSE

1: Operation is completed without error (while outputs Busy and Error are FALSE). This output is TRUE for atleast one cycle or until Execute is set to FALSE.

Busy

BOOL

FALSE

2: Operation is running (while outputs Done and Error are FALSE).

Error

BOOL

FALSE

3: Operation is stopped with error (while outputs Busy and Done are FALSE). This output is TRUE for at least one cycle or until Execute is set to FALSE. The output ErrorID gives more details about the error.

ErrorID

ERROR_ID

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 Execute is set to FALSE. The output ModMastErrorIDLast gives more details about the last error.

ModMastErrorIDLast

ERROR_ID

6: Error code of last active error in ModRtuMast, For error code description, refer to error codes in ERROR_ID.

WarnAct

BOOL

FALSE

7: Operation is running with warning . This output is TRUE for at least one cycle or until Execute is set to FALSE. The output WarnIDLast gives more details about the warning.

WarnIDLast

WARNING_ID

8: Warning code of last active warning.

JobDone

BOOL

FALSE

9: Read Write job finished.

JobBusy

BOOL

FALSE

10: Read Write job active.