无法使用libnodave和Java从西门子S71500中的数据库读取数据

无法使用libnodave和Java从西门子S71500中的数据库读取数据,java,libnodave,Java,Libnodave,我能够使用libnodave从西门子S7300读取数据,但无法从西门子S71500读取数据。在代码中,您可以看到我试图从DB2读取前4个字节的数据。当我更改IP地址和插槽号时,代码在S7300中成功运行 import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.Socket; import java.net.UnknownHostException;

我能够使用libnodave从西门子S7300读取数据,但无法从西门子S71500读取数据。在代码中,您可以看到我试图从DB2读取前4个字节的数据。当我更改IP地址和插槽号时,代码在S7300中成功运行

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();
        }
    }

}
import java.io.IOException;
导入java.io.InputStream;
导入java.io.OutputStream;
导入java.net.Socket;
导入java.net.UnknownHostException;
导入org.libnodave.Nodave;
导入org.libnodave.PLCinterface;
导入org.libnodave.S7Connection;
导入org.libnodave.TCPConnection;
公共类连接PLC{
公共静态void main(字符串[]args){
s7连接直流;
字符串ip=“192.168.0.61”;
插座;
OutputStream oStream=null;
InputStream iStream=null;
PLC接口di;
int槽=1;
试一试{
System.out.println(“在try块内部”);
插座=新插座(ip,102);
if(sock!=null){
oStream=sock.getOutputStream();
iStream=sock.getInputStream();
di=新的PLC接口(
奥斯特拉姆,
iStream,
“PLCInterface1”,
0, 
Nodave.协议(CP);
di.initAdapter();
dc=新的TCP连接(di,0,插槽);
int res=dc.connectPLC();
int x=0;
如果(0==res){
System.out.println(“+;
System.out.println(“PLC已连接”);
System.out.println(“+;
字节[]字节数组=新字节[4];
x=dc.readBytes(Nodave.DB,2,0,4,byteArray);
System.out.println(“x的值为“+x”);
for(int i=0;i
与本文中提到的问题相同


检查对PUT/GET的访问后,我能够从PLC读取数据

以及您得到的错误是什么?没有错误,但我没有得到任何值。读取字节后的x值不是0。我得到的x值是33028,当使用S7 300 PLC时,我得到的是0,我读取的数据是正确的。当使用S7 1500 PLC时,我得到的是33028,我从S71500读取的数据是错误的。找到了答案