-1
\$\begingroup\$

I am using libmodbus to connect to the a SunnyBoy 2.5 inverter. I make the connection as follows:

#include <modbus/modbus.h>
#include <stdio.h>
#include <errno.h>

int main()
{
    modbus_t *mb;
    uint16_t tab_reg[32];
    int rc;
    int socket;

    mb = modbus_new_tcp("192.168.100.1", 502);
    if (mb == NULL)
    {
        fprintf(stderr, "Unable to allocate libmodbus context\n.");
        return -1;
    }

    if (modbus_connect(mb) == -1)
    {
        fprintf(stderr, "Connection failed: %s\n",
                modbus_strerror(errno));
        modbus_free(mb);
        return -1;
    }
    else
    {
        socket = modbus_tcp_listen(mb, 1);
        if (socket == -1)
        {
            fprintf(stderr, "Socket problem: %s\n", modbus_strerror(errno));
        }
        modbus_tcp_accept(mb, &socket);
        printf("Connection successful.\n");
    }
}

When I attempt to listen on the socket (modbus_tcp_listen), it gives me a "permission denied" error. How does one gain permission to the SunnyBoy to talk Modbus to it / how do you implement that in the code?

\$\endgroup\$
  • 1
    \$\begingroup\$ Do you think that lot of people on this forum know about libmodbus library and your platform (that you didn't describe) to help you? Further, a modbus is a protocol of numbers, so where did you get the "permisson denied" as the modbus hasn't this feature. \$\endgroup\$ – Marko Buršič Feb 29 '16 at 9:26
  • \$\begingroup\$ What does the manual for the device say? \$\endgroup\$ – Nick Alexeev Feb 29 '16 at 19:31
1
\$\begingroup\$

You're getting this message because modbus uses port 502. In Unix port numbers below 1024 require root access, so try using

sudo bash

To get a root shell and give it a try. You'd also be better off using a scripting language that has a modbus library. This will let you produce fast prototypes with your Sunny Boy.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.