marco - 2016-01-10

Hello, i have some issue on retrieve Coils.
Im trying to retrieve coils from a xlogic PLC http://xlogic-plc.com/
For the connection I use TCP.
After I send the request i receive the answer but the value register is always 00
Below the HEX Request and Response Message of my code
Request getHexMessage 00 00 00 00 00 06 01 01 00 00 00 07
Response getHexMessage 00 00 00 00 00 04 01 01 01 00

If i use the following program (qmodmaster on sourceforge) to retrieve the same plc info every thing is working fine.

The send request is the same like my code( change only the TransactionID) but the Response
is different, in this case i have a value that reflect the coils status.

Request 00 01 00 00 00 06 01 01 00 00 00 07
Response 00 01 00 00 00 04 01 01 01 05

And for this was wondering what im doing wrong?
I will apriciate your suggestion.

Thanks
marco

Below the code that i use to retrieve coils

public class j2mod_read_coil {
    TCPMasterConnection con = null; // the connection
    ModbusTCPTransaction trans = null; // the transaction
    ReadCoilsResponse readCoilResponse = null; // the input Discrete response

    /* Variables for storing the parameters */
    InetAddress addr = null; // the slave's address
    // int port = 27011;
    int ref = 0; // the reference number
    int count = 7; // the number of bit to be read
    // int repeat = 1; // a loop for repeating the transaction

    public void callTCPModbus(int port) {
        // 2. Set master identifier
        try {
            addr = InetAddress.getByName("192.168.1.146");

            // 3. Prepare the Request
            ReadCoilsRequest readCoilRequest = new ReadCoilsRequest(ref, count);
            readCoilRequest.setTransactionID(0);
            readCoilRequest.setProtocolID(0);
            readCoilRequest.setUnitID(1);

            // 2. Open the connection
            con = new TCPMasterConnection(addr);
            con.setPort(port);
            con.connect();

            // 4. Prepare a transaction
            trans = new ModbusTCPTransaction(con);
            trans.setRequest(readCoilRequest);

            System.out.println("Request getHexMessage " + readCoilRequest.getHexMessage());

            // 5. Execute the transaction
            trans.execute();
            readCoilResponse = (ReadCoilsResponse) trans.getResponse();
            System.out.println("getBitCount " + readCoilResponse.getBitCount());
            System.out.println("getDataLength " + readCoilResponse.getDataLength());
            System.out.println("getFunctionCode " + readCoilResponse.getFunctionCode());
            System.out.println("Response getHexMessage " + readCoilResponse.getHexMessage());
            System.out.println("getMessage " + readCoilResponse.getMessage());
            System.out.println("getOutputLength " + readCoilResponse.getOutputLength());
            System.out.println("getProtocolID " + readCoilResponse.getProtocolID());
            System.out.println("getTransactionID " + readCoilResponse.getTransactionID());
            System.out.println("getUnitID " + readCoilResponse.getUnitID());
            System.out.println("getCoils " + readCoilResponse.getCoils());
            System.out.println("getCoilStatus " + readCoilResponse.getCoilStatus(0));

            // 6. Close the connection
            con.close();
            trans = null;

        } catch (Exception ExceptionResponse) {
            System.out.println("Errore getCause--> " + ExceptionResponse.getCause());
            System.out.println("Errore getMessage--> " + ExceptionResponse.getMessage());
            con.close();
        }
    }
}

-------------- BELOW my DEBUG RESULTS --------------
--GET COIL --
Request getHexMessage 00 00 00 00 00 06 01 01 00 00 00 07
getBitCount 8
getDataLength 4
getFunctionCode 1
Response getHexMessage 00 00 00 00 00 04 01 01 01 00
getMessage [B@2a0b20
getOutputLength 10
getProtocolID 0
getTransactionID 0
getUnitID 1
getCoils 00000000
getCoilStatus false
Digital COIL Status=00000000
Input Discrete bit 0=false
Input Discrete bit 1=false
Input Discrete bit 2=false
Input Discrete bit 3=false
Input Discrete bit 4=false
Input Discrete bit 5=false
Input Discrete bit 6=false
Input Discrete bit 7=false