ModRtuToken (FB)

FUNCTION_BLOCK ModRtuToken EXTENDS AbbLConCA

Communication to generic Modbus server devices via Modbus RTU using LineToken variable.

Function block ModRtuToken controls the Modbus RTU communication to a generic Modbus RTU server device. A generic Modbus RTU server device can be any field device which supports Modbus RTU server within it such as PLC, HMI or ABB ACS/DCS drive etc. It must be used together with the function blocks ModRtuRead and/or ModRtuWrite and/or ModRtuReadWrite23 to exchange Modbus data.

If more devices are connected to the same Modbus RTU line, for each of them an own instance of ModRtuToken or DrvModbusRtu (for connection to an ABB ACS/DCS drive) function block must be used. All these ModRtuToken and/or DrvModbusRtu (for connection to an ABB ACS/DCS drive) function blocks must be connected to the same LineToken variable of type ModRtuTokenType at their IN_OUT LineToken. Via this LineToken variable the serial access to the different devices is controlled. All these blocks must be called within the same PLC task.

At the IN_OUT ServData a variable of type ModRtuGenDevDataType must be connected, which in turn connected to the Modbus read/write function blocks related to the same device. Via the function blocks ModRtuRead, ModRtuWrite and ModRtuReadWrite23, the Modbus jobs are initiated in the order they are programmed. The requests to process these read, write or readwrite Modbus jobs are transferred via IN_OUT ServData variable to the ModRtuToken function block. The Modbus job will be started, when the ModRtuToken function block of the server has the token, and the read/write function block was started before. All these function blocks must be called within the same PLC task.

The input Timeout sets the timeout for one Modbus job in ms. After a Timeout this server will not be reconnected for the time specified at the input ReconnectPause in seconds. So a steady delay for a disconnected server can be avoided.

Error ERR_COM_DIFFERENT_LINE

In the same LineToken, if one function block has wrong Com port configured. At the program startup (rising edge of Enable input) if this block will occupy the LineToken with its Com value, the following blocks with different values at their Com input will be set to error ERR_COM_DIFFERENT_LINE, even if the following blocks might have the correct Com value. To verify who has occupied LineToken, user can check the byComSlot value in the LineToken variable. To solve this situation, a rising edge (FALSE to TRUE) must be given at Enable input of the function blocks where correct Com input is configured.

Diagnosis

The output ErrorID, which reflects an actual error number is only valid for one cycle, output Error is set to TRUE. To capture this error number, an external function must be programmed. However there are internal diagnosis variables available, which are not shown at any output, but can be accessed from the function block instance or visualization.

The additional diagnosis variables are:

uiWriteErrCnt: number of errors in write jobs since Enable = TRUE.

wLastWriteErno: holds the error number of the last executed write job.

uiReadErrCnt: number of errors in read jobs since Enable = TRUE.

wLastReadErno: holds the error number of the last executed read job.

uiReadWriteErrCnt: number of errors in read write jobs with function code 23 since Enable = TRUE.

wLastReadWriteErno: holds the error number of the last executed read write job with function code 23.

uiWriteMaskErrCnt: number of errors in writemask jobs with function code 22 since Enable = TRUE.

wLastWriteMaskErno: holds the error number of the last executed writemask job with function code 22.

Note

This function block must not be used in parallel with ModRtuMast function block for the same RTU line.

The function block must be used in same PLC task than other function blocks using the same variable on IN_OUT LineToken and 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

Com

BYTE

1

2: Modbus communication port - e.g: 1 = COM1 - changes are valid only after rising edge of Enable input (FALSE -> TRUE). Valid values are 1 to 3 depending on PLC type and configuration.

Serv

BYTE

1

3: Modbus RTU server address - if changed while a modbus job is running, this job will be finished with previous Serv address; 0 = Broadcast. valid range is 0..247.

TimeOut

WORD

1000

4: Timeout [ms] for ModRtuMast function block - TimeOut value should be at least 50ms.

ReconnectPause

WORD

0

5: Pause in seconds before next retry to connect after a timeout was detected. Timeout is detected with ModMastErrorID = 16#120

Inout

LineToken

ModRtuTokenType

6: Reference variable to connect to other Modbus RTU function blocks ModRtuRead, ModRtuWrite and ModRtuReadWrite23.

ServData

ModRtuGenDevDataType

7: Modbus RTU server reference variable to connect to all function blocks of this server device.

Output

ErrorID

ERROR_ID

4: Error codes

ModMastErrorAct

BOOL

FALSE

5: Active error in ModMast. 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

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 Enable 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: Modbus job finished

JobBusy

BOOL

FALSE

10: Modbus job active

Online

BOOL

FALSE

11: Connection established without error, all read jobs without errors and all Modbus Jobs finished within time set at input Timeout.