i am not getting any reponse in ModbusTCPTransport.java. when i call readResponse() function it will try to read
at m_Input.read(buffer, 0, 6). Here after no response. You can see this function below in that i am getting only fisrt logger(m_Input.isAvailbal 0) but not the second logger. Same driver is working fine in serial connection. An one has clue why it is not getting any value? Please reply to this. Any help is appreciated....
public ModbusResponse readResponse() throws ModbusIOException {
try{ModbusResponseresponse=null;synchronized(m_ByteIn){//usesamebufferbyte[]buffer=m_ByteIn.getBuffer();if(Modbus.debug)System.err.println("Read: "+ModbusUtil.toHex(buffer,0,m_ByteIn.count));if(!headless){/**AllModbusTCPtransactionsstartwith6bytes.Getthem.*/System.out.println("m_Input.isAvailbale "+m_Input.available());if(m_Input.read(buffer,0,6)==-1){thrownewModbusIOException("Premature end of stream (Header truncated).");}System.out.println("m_Input.isAvailbale_2 "+m_Input.available());/**ThetransactionIDisthefirstword(offset0)inthe*datathatwasjustread.Itwillbeechoedbacktothe*requester.**TheprotocolIDisthesecondword(offset2)inthe*data.Itshouldalwaysbe0,butIdon't check.**Thelengthofthepayloadisthethirdword(offset4)in*thedatathatwasjustread.That's what I need in order*toreadtherestoftheresponse.*/inttransaction=ModbusUtil.registerToShort(buffer,0);intprotocol=ModbusUtil.registerToShort(buffer,2);intcount=ModbusUtil.registerToShort(buffer,4);if(m_Input.read(buffer,6,count)==-1)thrownewModbusIOException("Premature end of stream (Message truncated).");m_ByteIn.reset(buffer,(6+count));m_ByteIn.reset();m_ByteIn.skip(7);intfunction=m_ByteIn.readUnsignedByte();response=ModbusResponse.createModbusResponse(function);/**Rewindtheinputbuffer,thenreadthedataintothe*response.*/m_ByteIn.reset();response.readFrom(m_ByteIn);response.setTransactionID(transaction);response.setProtocolID(protocol);}else{/**Thisisaheadlessresponse.Ithasthesameformatasa*RTUoverSerialresponse.*/intunit=m_Input.readByte();intfunction=m_Input.readByte();response=ModbusResponse.createModbusResponse(function);response.setUnitID(unit);response.setHeadless();response.readData(m_Input);/**NowdiscardtheCRC.Whichhopefullywasn't needed*becausethisisaTCPtransport.*/m_Input.readShort();}}returnresponse;}catch(SocketTimeoutExceptionex){thrownewModbusIOException("Timeout reading response");}catch(Exceptionex){if(exinstanceofSocketException){ModbusDevManager.bConnected=false;}thrownewModbusIOException("I/O exception - failed to read.");}}output:m_Input.isAvailbale0m_Input.isAvailbale0m_Input.isAvailbale0
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi all,
i am not getting any reponse in ModbusTCPTransport.java. when i call readResponse() function it will try to read
at m_Input.read(buffer, 0, 6). Here after no response. You can see this function below in that i am getting only fisrt logger(m_Input.isAvailbal 0) but not the second logger. Same driver is working fine in serial connection. An one has clue why it is not getting any value? Please reply to this. Any help is appreciated....
public ModbusResponse readResponse() throws ModbusIOException {