I was getting a Null Pointer Exception when the ModbusTCP Slave was not connected.
I had to modify ModbusTCPTransaction.java
Changed line 201
From: while (retryCounter < (m_Retries > 0 ? m_Retries:1)) {
To: while (retryCounter <= (m_Retries > 0 ? m_Retries:1)) {
So the ModbusIOException would be caught and not allow code to proceed to
line 254 "if (isCheckingValidity())" where the Null Pointer Exception was thrown.
Thanks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The solution I found previously was to protect the call to checkValidity() by verifying that message pointer was non-null.
You also found an issue with the original design in that there are off-by-one errors. m_Retries is initialized to 0. If you use "retryCounter <= (m_Retries > 0 ? m_Retries:1)" to terminate the loop, you will always get one more retry than you requested. The better solution is to fix the off-by-one problems.
I'll get that code change made and move the status to "Production" from beta once I get a new set of JAR files uploaded.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I was getting a Null Pointer Exception when the ModbusTCP Slave was not connected.
I had to modify ModbusTCPTransaction.java
Changed line 201
From: while (retryCounter < (m_Retries > 0 ? m_Retries:1)) {
To: while (retryCounter <= (m_Retries > 0 ? m_Retries:1)) {
So the ModbusIOException would be caught and not allow code to proceed to
line 254 "if (isCheckingValidity())" where the Null Pointer Exception was thrown.
Thanks
Ed,
The solution I found previously was to protect the call to checkValidity() by verifying that message pointer was non-null.
You also found an issue with the original design in that there are off-by-one errors. m_Retries is initialized to 0. If you use "retryCounter <= (m_Retries > 0 ? m_Retries:1)" to terminate the loop, you will always get one more retry than you requested. The better solution is to fix the off-by-one problems.
I'll get that code change made and move the status to "Production" from beta once I get a new set of JAR files uploaded.