Menu

Null Pointer Exception - ModbusTCP Master

ed nelson
2013-04-12
2013-04-14
  • ed nelson

    ed nelson - 2013-04-12

    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

     
  • Julie Haugh

    Julie Haugh - 2013-04-14

    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.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.