• 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

    SetValue() and getValue() methods

    Modbus4J general discussion
    1
    2
    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.
    • P
      pfau
      last edited by

      I'm trying to read and write to a PLC via a gateway using modbus4j. I've gotten the read function to work, but I'm not getting anywhere on the setValue() method. I've tried various variations of this:

      
      IpParameters params = new IpParameters();
      params.setHost("192.168.0.100");
      params.setPort(502);
      
      //create modbus TCP master
      ModbusMaster master = new ModbusFactory().createTcpMaster(params, false);
      master.init();
      
      int regValue=0;
      regValue = regValue | 1 << 0;
      ModbusLocator loc0 = new ModbusLocator(1,RegisterRange.HOLDING_REGISTER,0,DataType.TWO_BYTE_INT_UNSIGNED);
      master.setValue(loc0,8);
      
      

      Also the getValue() method only works sporadically maybe 30% of the time I call getValue() I get the response I expect, and the other times I get all 0s out.

      System.out.println(master.getValue(33,RegisterRange.HOLDING_REGISTER,70,2));
      

      Am I misunderstanding some aspect of the get and set value methods? Thanks.

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