MODBUS_SEND_RAW_REQU(3)
π modbus_send_raw_request β the libmodbus manual, but make it make sense π
okay bestie, welcome to the libmodbus manual page for modbus_send_raw_request, page MODBUS_SEND_RAW_REQU(3). yeah the title got cut off, that's just how manpages do, it's giving βοΈ energy. let's get into it π¦
β¨ NAME β¨
modbus_send_raw_request β bestie, it sends a raw request π
β¨ SYNOPSIS β¨
int modbus_send_raw_request(modbus_t *ctx, const uint8_t *raw_req, int
raw_req_length);
that's the whole vibe right there π
β¨ DESCRIPTION β¨
so modbus_send_raw_request() shall send a request through the socket of the context ctx. that's the job. that's what it does π«Ά
π¨ real talk though: this function must be used for debugging purposes because you have to take care to make a valid request by hand. it's not doing the thinking for you, bestie, you're the main character here π
here's the thing: the function only adds to the message the header or CRC of the selected backend. that's it. nothing else. so raw_req must start with β and contain at least β a slave/unit identifier and a function code. no skipping, no shortcuts πΈ
also? this function can be used to send requests that aren't handled by the library at all. it's the flexible one. it's giving "I got you, do your thing" π
and the public header of libmodbus provides a list of supported Modbus function codes, prefixed by MODBUS_FC_ (eg. MODBUS_FC_READ_HOLDING_REGISTERS), to help build those raw requests. use them, they're iconic β
β¨ RETURN VALUE β¨
if it works, the function shall return the full message length, counting the extra data relating to the backend. that's your win π
otherwise? it shall return -1 and set errno. sad girl hours, check your errno π
β¨ EXAMPLE β¨
here's the whole thing, verbatim, no notes π
modbus_t *ctx;
/* Read 5 holding registers from address 1 */
uint8_t raw_req[] = { 0xFF, MODBUS_FC_READ_HOLDING_REGISTERS, 0x00, 0x01, 0x0, 0x05 };
int req_length;
uint8_t rsp[MODBUS_TCP_MAX_ADU_LENGTH];
ctx = modbus_new_tcp("127.0.0.1", 1502);
if (modbus_connect(ctx) == -1) {
fprintf(stderr, "Connection failed: %s\n", modbus_strerror(errno));
modbus_free(ctx);
return -1;
}
req_length = modbus_send_raw_request(ctx, raw_req, 6 * sizeof(uint8_t));
modbus_receive_confirmation(ctx, rsp);
modbus_close(ctx);
modbus_free(ctx);
see how the raw request is built by hand? yeah. that's the whole point. handcrafted. artisanal. like you π§
β¨ SEE ALSO β¨
modbus_receive_confirmation(3)β go read it, bestie, they're a package deal π₯
β¨ AUTHORS β¨
the libmodbus documentation was written by StΓ©phane Raimbault <stephane.raimbault@gmail.com> π
and that's the whole page, bestie!! this one's from libmodbus v3.1.6, dated 11/17/2025 π go forth and send some valid-by-hand requests, no cap π«Άβ¨πΈ
π¦ where this page comes from
- debian bookworm: libmodbus-dev 3.1.6-2.1+deb12u1 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms