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.
StreamTransport null pointer exception
-
I have been trying to implement a RTU slave application, I used the ListenerTest as a start with the necessary modifications to make it create a RTU slave instead of the TCP slave. However when I try to run it I get a NullPointerException at the SteamTransporter.
run: Stable Library ========================================= Native lib Version = RXTX-2.1-7 Java lib Version = RXTX-2.1-7 com.serotonin.modbus4j.exception.ModbusInitException: java.lang.NullPointerException at com.serotonin.modbus4j.serial.SerialSlave.start(SerialSlave.java:51) at com.serotonin.modbus4j.serial.rtu.RtuSlave.start(RtuSlave.java:40) at kiwi.main$1.run(main.java:46) at java.lang.Thread.run(Thread.java:662) Caused by: java.lang.NullPointerException at com.serotonin.messaging.StreamTransport.start(StreamTransport.java:32) at com.serotonin.modbus4j.serial.SerialSlave.start(SerialSlave.java:48) ... 3 more
I looked through the examples but couldn't find any that were very relevant except the listener one. Google didn't really turn up anything useful either. When I looked closer at the code I figured it might be something up with the name being passed to StreamTransport and fetched the thread and got it's name and passed that as a variable instead. That didn't make any difference though.
Thanks in advance, hope I didn't miss anything painfully obvious :)
-
There is a line in SerialSlave that should be removed.
try { serialPort = SerialUtils.openSerialPort(serialParameters); transport = new StreamTransport(serialPort.getInputStream(), serialPort.getOutputStream()); transport.start("Modbus4J SerialSlave"); // <<< REMOVE THIS LINE }
The start method should be (and is) called in subclasses. I'm pretty sure this will fix the problem, but i don't have any equipment available to test on. Please let me know if it helps.
-
I've just come across this error from 2011 and I only downloaded the code a few days ago.
Why was this error still present in the code?
Anyway, the fix sorted the issue and I now have a working RTU slave.
-
I looked through the examples but couldn't find any that were very relevant except the listener one. Google didn't really turn up anything useful either. When I looked closer at the code I figured it might be something up with the name being passed to StreamTransport and fetched the thread and got it's name and passed that as a variable instead. That didn't make any difference though.
-
The line is not in the CVS code. Perhaps it still is in the src jar file. Try using the repo source instead.