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;
@ -65,12 +68,12 @@ import java.net.URI;
import org.springframework.http.MediaType;
import org.springframework.web.util.UriComponentsBuilder;
/**
* @Title: Controller
/**
* @Title: Controller
* @Description: PLC
* @author onlineGenerator
* @date 2022-09-12 18:33:25
* @version V1.0
* @version V1.0
*
*/
@Controller
@ -87,12 +90,12 @@ public class WmsPlcController extends BaseController {
private SystemService systemService;
@Autowired
private Validator validator;
/**
* PLC
*
*
* @return
*/
@RequestMapping(params = "list")
@ -102,11 +105,10 @@ public class WmsPlcController extends BaseController {
/**
* easyui AJAX
*
*
* @param request
* @param response
* @param dataGrid
* @param user
*/
@RequestMapping(params = "datagrid")
@ -123,10 +125,10 @@ public class WmsPlcController extends BaseController {
this.wmsPlcService.getDataGridReturn(cq, true);
TagUtil.datagrid(response, dataGrid);
}
/**
* PLC
*
*
* @return
*/
@RequestMapping(params = "doDel")
@ -147,10 +149,64 @@ public class WmsPlcController extends BaseController {
j.setMsg(message);
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
*
* @return
*/
@RequestMapping(params = "doBatchDel")
@ -161,7 +217,7 @@ public class WmsPlcController extends BaseController {
message = "PLC指令删除成功";
try{
for(String id:ids.split(",")){
WmsPlcEntity wmsPlc = systemService.getEntity(WmsPlcEntity.class,
WmsPlcEntity wmsPlc = systemService.getEntity(WmsPlcEntity.class,
id
);
wmsPlcService.delete(wmsPlc);
@ -179,8 +235,7 @@ public class WmsPlcController extends BaseController {
/**
* PLC
*
* @param ids
*
* @return
*/
@RequestMapping(params = "doAdd")
@ -200,11 +255,10 @@ public class WmsPlcController extends BaseController {
j.setMsg(message);
return j;
}
/**
* PLC
*
* @param ids
*
* @return
*/
@RequestMapping(params = "doUpdate")
@ -226,11 +280,11 @@ public class WmsPlcController extends BaseController {
j.setMsg(message);
return j;
}
/**
* PLC
*
*
* @return
*/
@RequestMapping(params = "goAdd")
@ -243,7 +297,7 @@ public class WmsPlcController extends BaseController {
}
/**
* PLC
*
*
* @return
*/
@RequestMapping(params = "goUpdate")
@ -254,10 +308,10 @@ public class WmsPlcController extends BaseController {
}
return new ModelAndView("com/zzjee/plc/wmsPlc-update");
}
/**
*
*
*
* @return
*/
@RequestMapping(params = "upload")
@ -265,10 +319,10 @@ public class WmsPlcController extends BaseController {
req.setAttribute("controller_name","wmsPlcController");
return new ModelAndView("common/upload/pub_excel_upload");
}
/**
* excel
*
*
* @param request
* @param response
*/
@ -287,7 +341,7 @@ public class WmsPlcController extends BaseController {
}
/**
* excel 使
*
*
* @param request
* @param response
*/
@ -301,13 +355,13 @@ public class WmsPlcController extends BaseController {
modelMap.put(NormalExcelConstants.DATA_LIST,new ArrayList());
return NormalExcelConstants.JEECG_EXCEL_VIEW;
}
@SuppressWarnings("unchecked")
@RequestMapping(params = "importExcel", method = RequestMethod.POST)
@ResponseBody
public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) {
AjaxJson j = new AjaxJson();
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
@ -335,14 +389,14 @@ public class WmsPlcController extends BaseController {
}
return j;
}
@RequestMapping(method = RequestMethod.GET)
@ResponseBody
public List<WmsPlcEntity> list() {
List<WmsPlcEntity> listWmsPlcs=wmsPlcService.getList(WmsPlcEntity.class);
return listWmsPlcs;
}
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<?> get(@PathVariable("id") String id) {

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");