PLC指令集

master
cez 2022-09-12 19:03:54 +08:00
parent 5fe8fe5e2c
commit 0da9bafc80
2 changed files with 114 additions and 30 deletions

View File

@ -1,4 +1,7 @@
package com.zzjee.plc.controller;
import HslCommunication.Core.Types.OperateResult;
import HslCommunication.Profinet.Siemens.SiemensPLCS;
import HslCommunication.Profinet.Siemens.SiemensS7Net;
import com.zzjee.plc.entity.WmsPlcEntity;
import com.zzjee.plc.service.WmsPlcServiceI;
import java.util.ArrayList;
@ -106,7 +109,6 @@ public class WmsPlcController extends BaseController {
* @param request
* @param response
* @param dataGrid
* @param user
*/
@RequestMapping(params = "datagrid")
@ -148,6 +150,60 @@ public class WmsPlcController extends BaseController {
return j;
}
/**
* PLC
*
* @return
*/
@RequestMapping(params = "dotoup")
@ResponseBody
public AjaxJson dotoup(String ids,HttpServletRequest request){
String message = null;
AjaxJson j = new AjaxJson();
message = "PLC指令执行成功";
try{
for(String id:ids.split(",")){
WmsPlcEntity wmsPlc = systemService.getEntity(WmsPlcEntity.class,
id
);
SiemensPLCS siemensPLCS = SiemensPLCS.S200Smart;
SiemensS7Net siemensS7Net = null;
siemensS7Net = new SiemensS7Net(siemensPLCS);
siemensS7Net.setIpAddress(wmsPlc.getPlcIp());
siemensS7Net.setPort(Integer.parseInt(wmsPlc.getPlcPort()) );
OperateResult connect = siemensS7Net.ConnectServer();
if(connect.IsSuccess){
System.out.println("connect success");
}else{
System.out.println("connect error");
}
String[] coms = wmsPlc.getComCons().split(";");
for (String com : coms) {
String[] split = com.split(",");
String defaultAddress = split[1];
if(split[0].equals("boolean")){
if(split[2].equals("false")){
siemensS7Net.Write(defaultAddress,false);
}else{
siemensS7Net.Write(defaultAddress,true);
}
}
else if(split[0].equals("float")){
siemensS7Net.Write(defaultAddress,Float.parseFloat(split[2]));
}
}
//执行完指令等待时间
Thread.sleep(Long.parseLong(wmsPlc.getComTime()));
}
}catch(Exception e){
e.printStackTrace();
message = "PLC指令执行失败";
throw new BusinessException(e.getMessage());
}
j.setMsg(message);
return j;
}
/**
* PLC
*
@ -180,7 +236,6 @@ public class WmsPlcController extends BaseController {
/**
* PLC
*
* @param ids
* @return
*/
@RequestMapping(params = "doAdd")
@ -204,7 +259,6 @@ public class WmsPlcController extends BaseController {
/**
* PLC
*
* @param ids
* @return
*/
@RequestMapping(params = "doUpdate")

View File

@ -30,7 +30,8 @@
<t:dgToolBar title="查看" icon="icon-search" url="wmsPlcController.do?goUpdate" funname="detail"></t:dgToolBar>
<t:dgToolBar title="导入" icon="icon-put" funname="ImportXls"></t:dgToolBar>
<t:dgToolBar title="导出" icon="icon-putout" funname="ExportXls"></t:dgToolBar>
<t:dgToolBar title="模板下载" icon="icon-putout" funname="ExportXlsByT"></t:dgToolBar>
<t:dgToolBar title="批量执行" funname="batchupbin"></t:dgToolBar>
</t:datagrid>
</div>
</div>
@ -38,9 +39,38 @@
<script type="text/javascript">
$(document).ready(function(){
});
function batchupbin() {
var rows = $('#wmsPlcList').datagrid('getSelections');
if(rows.length > 0){
var ids = [];
for (var i = 0; i < rows.length; i++) {
ids.push(rows[i].id);
}
var url = "wmsPlcController.do?dotoup&ids="+ids.join(',');
$.ajax({
async : false,
cache : false,
type : 'POST',
url : url,// 请求的action路径
error : function() {// 请求失败处理函数
},
success : function(data) {
var d = $.parseJSON(data);
if (d.success) {
}
}
});
tip("执行成功");
$('#wmsPlcList').datagrid('reload',{});
}
}
//导入
function ImportXls() {
openwindow('Excel导入', 'wmsPlcController.do?upload', "wmsPlcList");