-1

I am able to read data from Siemens S7300 using libnodave, but I was unable to read the data from Siemens S71500. In the code you can see that I am trying to read first 4 bytes of Data from DB2. The code runs successfully with S7300, when I change the IP address and the slot number

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;

import org.libnodave.Nodave;
import org.libnodave.PLCinterface;
import org.libnodave.S7Connection;
import org.libnodave.TCPConnection;

public class ConnectPLC {

    public static void main(String[] args) {
        S7Connection dc;
        String ip = "192.168.0.61";
        Socket sock;
        OutputStream oStream = null;
        InputStream iStream = null;
        PLCinterface di;
        int slot = 1;

        try {
            System.out.println("Inside the try block");
            sock = new Socket(ip, 102);

            if(sock != null) {
                oStream = sock.getOutputStream();
                iStream = sock.getInputStream();
                di = new PLCinterface(
                        oStream, 
                        iStream, 
                        "PLCInterface1", 
                        0, 
                        Nodave.PROTOCOL_ISOTCP);
                di.initAdapter();
                dc = new TCPConnection(di, 0, slot);            
                int res = dc.connectPLC();
                int x = 0;

                if (0 == res) {
                    System.out.println("++++++++++++++++++++++++++++++++++++");
                    System.out.println("PLC is connected");
                    System.out.println("++++++++++++++++++++++++++++++++++++");
                    byte[] byteArray = new byte[4];

                    x = dc.readBytes(Nodave.DB, 2, 0, 4, byteArray);
                    System.out.println("The value of x is "+x);

                    for (int i = 0; i < byteArray.length ; i++) {
                        System.out.println("The value at index "+i+" is "+byteArray[i]);
                    }
                    System.out.println(dc.getINT(0));
                    System.out.println(dc.getINT(2));
                    if (x == 0) {
                        //byte[] byteArray = dc.msgIn;
                        for (int i = 0; i < byteArray.length ; i++) {
                            System.out.println("The value at index "+i+" is "+byteArray[i]);
                        }
                        System.out.println(dc.getINT(0));
                        System.out.println(dc.getINT(2));
                    }



                } else {
                    System.out.println("PLC is not connected");
                }

                System.out.println("Now disconnecting\n");
                dc.disconnectPLC();
                di.disconnectAdapter();

                System.out.println();

            }
        } catch (UnknownHostException e) {
            System.out.println("Unknown Host Exception is Caught during the declaration of the socket");
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            System.out.println("IO Exception is Caught during the declaration of the socket");
            e.printStackTrace();
        }
    }

}
cricketfan
  • 15
  • 1
  • 4
  • And what error you are obtaining? – pringi Feb 14 '17 at 15:15
  • No Error, but I am not getting any value. The value of x after reading the bytes is not 0. I am getting a value of The value of x is 33028, When using S7 300 PLC I am getting 0 and the data which I read is correct. – cricketfan Feb 14 '17 at 15:33
  • When using S7 1500 PLC I am getting 33028 and the data which I read from S71500 is wrong. – cricketfan Feb 14 '17 at 15:45
  • Found the answer http://stackoverflow.com/questions/23745407/libnodave-error-while-reading-from-siemens-s7-1200-0x8104?rq=1 – cricketfan Feb 14 '17 at 15:57

1 Answers1

0

The same problem as mentioned in this post

libnodave error while reading from Siemens s7-1200 (0x8104)

After checking the access to PUT/GET I am able to read the data from the PLC

Community
  • 1
  • 1
cricketfan
  • 15
  • 1
  • 4