agv请求实体类和plc初始化连接
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
package com.ruoyi.schedule.data;
|
||||
|
||||
|
||||
import com.ruoyi.schedule.plc.domain.ConvPortRead;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.plc4x.java.PlcDriverManager;
|
||||
import org.apache.plc4x.java.api.PlcConnection;
|
||||
import org.apache.plc4x.java.api.messages.PlcReadRequest;
|
||||
import org.apache.plc4x.java.api.messages.PlcReadResponse;
|
||||
import org.apache.plc4x.java.api.types.PlcResponseCode;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 获取输送机plc连接
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class ConvConnection {
|
||||
|
||||
Integer convPortCount = 10;
|
||||
|
||||
String ipConv = "127.0.0.1";
|
||||
|
||||
PlcConnection convConnection;
|
||||
|
||||
/**
|
||||
* 初始化输送机plc连接
|
||||
*/
|
||||
@PostConstruct
|
||||
public void initializeConvConnection() {
|
||||
try {
|
||||
convConnection = new PlcDriverManager().getConnection("s7://" + ipConv);
|
||||
log.info("【输送机连接初始化】输送机连接成功!");
|
||||
}catch (Exception e){
|
||||
log.warn("【输送机连接初始化】输送机连接失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取所有输送机状态参数
|
||||
* @return
|
||||
*/
|
||||
public List<ConvPortRead> getConvPortStatus() {
|
||||
|
||||
List<ConvPortRead> convPorts = 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) {
|
||||
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"));
|
||||
|
||||
}else{
|
||||
log.warn("【获取出入口输送机状态】获取状态参数失败:" + response.getResponseCode("value-test"));
|
||||
return null;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.warn("【获取出入口输送机状态】获取状态参数失败:" + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return convPorts;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.ruoyi.schedule.plc.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ConvBaseRead {
|
||||
|
||||
/**
|
||||
* 输送机编号
|
||||
*/
|
||||
private String convName;
|
||||
|
||||
/**
|
||||
* 任务号
|
||||
*/
|
||||
private String taskId;
|
||||
|
||||
/**
|
||||
* 是否空闲
|
||||
* 1-空闲 0-占用
|
||||
*/
|
||||
private Integer free;
|
||||
|
||||
/**
|
||||
* 输送到位
|
||||
* 0-未到位 1-到位
|
||||
*/
|
||||
private Integer inPostion;
|
||||
|
||||
/**
|
||||
* 入库到位
|
||||
* 0-未到位 1-到位
|
||||
*/
|
||||
private Integer inPostionForStockIn;
|
||||
|
||||
/**
|
||||
* 出库到位
|
||||
* 0-未到位 1-到位
|
||||
*/
|
||||
private Integer inPostionForStockOut;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user