• 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

    How to cast BatchResults getValue(n) property to int in ModBus TCP/IP

    Modbus4J general discussion
    2
    3
    2.3k
    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.
    • L
      libu7alex
      last edited by

          BatchRead<Integer> batch = new BatchRead<Integer>();
          int add;
          int reg;
          int typ;
          add = FEOHdb.intDB[1][3];
         for (int m = 1 ; m < FEOHdb.tDev; m++){
      	   add = FEOHdb.intDB[m][3];
         
          for (int n = 1; n < FEOHdb.mapQty; n++ ){
          reg =FEOHdb.mapInt[n][1];
          typ =FEOHdb.mapInt[n][2];
         	batch.addLocator(n-1, BaseLocator.holdingRegister(add, reg, typ));
          }
      }
          
      
          try {
              master.init();
      
              while (pool) {
                  batch.setContiguousRequests(false);
                  BatchResults<Integer> results = master.send(batch);
                              
                  for (int n = 0; n < FEOHdb.mapQty; n++){ 
                  	System.out.println("Value =  " + (int) results.getValue(n));
                  }
                  Thread.sleep(500);
             
              }
      
      1 Reply Last reply Reply Quote 0
      • phildunlapP
        phildunlap
        last edited by

        Try casting it to java.lang.Number instead

        L 1 Reply Last reply Reply Quote 0
        • L
          libu7alex @phildunlap
          last edited by

          Thank you so much it works.

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