Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libmodbus change needed for lua-libmodbus #635

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

woodsnake
Copy link

@woodsnake woodsnake commented Mar 16, 2022

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

@cla-bot
Copy link

cla-bot bot commented Mar 16, 2022

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...

Copy link
Owner

@stephane stephane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense.
Could you call the function in the unit tests and provide the documentation, please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants