Mango uses Modbus4J in 1000's of applications around the world. It is a well used and full-featured library. You won't see much development activity on it since it has been very stable for a long time.
Modbus does not provide a built-in way of detecting slaves. So to do what you want to do would need to be a hack or workaround...Such as polling each slave, if there is a response from that slaveId even if it is an error code such as "illegal address", then there is probably a slave of that ID ??
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.
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.
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.
What happens if you use Mango's tools on the Modbus Data Source page to read these registers? Do you get better feedback, or output to the log file? The point locator test tool uses the same method you are using.
Can you attach a debugger? Modbus4J is open source and as far as gaining knowledge in Java goes, you should be able to attach a debugger in your IDE and step into the code.
Get a log4j configuration that will output the various log statements from TcpMaster and pass that into your program as a command line argument.
So, you're requesting the same register over some period of time, and it never errors but the value is usually what you would expect for the kWh and occasionally what you expect for the instantaneous voltage? That's bizarre. I would set up a Mango reading that register for a while to be sure that is what is going on (you make it sounds as though you are using Modbus4J in your own application), but that sounds like an issue with the PLC. If you're requesting the same range of values and it is spontaneously changing those values, that is its issue.
It should be the same process as any other Java project or regular JAR. I've never used Android studio personally though, so i can't give you specific instruction. I bet "import jar android studio" gets usable search results from elsewhere on the web. The github project is here: https://github.com/infiniteautomation/modbus4j
ReadSerialTest throws a null pointer because TestSerialPortWrapper returns nulls for its input and output streams. That looks like a bug in the test, and shouldn't affect the larger issue you seem to be asking about, so,
I believe you're writing code to use Modbus4J? We offer limited free support for this.
You are providing the SerialPortWrapper to the Modbus master you're creating an instance of, correct? If so you should set a breakpoint in your serial port wrapper and see what happens in the serial library you're wrapping for the 232 setup you're testing when it tries to get the input or output stream from your wrapper.