Main.java
3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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();
}
}