Main.java 3.34 KB
package com.huaheng.pc.plc.util;

import HslCommunication.Core.Types.OperateResult;
import HslCommunication.Core.Types.OperateResultExOne;
import HslCommunication.Profinet.Siemens.SiemensPLCS;

public class Main {

    public static void main(String[] args) {
	// write your code here

        //SiemensS7NetUtil

        //SiemensS7NetV siemensS7Net=new SiemensS7NetV(SiemensPLCS.S1500,"192.168.10.2");
        SiemensS7NetV siemensS7Net=PlcConnectUtil.start("127.0.0.1",1,103);
        //SiemensS7NetV siemensS7Net=new SiemensS7NetV(SiemensPLCS.S1500,"127.0.0.1");
        siemensS7Net.setPort(103);
        /*SiemensS7NetUtil.start();
        OperateResult resul=SiemensS7NetUtil.writeChar("string88stringgstringggstringgggstringgggg");*/
        //OperateResult resul1=SiemensS7NetUtil.writeInt(11);
        //string char
        String str="DB1CHAR16.0,20";
        //String str="DB112.0";
        //从11位开始nggstringggst  "1234567890"+
        OperateResult resul=siemensS7Net.Write(str,"string1stringgstringggstringgggstringgggg");
        System.out.println(resul.IsSuccess);
        OperateResultExOne<String> result=siemensS7Net.ReadString(str);
        System.out.println(result.Content);

        /*String str="DB1CHAR14.0";
        //8位
        byte b=8;
        OperateResult resul=siemensS7Net.Write(str,b);
        System.out.println(resul.IsSuccess);
        OperateResultExOne<Byte> result=siemensS7Net.ReadByte(str);
        System.out.println(result.Content);*/

        //bool  8位
        /*String str_bool="DB1X0.0";
        //String str_bool="DB1.DBX0.0";
        OperateResult resul_bool=siemensS7Net.Write(str_bool,true);
        System.out.println(resul_bool.IsSuccess);
        System.out.println(resul_bool.Message);
        OperateResultExOne<Boolean> result_bool=siemensS7Net.ReadBool(str_bool);
        System.out.println(result_bool.Content);*/


        //int  16位
        /*String str_int="DB1INT2";
        short a=7;
        OperateResult resul_int=siemensS7Net.Write(str_int,a);
        //System.out.println(resul_int.IsSuccess);
        OperateResultExOne<Integer> result_int=siemensS7Net.ReadUInt16(str_int);
        System.out.println("int-result===="+result_int.Content);*/

//        //dint  32位
//        String str_dint="DB1DINT4.0";
//        Integer aa=74;
//        OperateResult resul_dint=siemensS7Net.Write(str_dint,aa);
//        System.out.println(resul_dint.IsSuccess);
//        OperateResultExOne<Integer> result_dint=siemensS7Net.ReadInt32(str_dint);
//        System.out.println(result_dint.Content);

        //dword   4位  32位
        /*String str_dword="DB1D8";
       // long aa_dw= Integer.toUnsignedLong(-2);
        int aa=6666;
        // -1456210 & 0x0FFFFFFFF;
        OperateResult resul_dword=siemensS7Net.Write(str_dword,aa);
        System.out.println(resul_dword.IsSuccess);
        OperateResultExOne<Long> result_dword2=siemensS7Net.ReadUInt32(str_dword);
        System.out.println(result_dword2.Content);*/

        //word short 2位  修改了int类型  16位
//        String str_word="DB1MW12.0";
//        short aaa=21;
//        OperateResult resul_word=siemensS7Net.Write(str_word,aaa);
//        System.out.println(resul_word.IsSuccess);
//        OperateResultExOne<Short> result_word=siemensS7Net.ReadInt16(str_word);
//        System.out.println(result_word.Content);

        //siemensS7Net.ConnectClose();





    }
}