Closed Ahmid closed 7 years ago
It's not clear from your code if the exception is because RCres is null or the result of RCres.getCoils(). Could you tell me which it is? Also, can you turn on debug logging to see why an exception is not being thrown for an empty response.
It has been 2 months and nobody else has reported an issue so I'm closing this ticket
Hello,
Simply, I am running Modbuspal.java on a windows machine, where I have created a slave and filled some coils and registers.
Then from the same windows machine, I used j2mod in order to read coils/registers, the operation wen successfully.
The problem is that when I ran the same code on a linux (ubuntu) virtual machine, a null pointer exception is being released everytime, the connection phase is succeeding, but the reading is not.
The code is:
import java.net.InetAddress; import java.util.logging.Level; import java.util.logging.Logger;
import com.ghgande.j2mod.modbus.Modbus; import com.ghgande.j2mod.modbus.ModbusException; import com.ghgande.j2mod.modbus.io.ModbusTCPTransaction; import com.ghgande.j2mod.modbus.msg.ReadCoilsRequest; import com.ghgande.j2mod.modbus.msg.ReadCoilsResponse; import com.ghgande.j2mod.modbus.msg.ReadInputDiscretesRequest; import com.ghgande.j2mod.modbus.msg.ReadInputDiscretesResponse; import com.ghgande.j2mod.modbus.msg.ReadMultipleRegistersRequest; import com.ghgande.j2mod.modbus.msg.ReadMultipleRegistersResponse; import com.ghgande.j2mod.modbus.net.TCPMasterConnection;
//Process public class ModbusTest {
}
The error is in the line: System.out.println("The value READ (coils): " + RCres.getCoils().toString());
Connected to = /130.190.97.101 true /Start Register 1 Apr 19, 2017 2:55:16 AM ModbusTest main SEVERE: null java.lang.NullPointerException at ModbusTest.main(ModbusTest.java:62)