<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Modbus4J - Getting started]]></title><description><![CDATA[<p dir="auto">Hello,<br />
I've evaluated <a href="http://jamod.sourceforge.net/" rel="nofollow ugc">Jamod </a> 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.<br />
In Jamod, this looks something like (and I'm new to it):</p>
<pre><code>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();
    }
}
</code></pre>
<p dir="auto">thanks,<br />
-adaf.</p>
]]></description><link>https://forum.mango-os.com/topic/2000/modbus4j-getting-started</link><generator>RSS for Node</generator><lastBuildDate>Sat, 11 Apr 2026 13:57:35 GMT</lastBuildDate><atom:link href="https://forum.mango-os.com/topic/2000.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 25 Oct 2015 16:46:36 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Modbus4J - Getting started on Mon, 26 Oct 2015 00:36:48 GMT]]></title><description><![CDATA[<p dir="auto">Hi Adaf/Asaf</p>
<p dir="auto">There are some snippets from another user in this thread that might help:<br />
<a href="http://infiniteautomation.com/forum/topic/1969/modbus4j-modbus-rtu-master/8" rel="nofollow ugc">http://infiniteautomation.com/forum/topic/1969/modbus4j-modbus-rtu-master/8</a></p>
]]></description><link>https://forum.mango-os.com/post/10488</link><guid isPermaLink="true">https://forum.mango-os.com/post/10488</guid><dc:creator><![CDATA[jeremyh]]></dc:creator><pubDate>Mon, 26 Oct 2015 00:36:48 GMT</pubDate></item></channel></rss>