• Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Neuron M203/How to read DI?

    UniPi 1 - HW Q&A
    2
    2
    1151
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      Massimogai last edited by tomas_hora

      Hello,
      last week I bought a M203. I would like to read the digital inputs with the MODBUS protocol. I tried to use the neuron_tcp_modbus_server with libmodbus but the results are wrong, they change at every reading. Here my code:

          mb = modbus_new_tcp("192.1681.1.102", 502);
          //modbus_set_slave(mb, 2);
          modbus_connect(mb);
      
          /* Read 16  bit sfrom the address 0 */
          modbus_read_bits(mb, 0, 16, tab_reg);
        
          modbus_close(mb);
          modbus_free(mb);
          for (int i = 0; i < 16; i++) {
          std::cout << static_cast<uint8_t>(tab_reg[i]) << std::flush;
          std::cout <<",";
          }
      

      Any suggestions?
      Thanks.

      1 Reply Last reply Reply Quote 0
      • T
        tomas_hora administrators last edited by

        Hello,

        make sure set the slave to 2 as you had. Also double check the documentation, coils for DI using slave 2 are from coil 14 up to 29. You are reading coils 0-15.

        Br,
        Tomas

        1 Reply Last reply Reply Quote 0
        • First post
          Last post