FB_MBDiagnose (Modbus function 8)

The diagnosis function provides a series of tests for checking the communication system between the master and the slave and for examining a variety of internal error states within the slave.
Inputs
VAR_INPUT
sIPAddr : STRING(15);
nTCPPort : UINT:= MODBUS_TCP_PORT;
nUnitID : BYTE:=16#FF;
nSubFnc : WORD;
nWriteData : WORD;
bExecute : BOOL;
tTimeout : TIME;
END_VAR
Name | Type | Description |
---|---|---|
sIPAddr | STRING (15) | Is a string containing the IP address of the target device. |
nTCPPort | UINT | Port number of the target device. |
nUnitID | BYTE | Identification number of a serial sub-network device. If a device is addressed directly via TCP/IP, this value must be 16#FF. |
nSubFnc | WORD | The sub-function to be executed. |
nWriteData | WORD | The data word to be written. |
bExecute | BOOL | The function block is enabled by a rising edge at this input. |
tTimeout | TIME | States the length of the timeout that may not be exceeded by execution of the ADS command. |
Outputs
VAR_OUTPUT
bBUSY : BOOL;
bError : BOOL;
nErrId : UDINT;
nReadData : WORD;
END_VAR
Name | Type | Description |
---|---|---|
bBusy | BOOL | When the function block is enabled, this output is set and remains set until a feedback is received. |
bError | BOOL | If an ADS error should occur during the transfer of the command, then this output is set once the bBusy output is reset. |
nErrId | UDINT | Returns the ADS error number when the bError output is set. |
nReadData | WORD | Supplies the read data word. |
Sample of calling the function block in FBD
PROGRAM Test
VAR
fbDiagnose : FB_MBDiagnose;
bDiagnose : BOOL;
bDiagnoseBusy : BOOL;
bDiagnoseError : BOOL;
nDiagnoseErrorId : UDINT;
nSubFnc : WORD;
nReadData : WORD;
nWriteData : WORD;
END_VAR

After rising edge of "bExecute" and successful execution of the diagnostic command, nReadData contains the read data word.
Requirements
Development environment |
Target system type |
PLC libraries to be linked |
---|---|---|
TwinCAT v3.0.0 |
PC or CX (x86) |
Tc2_ModbusSrv |