• 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

    Modbus4J - Getting started

    Modbus4J general discussion
    2
    2
    2.7k
    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.
    • A
      adaf
      last edited by adaf

      Hello,
      I've evaluated Jamod and would like to evaluate and compare Modbus4J. Is there a "Getting Started" page? Some usage examples? I'm looking for a simple TCP/IP master code that runs function '2' to retrieve the value of a single bit from a given ip:port.
      In Jamod, this looks something like (and I'm new to it):

      private void qTest() throws Exception {
      
          // Build a connection
          TCPMasterConnection con = new TCPMasterConnection(InetAddress.getByName(slaveIPAddr));
          try {
              con.setPort(slavePort);
              con.connect();  // may throw an exception
      
              // Prepare a request
              final int bitIndex2read = 3;
              final int numBits2Read = 6;
              ReadInputDiscretesRequest request = new ReadInputDiscretesRequest(/*refRegister=*/0, numBits2Read);
      
              // Run a transaction (you can run as many as you like until you close the connection)
              ModbusTCPTransaction transaction = new ModbusTCPTransaction(con);
              transaction.setRequest(request);
      
              try {
                  transaction.execute();
              } catch (ModbusSlaveException e) {
                  System.out.println("Got a Modbus error response with code "+e.getType());
                  e.printStackTrace();
              }
      
              // Parse response
              ReadInputDiscretesResponse response = (ReadInputDiscretesResponse)transaction.getResponse();
              boolean isOn = response.getDiscreteStatus(bitIndex2read);
              System.out.println("Digital Input @" + bitIndex2read + " is " + (isOn ? "On." : "Off."));
          } finally {
              //6. Close the connection
              con.close();
          }
      }
      

      thanks,
      -adaf.

      1 Reply Last reply Reply Quote 0
      • jeremyhJ
        jeremyh
        last edited by

        Hi Adaf/Asaf

        There are some snippets from another user in this thread that might help:
        http://infiniteautomation.com/forum/topic/1969/modbus4j-modbus-rtu-master/8

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