MODBUS_REPORT_SLAVE_(3)

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

πŸ’– MODBUS_REPORT_SLAVE_ID πŸ’–

okay bestie, so this is a page from the libmodbus Manual and it's about modbus_report_slave_id β€” literally the function that goes "hey controller, who ARE you? describe yourself for me" ✨ and then writes the answer into your buffer. Let's get into it πŸ¦‹


🌸 NAME 🌸

modbus_report_slave_id β€” returns a description of the controller πŸ’…


✨ SYNOPSIS ✨

int modbus_report_slave_id(modbus_t *ctx, int max_dest, uint8_t *dest);

πŸ’œ DESCRIPTION πŸ’œ

So modbus_report_slave_id() sends a request over to the controller asking it to describe itself. That's it, that's the whole vibe. 🫢

The response lands in dest, and bestie, it's got a few things in it:

  • the slave ID β€” and here's the tea β˜•, this "unique" ID is in reality not unique at all, so you literally cannot depend on it to figure out how the information is packed in the response. Not even a little. πŸ™ˆ
  • the run indicator status (0x00 = OFF, 0xFF = ON) πŸ‘‘
  • additional data specific to each controller. For example, libmodbus returns the version of the library as a string. cute, right? πŸŽ€

The function writes at most max_dest bytes from the response into dest, so you must make sure dest is big enough. No cap, please check. πŸ’€


πŸ”₯ RETURN VALUE πŸ”₯

If everything's slaying, the function returns the number of read data. ✨

If the output got truncated because of the max_dest limit, then the return value is the number of bytes that would have been written to dest if enough space had been available. So if you get a return value greater than max_dest, that means the response data was truncated. Periodt. πŸ’…

Otherwise it returns -1 and sets errno. 😭


🌈 EXAMPLE 🌈

uint8_t tab_bytes[MODBUS_MAX_PDU_LENGTH];

...

rc = modbus_report_slave_id(ctx, MODBUS_MAX_PDU_LENGTH, tab_bytes);
if (rc > 1) {
    printf("Run Status Indicator: %s\n", tab_bytes[1] ? "ON" : "OFF");
}

πŸ‘‘ AUTHORS πŸ‘‘

The libmodbus documentation was written by Stéphane Raimbault <stephane.raimbault@gmail.com> 🫢


and that's the whole page bestie, you ate πŸ’– this was libmodbus v3.1.6, dated 11/17/2025, and it's giving main character energy from the MODBUS_REPORT_SLAVE_(3) page itself 🌸✨ mwah πŸ’…

πŸ“¦ where this page comes from