MODBUS_REPLY_EXCEPTI(3)

πŸ“¦
version 3.1.6 Β· 3 versions
, in debian bookworm

✨ MODBUS_REPLY_EXCEPTI ✨

okay bestie, pull up a chair, we're diving into libmodbus's modbus_reply_exception πŸ’– this one lives in section 3 of the manual and it's genuinely so useful, no cap.


🌸 NAME 🌸

modbus_reply_exception β€” bestie, this thing sends an exception response πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

int modbus_reply_exception(modbus_t *ctx, const uint8_t *req, unsigned
int exception_code);

πŸ¦‹ DESCRIPTION πŸ¦‹

so like, the modbus_reply_exception() function shall send an exception response based on the exception_code you hand it in the argument. that's the whole vibe. you give it a code, it throws that exception back at whoever asked. iconic behavior honestly ✨

libmodbus comes stocked with these exception codes, and you will be using them:

  • MODBUS_EXCEPTION_ILLEGAL_FUNCTION (1)
  • MODBUS_EXCEPTION_ILLEGAL_DATA_ADDRESS (2)
  • MODBUS_EXCEPTION_ILLEGAL_DATA_VALUE (3)
  • MODBUS_EXCEPTION_SLAVE_OR_SERVER_FAILURE (4)
  • MODBUS_EXCEPTION_ACKNOWLEDGE (5)
  • MODBUS_EXCEPTION_SLAVE_OR_SERVER_BUSY (6)
  • MODBUS_EXCEPTION_NEGATIVE_ACKNOWLEDGE (7)
  • MODBUS_EXCEPTION_MEMORY_PARITY (8)
  • MODBUS_EXCEPTION_NOT_DEFINED (9)
  • MODBUS_EXCEPTION_GATEWAY_PATH (10)
  • MODBUS_EXCEPTION_GATEWAY_TARGET (11)

also, lowkey important: the initial request req is required to build a valid response. like, you literally cannot skip it. no req, no response, that's the rule 🫢


πŸ’œ RETURN VALUE πŸ’œ

if everything slays? the function shall return the length of the response sent β€” that's your success signal, periodt πŸ‘‘

but if it doesn't work out? it shall return -1 and set errno. not the vibe, but at least you know why 😭


πŸ’€ ERRORS πŸ’€

  • EINVAL β€” the exception code is invalid. bestie. the code. it's not a real one. check yourself πŸ™ˆ

🌈 SEE ALSO 🌈


πŸ‘‘ AUTHORS πŸ‘‘

the libmodbus documentation was written by StΓ©phane Raimbault <stephane.raimbault@gmail.com> β€” absolute legend, we stan 🫢


and that's the whole page bestie!! this was libmodbus v3.1.6, dated 11/17/2025 β€” go forth and handle your exceptions responsibly πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from