Search code examples
cembeddedmodbus

libmodbus : Unable to Poll modbus energy meter having stop bit as 2


I am trying to poll n schneider Energymeter in having parity as none and stop bit as 2 using a RS485 to USB converter. I am getting connection timed out error. But when I try to poll the same meter with parity as none and stopbit as 1, I am able to receive the data.

The code snippet I am using to poll the meter is as follows

     ctx = modbus_new_rtu("/dev/ttyUSB0",9600, 'N', 8, 2);
     modbus_set_debug(ctx, TRUE);
      if (modbus_connect(ctx) == -1) {
           printf("Modbus Connection failed: %s", modbus_strerror(errno));
           modbus_free(ctx);
           return -1;
      }
      modbus_set_slave(ctx,2);
      memset(tab_rp_registers, 0, 2 * sizeof(uint16_t));
      rc = modbus_read_registers(ctx,3109,2,tab_rp_registers);
      modbus_close(ctx);
      modbus_free(ctx);
      if (rc != -1) {
      // actions performed

      }
      else {
      free(tab_rp_registers);
      printf("Error str is %s\n",modbus_strerror(errno));
       }

Always I am getting the rc as -1 and the Connection timed out error when converting the errno.

Am I missing anything ?


Solution

  • Issue resolved on updating the library to 3.1.4.