• Recent
    • Tags
    • Popular
    • Register
    • Login

    Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.

    Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website Mango 5 Documentation Website

    StreamTransport null pointer exception

    Modbus4J general discussion
    4
    6
    4.4k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K
      kelden
      last edited by

      I have been trying to implement a RTU slave application, I used the ListenerTest as a start with the necessary modifications to make it create a RTU slave instead of the TCP slave. However when I try to run it I get a NullPointerException at the SteamTransporter.

      
      run:
      Stable Library
      =========================================
      Native lib Version = RXTX-2.1-7
      Java lib Version   = RXTX-2.1-7
      com.serotonin.modbus4j.exception.ModbusInitException: java.lang.NullPointerException
              at com.serotonin.modbus4j.serial.SerialSlave.start(SerialSlave.java:51)
              at com.serotonin.modbus4j.serial.rtu.RtuSlave.start(RtuSlave.java:40)
              at kiwi.main$1.run(main.java:46)
              at java.lang.Thread.run(Thread.java:662)
      Caused by: java.lang.NullPointerException
              at com.serotonin.messaging.StreamTransport.start(StreamTransport.java:32)
              at com.serotonin.modbus4j.serial.SerialSlave.start(SerialSlave.java:48)
              ... 3 more
      
      

      I looked through the examples but couldn't find any that were very relevant except the listener one. Google didn't really turn up anything useful either. When I looked closer at the code I figured it might be something up with the name being passed to StreamTransport and fetched the thread and got it's name and passed that as a variable instead. That didn't make any difference though.

      Thanks in advance, hope I didn't miss anything painfully obvious :)

      1 Reply Last reply Reply Quote 0
      • M
        mlohbihler
        last edited by

        There is a line in SerialSlave that should be removed.

                try {
                    serialPort = SerialUtils.openSerialPort(serialParameters);
                    transport = new StreamTransport(serialPort.getInputStream(), serialPort.getOutputStream());
                    transport.start("Modbus4J SerialSlave");  // &lt&lt&lt REMOVE THIS LINE
                }
        
        

        The start method should be (and is) called in subclasses. I'm pretty sure this will fix the problem, but i don't have any equipment available to test on. Please let me know if it helps.

        Best regards,
        Matthew

        1 Reply Last reply Reply Quote 0
        • V
          v8dave
          last edited by

          I've just come across this error from 2011 and I only downloaded the code a few days ago.

          Why was this error still present in the code?

          Anyway, the fix sorted the issue and I now have a working RTU slave.

          1 Reply Last reply Reply Quote 0
          • S
            statisticblogs
            last edited by

            I looked through the examples but couldn't find any that were very relevant except the listener one. Google didn't really turn up anything useful either. When I looked closer at the code I figured it might be something up with the name being passed to StreamTransport and fetched the thread and got it's name and passed that as a variable instead. That didn't make any difference though.

            1 Reply Last reply Reply Quote 0
            • M
              mlohbihler
              last edited by

              The line is not in the CVS code. Perhaps it still is in the src jar file. Try using the repo source instead.

              Best regards,
              Matthew

              1 Reply Last reply Reply Quote 0
              • First post
                Last post