• Recent
    • Tags
    • Popular
    • Register
    • Login

    Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.

    Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website Mango 5 Documentation Website

    Multiple register writes

    Modbus4J general discussion
    3
    6
    5.4k
    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.
    • V
      v8dave
      last edited by

      I saw a few postings about this here but no answers.

      I have a server listening for Modbus connections and I have about 20 sequential registers I would like to write to and also read back 10 registers.

      As this will be over a GPRS connection, I would like to keep the number of bytes down and the present way of using a setValue for each register consumes too much data.

      I see there is a reference in the forum to sendBatch but this function doesn't exist in the code I downloaded.

      Modbus supports multiple reads and writes but this seems to be missing from the Modbus4j code or am I missing something?

      How do I go about writing and reading to and from multiple registers.

      1 Reply Last reply Reply Quote 0
      • V
        v8dave
        last edited by

        I got it working.

        For anyone else, have a look at WriteRegistersRequest.

        1 Reply Last reply Reply Quote 0
        • N
          nikorun
          last edited by

          Hello v8dave,

          oour needs are exactly opposites : I want to write a single register (function 0x06) and my Mango instance only write multiple registers (0x16) and you want to writemultiple registers and your mango only writes one by one !!!

          :-)

          happy that ou found the solution but by the way how did you manage to write a single register ???

          1 Reply Last reply Reply Quote 0
          • V
            v8dave
            last edited by

            @nikorun said:

            Hello v8dave,
            happy that ou found the solution but by the way how did you manage to write a single register ???

            I just used the setValue() call. It takes a single value and writes this to the register. eg,

            
                master.setValue(1, RegisterRange.INPUT_REGISTER, 0, DataType.TWO_BYTE_INT_SIGNED, value);
            
            

            I think you'll find that it uses 16 because it handles other sizes of data. Eg, FOUR_BYTE_INT_SIGNED would write out to 2 registers but it would handle the Endian support for you. You would only have to worry about writing the value and not have to consider breaking the 32 bit value into 2 16 bit values. The library takes care of this for you.

            The issue with this is if the Modbus device you have does not support function 16. You could modify the library to use function 6 if the value being written was of the 2 byte types. The source is there so this is very possible.

            B 1 Reply Last reply Reply Quote 0
            • B
              bkm @v8dave
              last edited by

              @nikorun
              where this master.setValue
              (...) line should be added ?

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