Modbus Function 7 Read Exception Status

220 views
Skip to first unread message

Amine

unread,
Dec 17, 2021, 4:31:20 PM12/17/21
to libmodbus
Hi,

Does Modbus provide functions to handle Modbus function number 7 (read exception status) ?

I have a flowmeter that uses this function. I quote :

"The Read Exception Status command (function code 07) returns the exception status byte, which is defined as follows. This byte may be cleared by setting “coil” register #00003 (function code 5, address 2, data = 0xff00).

Bit(s) Definition
0-1 Byte order (see Modbus Order on page 2)
0 = 3-2:1-0 1 = 2-3:0-1
2 = 1-0:3-2 3 = 0-1:2-3
2 Temperature sensor fault
3 Pressure sensor fault
4 A/D converter fault
5 Period overflow
6 Pulse overflow
7 Configuration changed
"

I will code the feature if it doesn't exist and send a pull request.

Thank you.

Amine

unread,
Feb 11, 2022, 11:01:05 AM2/11/22
to libmodbus
Up

Amine

unread,
Mar 7, 2022, 5:14:52 AM3/7/22
to libmodbus
Re-Up

Amine

unread,
Mar 25, 2022, 6:08:03 AM3/25/22
to libmodbus
Can anyone give me any information about this?

Thank you.

Amine

unread,
Mar 25, 2022, 2:45:20 PM3/25/22
to libmodbus

Amine

unread,
Mar 28, 2022, 8:42:03 AM3/28/22
to libmodbus
I share with you my solution based on the examples I found in the documentation, I haven't tested it yet :

bool ModbusMaster::ReadExceptionStatus(const int slaveAddr, uint8_t& statusByte) const
{
    if (modbus_set_slave(m_Internals->Ctx, slaveAddr) != 0)
    {
        m_Internals->LastErrorCode = errno;
        return false;
    }

    const int reqSize = 2;
    uint8_t rawReq[reqSize] = { slaveAddr, MODBUS_FC_READ_EXCEPTION_STATUS };

    const int ret = modbus_send_raw_request(m_Internals->Ctx, rawReq, reqSize * sizeof(uint8_t));
    if (ret > 0)
    {
        uint8_t rsp[MODBUS_MAX_ADU_LENGTH];
        const int rspLen = modbus_receive_confirmation(m_Internals->Ctx, rsp);
        if (rspLen >= 3 && rsp[0] == slaveAddr && rsp[1] == MODBUS_FC_READ_EXCEPTION_STATUS)
        {
            statusByte = rsp[2];
            return true;
        }
        else
        {
            m_Internals->LastErrorCode = errno;
            return false;
        }
    }
    else
    {
        m_Internals->LastErrorCode = errno;
        return false;
    }
}
Reply all
Reply to author
Forward
0 new messages