1
zhang
1 天以前 3271f9b1293bef8304734534a965e2230b309116
1
3个文件已修改
46 ■■■■■ 已修改文件
zy-asc-conveyor/src/main/java/com/zy/acs/conveyor/core/service/Snap7Service.java 40 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-asc-conveyor/src/main/java/com/zy/acs/conveyor/core/thread/SiemensDevpThread.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-asc-conveyor/src/main/resources/application.yml 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-asc-conveyor/src/main/java/com/zy/acs/conveyor/core/service/Snap7Service.java
@@ -14,6 +14,7 @@
import com.zy.acs.conveyor.core.properties.SlaveProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.text.MessageFormat;
@@ -30,8 +31,8 @@
    @Autowired
    private DevpS7Service devpS7Service;
    private static final int WRITE_RETRY_MAX = 5;
    @Value("plc-write.retry")
    private int WRITE_RETRY;
    private static final int WRITE_RETRY_INTERVAL_MS = 200;
@@ -41,25 +42,25 @@
    public void writeSafe(StaProtocol staProtocol) throws InterruptedException {
        if (staProtocol == null) {
            log.warn("写入数据为空,跳过 [id:{}]", JSON.toJSONString(staProtocol));
            News.warn("写入数据为空,跳过 [id:{}]", JSON.toJSONString(staProtocol));
            return;
        }
        SiemensS7Net siemensS7Net = devpS7Service.get(staProtocol.getPlcId());
        if (siemensS7Net == null) {
            log.error("PLC未连接,无法写入 [id:{}]", JSON.toJSONString(staProtocol));
            News.error("PLC未连接,无法写入 [id:{}]", JSON.toJSONString(staProtocol));
            return;
        }
        List<DevpSlave> devp = slaveProperties.getDevp();
        DevpSlave devpSlave = devp.stream().filter(slave -> slave.getId().equals(staProtocol.getPlcId())).findFirst().orElse(null);
        if (devpSlave == null) {
            log.error("PLC未配置,无法写入 [id:{}]", JSON.toJSONString(staProtocol));
            News.error("PLC未配置,无法写入 [id:{}]", JSON.toJSONString(staProtocol));
            return;
        }
        int index = devpSlave.getStaNos().indexOf(staProtocol.getSiteId());
        if (index < 0) {
            log.error("站点编号不存在于配置中 [id:{}] [siteId:{}]", staProtocol.getPlcId(), staProtocol.getSiteId());
            News.error("站点编号不存在于配置中 [id:{}] [siteId:{}]", staProtocol.getPlcId(), staProtocol.getSiteId());
            return;
        }
        SafeSignal safeSignal = staProtocol.getSafeSignal();
@@ -86,11 +87,11 @@
        int writeCount = 0;
        boolean success = false;
        while (writeCount < WRITE_RETRY_MAX) {
        while (writeCount <= WRITE_RETRY) {
            OperateResult writeResult = siemensS7Net.Write(flagAddr, array);
            if (writeResult.IsSuccess) {
                log.info("写入安全信号输送线命令成功 [id:{}] [siteId:{}] [workNo:{}] [destSta:{}] [retry:{}]",
                News.info("写入安全信号输送线命令成功 [id:{}] [siteId:{}] [workNo:{}] [destSta:{}] [retry:{}]",
                        staProtocol.getPlcId(), staProtocol.getSiteId(), staProtocol.getWorkNo(),
                        staProtocol.getStaNo(), writeCount);
                OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入安全信号输送线命令成功。输送线plc编号={1},站点数据={2}",
@@ -100,10 +101,12 @@
            }
            writeCount++;
            log.error("写入安全信号输送线命令失败 [id:{}] [siteId:{}] [retry:{}] [workErr:{}] ",
            News.error("写入安全信号输送线命令失败 [id:{}] [siteId:{}] [retry:{}] [workErr:{}] ",
                    staProtocol.getPlcId(), staProtocol.getSiteId(), writeCount,
                    writeResult.Message);
            if (writeCount <= WRITE_RETRY) {
                Thread.sleep(WRITE_RETRY_INTERVAL_MS);
            }
        }
        if (!success) {
@@ -118,25 +121,25 @@
    public void write(StaProtocol staProtocol) throws InterruptedException {
        if (staProtocol == null) {
            log.warn("写入数据为空,跳过 [id:{}]", JSON.toJSONString(staProtocol));
            News.warn("写入数据为空,跳过 [id:{}]", JSON.toJSONString(staProtocol));
            return;
        }
        SiemensS7Net siemensS7Net = devpS7Service.get(staProtocol.getPlcId());
        if (siemensS7Net == null) {
            log.error("PLC未连接,无法写入 [id:{}]", JSON.toJSONString(staProtocol));
            News.error("PLC未连接,无法写入 [id:{}]", JSON.toJSONString(staProtocol));
            return;
        }
        List<DevpSlave> devp = slaveProperties.getDevp();
        DevpSlave devpSlave = devp.stream().filter(slave -> slave.getId().equals(staProtocol.getPlcId())).findFirst().orElse(null);
        if (devpSlave == null) {
            log.error("PLC未配置,无法写入 [id:{}]", JSON.toJSONString(staProtocol));
            News.error("PLC未配置,无法写入 [id:{}]", JSON.toJSONString(staProtocol));
            return;
        }
        int index = devpSlave.getStaNos().indexOf(staProtocol.getSiteId());
        if (index < 0) {
            log.error("站点编号不存在于配置中 [id:{}] [siteId:{}]", staProtocol.getPlcId(), staProtocol.getSiteId());
            News.error("站点编号不存在于配置中 [id:{}] [siteId:{}]", staProtocol.getPlcId(), staProtocol.getSiteId());
            return;
        }
@@ -150,14 +153,14 @@
        int writeCount = 0;
        boolean success = false;
        while (writeCount < WRITE_RETRY_MAX) {
        while (writeCount <= WRITE_RETRY) {
            OperateResult writeResult = siemensS7Net.Write(workNoAddr, staProtocol.getWorkNo());
            Thread.sleep(WRITE_RETRY_INTERVAL_MS);
            OperateResult writeResult1 = siemensS7Net.Write(destStaAddr, staProtocol.getStaNo().shortValue());
            if (writeResult.IsSuccess && writeResult1.IsSuccess) {
                log.info("写入输送线命令成功 [id:{}] [siteId:{}] [workNo:{}] [destSta:{}] [retry:{}]",
                News.info("写入输送线命令成功 [id:{}] [siteId:{}] [workNo:{}] [destSta:{}] [retry:{}]",
                        staProtocol.getPlcId(), staProtocol.getSiteId(), staProtocol.getWorkNo(),
                        staProtocol.getStaNo(), writeCount);
                OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线命令成功。输送线plc编号={1},站点数据={2}",
@@ -167,11 +170,11 @@
            }
            writeCount++;
            log.error("写入输送线命令失败 [id:{}] [siteId:{}] [retry:{}] [workErr:{}] [destErr:{}]",
            News.error("写入输送线命令失败 [id:{}] [siteId:{}] [retry:{}] [workErr:{}] [destErr:{}]",
                    staProtocol.getPlcId(), staProtocol.getSiteId(), writeCount,
                    writeResult.Message, writeResult1.Message);
            if (writeCount < WRITE_RETRY_MAX) {
            if (writeCount <= WRITE_RETRY) {
                Thread.sleep(WRITE_RETRY_INTERVAL_MS);
            }
        }
@@ -182,7 +185,6 @@
            OutputQueue.DEVP.offer(errorMsg);
            News.error("SiemensDevp - 4 - 写入输送线站点数据失败。输送线plc编号={},站点数据={}",
                    staProtocol.getPlcId(), JSON.toJSON(staProtocol));
            log.error(errorMsg);
        }
    }
zy-asc-conveyor/src/main/java/com/zy/acs/conveyor/core/thread/SiemensDevpThread.java
@@ -381,11 +381,12 @@
            if (status[3]) {
                staProtocolPut.setSafeSignal( new SafeSignal(i, (short) 0, true));
                redis.push(RedisConveyorConstant.CONVEYOR_SAFE_FLAG,staProtocolPut);
                News.info("安全交互信号复位 [id:{}] [staNo:{}]", slave.getId(), staProtocolPut.getSiteId());
            }
            if (status2[4]) {
                staProtocolTake.setSafeSignal(new SafeSignal(i, (short) 0, false));
                redis.push(RedisConveyorConstant.CONVEYOR_SAFE_FLAG, staProtocolTake);
                News.info("安全交互信号复位 [id:{}] [staNo:{}]", slave.getId(), staProtocolPut.getSiteId());
            }
        }
zy-asc-conveyor/src/main/resources/application.yml
@@ -74,6 +74,9 @@
swagger:
  enable: false
#写入plc次数,可防止无法写入
plc-write:
  retry: 1
# 下位机配置
cv-slave: