Hello:
I have an active TCP connection that has been verfied. When I run the code below I get a NullPointerException when calling trans.execute. Is there anyone that can tell me what I am doing wrong. Thanks in advance.
I propose you put the modbusSlaveException.printStackTrace() into the block of the ModbusSlaveException and the corresponding stack traces into the other two blocks to get more information on why the execute() fails.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have the same issue. I connected my TCPMasterConnection to the modbus TCP emulator (modsim32). If m_Transaction.setReconnecting(false); then m_Transaction.execute() throw java.lang.NullPointerException at com.ghgande.j2mod.modbus.io.ModbusTCPTransport.writeMessage(ModbusTCPTransport.java:151)
at com.ghgande.j2mod.modbus.io.ModbusTCPTransaction.execute(ModbusTCPTransaction.java:218)
The higher frequency of requests (lower delays in Thread.sleep() inside loop) - the fasters NullPointerException appears. But always in 1-5 seconds from start.
If m_Transaction.setReconnecting(true), then application create too many (over hundred) TCP-connetions in TIME_WAIT state. It's unacceptable in production, cause many of modbus-tcp slaves have limit of simultaneously incoming connection (max 16 connection in my case).
I need to request modbus-slaves several times in second.
How can I work around NullPointerException without hundreds of unclosed connection?
Last edit: Andrey Lavrukhin 2017-05-02
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello:
I have an active TCP connection that has been verfied. When I run the code below I get a NullPointerException when calling trans.execute. Is there anyone that can tell me what I am doing wrong. Thanks in advance.
public void readWriteTest(){
I propose you put the modbusSlaveException.printStackTrace() into the block of the ModbusSlaveException and the corresponding stack traces into the other two blocks to get more information on why the execute() fails.
I have the same issue. I connected my TCPMasterConnection to the modbus TCP emulator (modsim32). If
m_Transaction.setReconnecting(false)
; thenm_Transaction.execute()
throw java.lang.NullPointerException at com.ghgande.j2mod.modbus.io.ModbusTCPTransport.writeMessage(ModbusTCPTransport.java:151)at com.ghgande.j2mod.modbus.io.ModbusTCPTransaction.execute(ModbusTCPTransaction.java:218)
The higher frequency of requests (lower delays in Thread.sleep() inside loop) - the fasters NullPointerException appears. But always in 1-5 seconds from start.
If
m_Transaction.setReconnecting(true)
, then application create too many (over hundred) TCP-connetions in TIME_WAIT state. It's unacceptable in production, cause many of modbus-tcp slaves have limit of simultaneously incoming connection (max 16 connection in my case).I need to request modbus-slaves several times in second.
How can I work around NullPointerException without hundreds of unclosed connection?
Last edit: Andrey Lavrukhin 2017-05-02
This issue was on j2mod-1.06.
Found it solved in j2mod-2.3.3