Suman - 2015-04-28

i am developing a android app and i want to read the coil status on click of a button.i encounter problem at "trans.execute".Please let me know what is the problem. the java code works perfectly but this android code is not.

Below is the code:

public void onClick(View view)
{
// Reading coil status

               if(MainActivity.con.isConnected())
               {
                 System.out.println("connected");
                 Toast.makeText(NextActivity.this,"Connected to "+MainActivity.ipAddr.getText().toString(), Toast.LENGTH_LONG).show();
                 req=new ReadCoilsRequest(99, 1);
                MainActivity.con.setTimeout(9000);
                trans=new ModbusTCPTransaction(MainActivity.con);
                trans.setRequest(req);
                try {
                    trans.execute();
                } catch (ModbusException e) {
                    e.printStackTrace();
                    System.out.println("Exception caught");
                }
                res=(ReadCoilsResponse)trans.getResponse();
                Toast.makeText(NextActivity.this,"Response : "+res.getCoils().toString(), Toast.LENGTH_LONG).show();
                System.out.println("Response : "+res.getCoils().toString());
               }

The exception encountered is:

04-28 06:00:34.349: W/System.err(1484): net.wimpi.modbus.ModbusIOException: Executing transaction failed (tried 3 times)