<?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 throwing error.]]></title><description><![CDATA[<p dir="auto">I've tested this code to detect a Modbus device ( was discovered by a discovery software) connected to my computer.<br />
but the code throw a <strong>null pointer Exception,</strong> can someone help me understand it.</p>
<p dir="auto">public class MasterTest {<br />
public static void main(String[] args) throws Exception {</p>
<pre><code>	String commPortId = "/dev/ttyUSB0";
	int baudRate = 9600;
	int flowControlIn = 0;
	int flowControlOut = 0;
	int dataBits = 0;
	int stopBits = 0;
	int parity = 1;
	
	TestSerialPortWrapper wrapper = new TestSerialPortWrapper(commPortId, baudRate, flowControlIn, flowControlOut, dataBits, stopBits, parity);
    
    IpParameters ipParameters = new IpParameters();
    ipParameters.setHost("localhost");

    ModbusFactory modbusFactory = new ModbusFactory();

     ModbusMaster master = modbusFactory.createRtuMaster(wrapper);
    try {
        master.setTimeout(1000);
        master.setRetries(0);
        master.init();
        int slaveId = 2;
      BaseLocator&lt;Number&gt; locator = BaseLocator.holdingRegister(slaveId, 50, DataType.EIGHT_BYTE_INT_UNSIGNED);
        master.setValue(locator, 10000000);
        System.out.println(master.getValue(locator));
    }
    finally {
        master.destroy();
    }
}
</code></pre>
]]></description><link>https://forum.mango-os.com/topic/4232/modbus4j-throwing-error</link><generator>RSS for Node</generator><lastBuildDate>Sun, 19 Apr 2026 12:09:00 GMT</lastBuildDate><atom:link href="https://forum.mango-os.com/topic/4232.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 29 May 2019 08:34:07 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Modbus4J throwing error. on Mon, 03 Jun 2019 17:21:11 GMT]]></title><description><![CDATA[<p dir="auto">The most proactive thing you could do for the issue of the null pointer is perhaps to fork the repository, implement some tests that use input and output streams, finish the TestSerialPortWrapper class, and submit a pull request.</p>
<p dir="auto">But, if you're trying to talk to an actual device and not simply playing with the test code, then perhaps you are wanting to use your own implementing class of SerialPortWrapper which presents the input and output streams of your serial port in the methods that return null in the test class.</p>
<p dir="auto">In Mango, our Modbus module makes a call to the SerialPortManager to get a proxy, and then returns the input stream and output stream from the proxy.</p>
<p dir="auto"><a href="https://github.com/infiniteautomation/ma-core-public/blob/main/Core/src/com/infiniteautomation/mango/io/serial/SerialPortManagerImpl.java#L205" rel="nofollow ugc">https://github.com/infiniteautomation/ma-core-public/blob/main/Core/src/com/infiniteautomation/mango/io/serial/SerialPortManagerImpl.java#L205</a><br />
returns<br />
<a href="https://github.com/infiniteautomation/ma-core-public/blob/main/Core/src/com/infiniteautomation/mango/io/serial/JsscSerialPortProxy.java" rel="nofollow ugc">https://github.com/infiniteautomation/ma-core-public/blob/main/Core/src/com/infiniteautomation/mango/io/serial/JsscSerialPortProxy.java</a><br />
for non-virtual serial ports in Mango, which uses Jssc to actually handle the serial nitty-gritty.</p>
]]></description><link>https://forum.mango-os.com/post/22289</link><guid isPermaLink="true">https://forum.mango-os.com/post/22289</guid><dc:creator><![CDATA[phildunlap]]></dc:creator><pubDate>Mon, 03 Jun 2019 17:21:11 GMT</pubDate></item><item><title><![CDATA[Reply to Modbus4J throwing error. on Mon, 03 Jun 2019 12:08:41 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/phildunlap" aria-label="Profile: phildunlap">@<bdi>phildunlap</bdi></a> OMG thanks, but how can we fix this?</p>
]]></description><link>https://forum.mango-os.com/post/22285</link><guid isPermaLink="true">https://forum.mango-os.com/post/22285</guid><dc:creator><![CDATA[vijay chelliah]]></dc:creator><pubDate>Mon, 03 Jun 2019 12:08:41 GMT</pubDate></item><item><title><![CDATA[Reply to Modbus4J throwing error. on Wed, 29 May 2019 13:00:28 GMT]]></title><description><![CDATA[<p dir="auto">Hi vijay,</p>
<p dir="auto">Any chance you read line 14 of TestSerialPortWrapper?</p>
<pre><code>/*
 * This class is not finished
 */
</code></pre>
]]></description><link>https://forum.mango-os.com/post/22265</link><guid isPermaLink="true">https://forum.mango-os.com/post/22265</guid><dc:creator><![CDATA[phildunlap]]></dc:creator><pubDate>Wed, 29 May 2019 13:00:28 GMT</pubDate></item><item><title><![CDATA[Reply to Modbus4J throwing error. on Wed, 29 May 2019 12:20:33 GMT]]></title><description><![CDATA[<p dir="auto">wrapper.getInputStream is  returning null.</p>
]]></description><link>https://forum.mango-os.com/post/22260</link><guid isPermaLink="true">https://forum.mango-os.com/post/22260</guid><dc:creator><![CDATA[vijay chelliah]]></dc:creator><pubDate>Wed, 29 May 2019 12:20:33 GMT</pubDate></item></channel></rss>