ConnectPlcController.java 1.83 KB
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();
    }

}