ConnectPlcController.java
1.83 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
package com.huaheng.pc.plc.controller;
import HslCommunication.Core.Types.OperateResult;
import HslCommunication.Core.Types.OperateResultExOne;
import HslCommunication.Profinet.Siemens.SiemensPLCS;
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.plc.util.SiemensS7NetV;
import io.swagger.annotations.Api;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* @author:zhouhong
* 202203
*/
@Api(tags = {"连接plc"})
@Controller
@RequestMapping("/plc/connectPlc")
public class ConnectPlcController extends BaseController {
private String prefix = "plc";
@RequiresPermissions("connectPlc:toPlcView")
@GetMapping()
public String toPlcView()
{
return prefix + "/startOrStop";
}
/**
* 点击开始按钮
*/
@PostMapping("/startClick")
@ResponseBody
public AjaxResult startClick(){
SiemensS7NetV siemensS7Net=new SiemensS7NetV(SiemensPLCS.S1500,"192.168.10.2");
String address2="DB1.DBX1.12";
OperateResult write2=siemensS7Net.Write(address2,"stringstri1233445667777");
System.out.println( write2.Message);
OperateResultExOne<String> result2=siemensS7Net.ReadString(address2);
System.out.println( result2.Content );
siemensS7Net.ConnectClose();
return AjaxResult.success();
}
/**
* 点击结束按钮
*/
@PostMapping("/stopClick")
@ResponseBody
public AjaxResult stopClick(){
return AjaxResult.success();
}
}