Menu

j2mod receiving Null responses communicating with Modbus RTU via Modbus TCP gateway

Paul Glenn
2016-03-18
2016-06-27
  • Paul Glenn

    Paul Glenn - 2016-03-18

    I have modbus master that was working perfectly communicating via both TCP and Serial to the Modbus Slave Simulator 1.07 by wingpath.

    Now I'm on site attempting to communicate with PhoenixConnect FL COMSERVER UNI gateway that is connected via RS485 and MODBUS RTU to multiple sensors.

    I am able to successfully connect via TCP however my requests are always return NULL response. Wireshark is also showing lots of TCP Dup Ack packets and an occasional Modbus/TCP malformed packet error message.

    The following is my example code and modbus.debug output

        public static void main(String[] args) {
    
            TCPMasterConnection conn = null;
            try { 
                conn = new TCPMasterConnection(InetAddress.getByName("192.168.8.113"));
                conn.setPort(502);
                conn.connect();
                Thread.sleep(2000);
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
            Measurement aResult = null;
            ModbusTransaction trans = null; // the transaction
            ReadMultipleRegistersRequest reqmsg = null;
            ReadMultipleRegistersResponse respmsg = null;
            trans = new ModbusTCPTransaction(conn);
    
            reqmsg = new ReadMultipleRegistersRequest(2,2);
            reqmsg.setHeadless();
            reqmsg.setUnitID(3);
    
            trans.setRequest(reqmsg);
            int retryCount = 0;
            boolean result = false;
            while( result == false && retryCount < 3) {
                try {
    
                    trans.execute();
                    result = true;
                }
                catch (Exception tee)
                {
                    logger.debug("ReadMultipleRegister tran execute exception: " + tee.fillInStackTrace());
                    retryCount++;
                    logger.debug("RETRY");
                }
    
            }
            ModbusResponse aResp =  trans.getResponse();
    
            if( aResp != null && aResp.getClass().equals(ReadMultipleRegistersResponse.class))
            {
                System.out.println("Received Modbus Response: " + aResp.getMessage().toString());
            }
            else if( aResp == null)
            {
                System.out.println("response is null");
            }
        }
    

    connect()
    request transaction ID = 0
    Sent: 00 00 00 00 00 06 03 03 00 02 00 02
    Read: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    request transaction ID = 0
    Sent: 00 00 00 00 00 06 03 03 00 02 00 02
    Read: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    request transaction ID = 0
    Sent: 00 00 00 00 00 06 03 03 00 02 00 02
    Read: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    response is null

    Any help you can provide would be greatly appreciated.

    Thanks,

    Paul

     
  • Julie Haugh

    Julie Haugh - 2016-03-19

    Paul -

    I saw this problem recently with another user, and if I keep seeing it I'll get motivated and fix the JavaDocs.

    The issue is you're using a TCP transport and the transport is what controls whether or not the messages are sent headless or not. You're setting the message to be "headless" and that's for creating bridges where the message is received, the state of being headless or having a header is changed, the raw message retrieved, then written directly to the transport.

    What you need to do is add "trans.setHeadless(true);" after you create the TCP transport.

     
  • Paul Glenn

    Paul Glenn - 2016-03-19

    Thanks Julie!

    I tried your suggestion however now im getting IllegalMonitoringStateException on execute. Do I still need to set the request message to headless as well?

     
  • Paul Glenn

    Paul Glenn - 2016-03-19

    The illegalStateException was related to something else. I am still getting null responses from execute. I've also tried removing setheadless on the request message with the same result. Any other suggestions?

     
  • Nicolas BRIOT

    Nicolas BRIOT - 2016-06-27

    Hey there !
    I use ModbusTCP, RTU and RTU-TCP daily but not with this library.
    To me it seems like there is no CRC16 (error trailer) at the end of your Modbus Frame, is it the complete request or is there some trailer not displayed ? I personally use WireShark (free soft) to view the frames in order to debug !

    Anyway, if this is the problem then you'll have to had a 16-bit trailer (see on Wikipedia or search for code)
    Hope this helped !

     

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.