This function is called from YOUR application code to perform a diagnostic check on a Modbus slave.
Prototype
CPU_INT16U MBM_FC08_Diag (MODBUS_CH *pch, CPU_INT08U slave_node, CPU_INT16U fnct, CPU_INT16U sub_fnct, CPU_INT16U *pval);
Arguments
pch
is a pointer to the channel (returned by MB_CfgCh()
). This pointer specifies onto which channel the Modbus master will be communicating on. Of course, ‘pch
’ must have been configured as a Master when you configured the channel.
slave_node
specifies the slave ‘node address’ of the slave you want to perform a diagnostic function to. This can be a number between 1 and 255 but needs to match the number assigned to the slave node.
fnct
specifies the function you want to perform on the slave and you must specify either:
MODBUS_FC08_LOOPBACK_CLR_CTR
You want to clear the loopback counters in the slave.
MODBUS_FC08_BUS_MSG_CTR
You want to read the counter of messages received by the slave. This counter keeps track of all messages received whether processed or not.
MODBUS_FC08_BUS_CRC_CTR
You want to read the counter of bad CRCs detected by the slave.
MODBUS_FC08_BUS_EXCEPT_CTR
You want to read the counter of exceptions detected by the slave.
MODBUS_FC08_SLAVE_MSG_CTR
You want to read the number of message received and processed by the slave.
MODBUS_FC08_SLAVE_NO_RESP_CTR
You want to read the number of messages that have not been replied to because of bad CRCs, invalid commands, etc.
sub_fnct
corresponds to a sub-function argument for the function. At this time, µC/Modbus does not support sub-functions.
Returned Value
MODBUS_ERR_NONE
if the call was successful.
MODBUS_ERR_RX
if a response was not received from the slave within the timeout specified for this channel (see MB_CfgCh()
).
MODBUS_ERR_SLAVE_ADDR
If the transmitted slave address doesn't correspond to the received slave address
MODBUS_ERR_DIAG
If you specified an invalid diagnostic function code (i.e. not one of the function described in the ‘fnc
t’ argument).
MODBUS_ERR_SUB_FNCT
If you specified an invalid sub-function.
Notes / Warnings
None
Called By
Your Modbus master application.