Fatima - 2014-05-21

I am trying to read the input registers of my PLC through MODBUS TCP using this program But I am getting some Errors.
I am trying to resolve them from so many days but its really impossible for me to do so. Please help me as soon as possible. Below is my program and then errors.

PROGRAM;

package javaapplication5;

import net.wimpi.modbus.io.ModbusTCPTransaction;
import net.wimpi.modbus.msg.WriteCoilRequest;
import net.wimpi.modbus.msg.ReadInputRegistersResponse ;
import net.wimpi.modbus.net.TCPMasterConnection;
import java.lang.*;
import java.net.InetAddress;
import net.wimpi.modbus.msg.ReadInputRegistersRequest;

public class test_modbus {

public static void main(String[] args) {

try {
TCPMasterConnection con = null; // the connection
ModbusTCPTransaction trans = null; // the transaction
ReadInputRegistersRequest rreq = null; // the read request
ReadInputRegistersResponse rres = null; // the read response
WriteCoilRequest req = null; // the write request
InetAddress addr = null; // the slave's address
int port = 502; // the default port
int repeat = 3;

        // 1. Setup the parameters
        addr = InetAddress.getByName("192.168.225.202"); // ** The address
                                                        // assigned to the
                                                        // module **

        // 2. Open the connection
        con = new TCPMasterConnection(addr);
        con.setPort(port);
        con.connect();
        System.out.println( "--- Message: Line:36 success --- " );
        // ~~~~~~~~~~~~~~~~~~~~ The faulty Read Request ~~~~~~~~~~~~~~~~~~~~
        // 3r. Prepare the READ request
        int k = 10001; 
        rreq = new ReadInputRegistersRequest(k, 3); // Reading 8 bytes (of
                                                    // what??)

        // 4r. Prepare the READ transaction
        trans = new ModbusTCPTransaction(con);
        trans.setRequest(rreq);
        System.out.println( "--- Message: Line:46 success --- " );

       //5. Execute the transaction repeat times
        int z = 0;
        do {
          trans.execute();

          rres = (ReadInputRegistersResponse)trans.getResponse(); 
          System.out.println("Hex Value of register "+"=" + rres.getHexMessage());

          z++;
        } while (z < repeat);

        // 6. Close the connection
        con.close();

    } catch (Exception ex) {
        System.out.println("Error");
        ex.printStackTrace();
        System.exit(1);
    }
}

}

ERRORS:

run:
--- Message: Line:36 success ---
--- Message: Line:46 success ---
java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
Hex Value of register =00 00 00 00 00 00 00 00 00
at java.net.SocketInputStream.read(SocketInputStream.java:150)
at java.net.SocketInputStream.read(SocketInputStream.java:121)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
at java.io.BufferedInputStream.read(BufferedInputStream.java:254)
at java.io.DataInputStream.readUnsignedShort(DataInputStream.java:337)
at net.wimpi.modbus.io.ModbusTCPTransport.readResponse(ModbusTCPTransport.java)
at net.wimpi.modbus.io.ModbusTCPTransaction.execute(ModbusTCPTransaction.java)
at javaapplication5.test_modbus.main(test_modbus.java:54)

:::::LINE 54 IS trans.execute();:::::::::::