agv常用请求接口实体和和设备参数获取
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
package com.ruoyi.schedule.data;
|
||||
|
||||
|
||||
import com.ruoyi.schedule.plc.domain.ConvPortRead;
|
||||
import com.ruoyi.schedule.plc.domain.ConvPTLInRead;
|
||||
import com.ruoyi.schedule.plc.domain.ConvPTLOutRead;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.plc4x.java.PlcDriverManager;
|
||||
import org.apache.plc4x.java.api.PlcConnection;
|
||||
@@ -42,13 +43,63 @@ public class ConvConnection {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取所有输送机状态参数
|
||||
* 获取所有PTL入口输送机状态参数
|
||||
* @return
|
||||
*/
|
||||
public List<ConvPortRead> getConvPortStatus() {
|
||||
public List<ConvPTLInRead> getConvPTLIn() {
|
||||
|
||||
List<ConvPortRead> convPorts = new ArrayList<>();
|
||||
List<ConvPTLInRead> convPTLIn = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < convPortCount; i++) {
|
||||
try {
|
||||
PlcReadRequest.Builder builder = convConnection.readRequestBuilder();
|
||||
|
||||
builder.addItem("value-test","%M0.0:BOOL");
|
||||
builder.addItem("conv-inPostion","%DB501.DBW" + (0 + i * 30) + ":INT");
|
||||
// builder.addItem("conv-height","%DB501.DBW" + (2 + i * 30) + ":INT");
|
||||
builder.addItem("conv-isException","%DB501.DBD" + (4 + i * 30) + ":DINT");
|
||||
builder.addItem("conv-free","%DB501.DBW" + (6 + i * 30) + ":INT");
|
||||
builder.addItem("conv-taskId","%DB501.DBD" + (8 + i * 30) + ":INT");
|
||||
// builder.addItem("conv-palletId","%DB501.DBD" + (16 + i * 30) + ":STRING");
|
||||
|
||||
PlcReadRequest readRequest = builder.build();
|
||||
|
||||
PlcReadResponse response=readRequest.execute().get(2000, TimeUnit.MILLISECONDS);
|
||||
|
||||
if (response.getResponseCode("value-test") == PlcResponseCode.OK) {
|
||||
convPTLIn.get(i).setInPostion(response.getInteger("conv-inPostion"));
|
||||
// convPTLIn.get(i).setHeight(response.getInteger("conv-height"));
|
||||
convPTLIn.get(i).setIsException(response.getInteger("conv-isException"));
|
||||
convPTLIn.get(i).setFree(response.getInteger("conv-free"));
|
||||
convPTLIn.get(i).setTaskId(response.getString("conv-taskId"));
|
||||
// convPTLIn.get(i).setPalletId(response.getString("conv-palletId"));
|
||||
|
||||
}else{
|
||||
log.warn("【获取PTL拣选入口输送机状态】获取状态参数失败:" + response.getResponseCode("value-test"));
|
||||
return null;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.warn("【获取PTL拣选入口输送机状态】获取状态参数失败:" + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return convPTLIn;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取所有PTL出口输送机状态参数
|
||||
* @return
|
||||
*/
|
||||
public List<ConvPTLOutRead> getConvPTLOut() {
|
||||
|
||||
List<ConvPTLOutRead> convPTLOut = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < convPortCount; i++) {
|
||||
try {
|
||||
@@ -67,25 +118,25 @@ public class ConvConnection {
|
||||
PlcReadResponse response=readRequest.execute().get(2000, TimeUnit.MILLISECONDS);
|
||||
|
||||
if (response.getResponseCode("value-test") == PlcResponseCode.OK) {
|
||||
convPorts.get(i).setInPostion(response.getInteger("conv-inPostion"));
|
||||
convPorts.get(i).setHeight(response.getInteger("conv-height"));
|
||||
convPorts.get(i).setIsException(response.getInteger("conv-isException"));
|
||||
convPorts.get(i).setFree(response.getInteger("conv-free"));
|
||||
convPorts.get(i).setTaskId(response.getString("conv-taskId"));
|
||||
convPorts.get(i).setPalletId(response.getString("conv-palletId"));
|
||||
convPTLOut.get(i).setInPostion(response.getInteger("conv-inPostion"));
|
||||
convPTLOut.get(i).setHeight(response.getInteger("conv-height"));
|
||||
convPTLOut.get(i).setIsException(response.getInteger("conv-isException"));
|
||||
convPTLOut.get(i).setFree(response.getInteger("conv-free"));
|
||||
convPTLOut.get(i).setTaskId(response.getString("conv-taskId"));
|
||||
convPTLOut.get(i).setPalletId(response.getString("conv-palletId"));
|
||||
|
||||
}else{
|
||||
log.warn("【获取出入口输送机状态】获取状态参数失败:" + response.getResponseCode("value-test"));
|
||||
log.warn("【获取PTL拣选出口输送机状态】获取状态参数失败:" + response.getResponseCode("value-test"));
|
||||
return null;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.warn("【获取出入口输送机状态】获取状态参数失败:" + e.getMessage());
|
||||
log.warn("【获取PTL拣选出口输送机状态】获取状态参数失败:" + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return convPorts;
|
||||
return convPTLOut;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -43,4 +43,10 @@ public class ConvBaseRead {
|
||||
*/
|
||||
private Integer inPostionForStockOut;
|
||||
|
||||
/**
|
||||
* 是否异常
|
||||
* 0-正常 1-异常
|
||||
*/
|
||||
private Integer isException;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.ruoyi.schedule.plc.domain;
|
||||
|
||||
public class ConvBaseWrite {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.ruoyi.schedule.plc.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* PTL拣选输送线入口输送机-读plc状态
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class ConvPTLInRead extends ConvBaseRead {
|
||||
|
||||
/**
|
||||
* 外形检测-高度
|
||||
* 1-500mm 2-800mm 3-1000mm
|
||||
*/
|
||||
// private Integer height;
|
||||
|
||||
/**
|
||||
* 托盘码
|
||||
*/
|
||||
// private String palletId;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.ruoyi.schedule.plc.domain;
|
||||
|
||||
public class ConvPTLInWrite extends ConvBaseWrite {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.ruoyi.schedule.plc.domain;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* PTL拣选输送线出口输送机
|
||||
*/
|
||||
@Data
|
||||
public class ConvPTLOutRead extends ConvBaseRead {
|
||||
|
||||
/**
|
||||
* 是否异常
|
||||
* 0-正常 1-异常
|
||||
*/
|
||||
private Integer isException;
|
||||
|
||||
/**
|
||||
* 外形检测-高度
|
||||
* 1-500mm 2-800mm 3-1000mm
|
||||
*/
|
||||
private Integer height;
|
||||
|
||||
/**
|
||||
* 托盘码
|
||||
*/
|
||||
private String palletId;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.ruoyi.schedule.plc.domain;
|
||||
|
||||
|
||||
public class ConvPTLOutWrite extends ConvBaseWrite{
|
||||
}
|
||||
119
ruoyi-admin/src/main/java/com/ruoyi/schedule/task/Execution.java
Normal file
119
ruoyi-admin/src/main/java/com/ruoyi/schedule/task/Execution.java
Normal file
@@ -0,0 +1,119 @@
|
||||
package com.ruoyi.schedule.task;
|
||||
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.ruoyi.common.Constant;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.device.agv.domain.genAgvSchedulingTask.GenAgvSchedulingTaskRequest;
|
||||
import com.ruoyi.device.agv.domain.genAgvSchedulingTask.GenAgvSchedulingTaskResponse;
|
||||
import com.ruoyi.device.agv.domain.queryAgvStatus.QueryAgvStatusRequest;
|
||||
import com.ruoyi.device.agv.domain.queryAgvStatus.QueryAgvStatusResponse;
|
||||
import com.ruoyi.schedule.job.mydojob.domain.MydoJob;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 向AGV/CTU下发指令
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class Execution {
|
||||
|
||||
|
||||
/**
|
||||
* 查询是否有wcs任务
|
||||
*/
|
||||
@PostConstruct
|
||||
public List<MydoJob> getmydoJob(){
|
||||
|
||||
String url = "http://127.0.0.1:8080/job/inmydoJob/listAll";
|
||||
|
||||
HttpResponse response = HttpRequest.get(url).execute();
|
||||
|
||||
List<MydoJob> mydoJobs = JSON.parseArray(response.body(), MydoJob.class);
|
||||
|
||||
return mydoJobs;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 向AGV/CTU请求下发指令
|
||||
* @param request 请求对象
|
||||
* @return
|
||||
*/
|
||||
public boolean sendCommand(GenAgvSchedulingTaskRequest request) {
|
||||
|
||||
//下发校验
|
||||
if (checkForSendCommand(request)) return false;
|
||||
|
||||
String jsonString = JSON.toJSONString(request);
|
||||
|
||||
//请求源数据输出日志
|
||||
log.info(jsonString);
|
||||
|
||||
//请求接口
|
||||
HttpResponse response = HttpRequest.post(Constant.BASEURL_REST + "genAgvSchedulingTask")
|
||||
.body(jsonString)
|
||||
.header("Content-Type", "application/json")
|
||||
.execute();
|
||||
|
||||
//获取响应对象
|
||||
GenAgvSchedulingTaskResponse genAgvSchedulingTaskResponse = JSON.parseObject(response.body(), GenAgvSchedulingTaskResponse.class);
|
||||
|
||||
//返回请求编号校验
|
||||
if (genAgvSchedulingTaskResponse.getReqCode() != request.getReqCode()) {
|
||||
log.error("【下发设备任务】下发任务失败,请求编号错误不一致!");
|
||||
return false;
|
||||
}
|
||||
|
||||
//返回码
|
||||
if (genAgvSchedulingTaskResponse.getCode() == 0 ) {
|
||||
return true;
|
||||
}else {
|
||||
log.error("【下发设备任务】下发任务失败," + genAgvSchedulingTaskResponse.getMessage() + "!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 下发指令校验
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
public boolean checkForSendCommand(GenAgvSchedulingTaskRequest request){
|
||||
//todo:请求信息校验
|
||||
//1.reqCode空
|
||||
if (StringUtils.isBlank(request.getReqCode())){
|
||||
log.warn("【生成AGV任务请求接口】---请求异常,reqCode为空!---");
|
||||
return false;
|
||||
}
|
||||
|
||||
//2.wbCode和positionCodePath至少填写其中一项,以确定任务中的位置信息。若任务中需要指定多个位置信息,如起点和终点信息等,请使用positionCodePath
|
||||
if (StringUtils.isBlank(request.getWbCode()) && request.getPositionCodePath().size() < 1){
|
||||
log.warn("【生成AGV任务请求接口】---请求异常,wbCode和positionCodePath至少填写其中一项!---");
|
||||
return false;
|
||||
}
|
||||
|
||||
//3.当前区域AGV/CTU是否已存在任务
|
||||
//todo 请求获取设备状态
|
||||
if (true){
|
||||
log.warn("【生成AGV任务请求接口】---当前设备已存在执行中的任务!---");
|
||||
return false;
|
||||
}
|
||||
|
||||
//4.请求编号一致时避免重复下发
|
||||
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.ruoyi.schedule.task;
|
||||
|
||||
import com.ruoyi.schedule.data.ConvConnection;
|
||||
import com.ruoyi.schedule.plc.domain.ConvPTLInRead;
|
||||
import com.ruoyi.schedule.plc.domain.ConvPTLOutRead;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 获取任务生成AGV指令
|
||||
*/
|
||||
@Component
|
||||
public class Generation {
|
||||
|
||||
@Autowired
|
||||
ConvConnection conv;
|
||||
|
||||
//获取PTL拣选工位入口状态
|
||||
public List<ConvPTLInRead> getConvPTLInRead() {
|
||||
|
||||
List<ConvPTLInRead> convPTLInReads=conv.getConvPTLIn();
|
||||
|
||||
for (int i = 0; i < convPTLInReads.size(); i++) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
return convPTLInReads;
|
||||
}
|
||||
|
||||
|
||||
//获取PTL拣选工位出口状态
|
||||
public List<ConvPTLOutRead> getConvPTLOutRead() {
|
||||
|
||||
List<ConvPTLOutRead> convPTLOutReads=conv.getConvPTLOut();
|
||||
|
||||
|
||||
return convPTLOutReads;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user