ERROR Connection reset by peer: read

83 views
Skip to first unread message

JS

unread,
Oct 1, 2015, 6:09:02 PM10/1/15
to libmodbus
Hi,
I have been trying to read a IME NEMO 96 using the modbus library libmodbus dev latest version under Ubuntu 14.04 LTS. The same hardware works under windows 7. Please see the code below when it trys to execute modbus_read_registers I get the error message shown, where should I start looking? I have checked with a null modem cable and it is sending the data from the PC

Opening /dev/ttyS5 at 19200 bauds (N, 8, 1)
[01][03][10][00][00][02][C0][CB]
Waiting for a confirmation...
ERROR Connection reset by peer: read
Connection reset by peer


int main(void) {
     meter_data_str_t meter_value_data_v;
     meter_status_str_t meter_status_v;
     meter_value_data_reset (&meter_value_data_v);
     meter_status_data_reset (&meter_status_v);

    int return_val;
    struct timeval response_timeout;
    u_int16_t data_rx [123];

    modbus_t *ctx;
    response_timeout.tv_sec = 1;

    ctx = modbus_new_rtu("/dev/ttyS5", 19200, 'N', 8, 1);
    if (ctx == NULL) {
        fprintf(stderr, "Unable to create the libmodbus context\n");
        return -1;
    }
    modbus_set_debug(ctx, TRUE);
    modbus_set_response_timeout(ctx,&response_timeout);
    return_val =  modbus_set_slave( ctx, MODBUS_SLAVE_NUM_C);
    if (return_val  == -1) {
        fprintf(stderr, "Unable to set modbus slave \n");
        return -1;
    }
    if (modbus_connect(ctx) == -1) {
        fprintf(stderr, "Connection failed: %s\n", modbus_strerror(errno));
        modbus_free(ctx);
        return -1;
    }



    return_val =  modbus_read_registers(ctx,0x1000,2, data_rx);
    if (return_val  == -1) {
        fprintf(stderr, "%s\n", modbus_strerror(errno));
        return -1;
    }
    modbus_close(ctx);
    modbus_free(ctx);
    return EXIT_SUCCESS;
}

Reply all
Reply to author
Forward
0 new messages