MODBUS_CLOSE(3)

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

πŸ’– MODBUS_CLOSE πŸ’–

okay bestie, gather round, because today we're learning how to say bye to a Modbus connection the polite way πŸŽ€ this one lives in the libmodbus Manual, and it is genuinely the easiest page in the whole library. no cap. it's giving "one job, done perfectly" energy πŸ‘‘


🌸 NAME 🌸

modbus_close β€” close a Modbus connection


✨ SYNOPSIS ✨

void modbus_close(modbus_t *ctx);

πŸ¦‹ DESCRIPTION πŸ¦‹

so like. the modbus_close() function shall close the connection that was established with the backend set in the context. that's it. that's the whole vibe. you connected, you did your thing, now you're closing the door behind you like the main character you are πŸ’…


πŸ’œ RETURN VALUE πŸ’œ

there is no return value. none. zero. nada. it's a void function, she doesn't gossip back to you, she just does 🫢


🌈 EXAMPLE 🌈

here's the whole glow-up arc in code form, bestie β€” connect, check, close, free, periodt:

    modbus_t *ctx;

    ctx = modbus_new_tcp("127.0.0.1", 502);
    if (modbus_connect(ctx) == -1) {
        fprintf(stderr, "Connection failed: %s\n", modbus_strerror(errno));
        modbus_free(ctx);
        return -1;
    }

    modbus_close(ctx);
    modbus_free(ctx);

see how she closes ctx and then frees it? iconic behavior. do not skip steps πŸ“


πŸ‘‘ SEE ALSO πŸ‘‘

(the prequel to this masterpiece, fr fr)


πŸ’– AUTHORS πŸ’–

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


ok that's the whole page, you're officially a modbus_close expert now, no notes πŸ’€βœ¨

and for the credits roll at the very end: this lil beauty is libmodbus v3.1.6, dated 11/17/2025. slay, bye bestie!! πŸŽ€πŸ¦‹πŸ’œ

πŸ“¦ where this page comes from