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
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login