libmodbus icon indicating copy to clipboard operation
libmodbus copied to clipboard

libmodbus change needed for lua-libmodbus

Open woodsnake opened this issue 3 years ago • 1 comments

Hello stephane,

we need a additionally function in the libmodbus for lua-libmodbus. Can you add this in the origin code from you ?

https://github.com/woodsnake/libmodbus/blob/libmodbus-3.1.7.a/src/modbus.c

at Linie 245

int modbus_send_raw_response(modbus_t *ctx, uint8_t *req, const uint8_t *raw_resp, int raw_resp_length)
{
    sft_t sft;
    uint8_t resp[MAX_MESSAGE_LENGTH];
    int resp_length;
    int req_length;

    if (ctx == NULL) {
        errno = EINVAL;
        return -1;
    }

    if (raw_resp_length < 2 || raw_resp_length > (MODBUS_MAX_PDU_LENGTH + 1)) {
        /* The raw request must contain function and slave at least and
           must not be longer than the maximum pdu length plus the slave
           address. */
        errno = EINVAL;
        return -1;
    }

    sft.t_id = ctx->backend->prepare_response_tid(req, &req_length);
    sft.slave = raw_resp[0];
    sft.function = raw_resp[1];

    /* This response function only set the header so it's convenient here */
    resp_length = ctx->backend->build_response_basis(&sft, resp);

    if (raw_resp_length > 2) {
        /* Copy data after function code */
        memcpy(resp + resp_length, raw_resp + 2, raw_resp_length - 2);
        resp_length += raw_resp_length - 2;
    }

    return send_msg(ctx, resp, resp_length);
}

Thanks

woodsnake avatar Mar 16 '22 12:03 woodsnake

We require contributors to sign our Contributor License Agreement. In order for us to review and merge your code, please fill https://forms.gle/5635zjphDo5JEJQSA to get added. Your document will be manually checked by the maintainer. Be patient...

cla-bot[bot] avatar Mar 16 '22 12:03 cla-bot[bot]