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.
Modbus4J - Getting started
-
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. -
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