1
Administrator
2026-04-20 63703b10d1f68df3f47c2f071c19fad5686274f0
1
4个文件已修改
71 ■■■■ 已修改文件
zy-asc-conveyor/src/main/java/com/zy/acs/conveyor/core/listen/DevpPlcDataSubscriber.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-asc-conveyor/src/main/java/com/zy/acs/conveyor/core/operation/handler/AppleLocOperationHandler.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-asc-conveyor/src/main/java/com/zy/acs/conveyor/core/service/StationService.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-asc-conveyor/src/main/java/com/zy/acs/conveyor/core/thread/SiemensDevpThread.java 63 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-asc-conveyor/src/main/java/com/zy/acs/conveyor/core/listen/DevpPlcDataSubscriber.java
@@ -38,7 +38,7 @@
    @EventListener(ApplicationReadyEvent.class)
    private void start() {
        for (DevpSlave devp : slaveProperties.getDevp()) {
            Thread thread = new Thread(new SiemensDevpThread(devp, devpS7Service.get(devp.getId()), stationService.getStationMap(devp.getId())));
            Thread thread = new Thread(new SiemensDevpThread(devp, devpS7Service.get(devp.getId()), stationService));
            conContain.put(devp.getId().toString(), thread);
            thread.start();
        }
zy-asc-conveyor/src/main/java/com/zy/acs/conveyor/core/operation/handler/AppleLocOperationHandler.java
@@ -110,7 +110,7 @@
                            continue;
                        }
                        if (staProtocol.isWeightErr()) {
                            News.error("{}:站点:{},超重或", config.getMark(), staProtocol.getSiteId());
                            News.error("{}:站点:{},超重", config.getMark(), staProtocol.getSiteId());
                            continue;
                        }
                        if (staProtocol.isBarcodeErr()) {
zy-asc-conveyor/src/main/java/com/zy/acs/conveyor/core/service/StationService.java
@@ -79,5 +79,9 @@
        }
    }
    public void updateStaProtocol(Integer plcId, Map<Integer, StaProtocol> data) {
        STATION_CACHE.put(plcId, data);
    }
}
zy-asc-conveyor/src/main/java/com/zy/acs/conveyor/core/thread/SiemensDevpThread.java
@@ -39,7 +39,7 @@
    private SiemensS7Net siemensS7Net;
    private Map<Integer, StaProtocol> station;
    private StationService stationService;
    private final RedisSupport redis = RedisSupport.defaultRedisSupport;
@@ -55,10 +55,10 @@
    private long lastDbUpdateTime = 0;
    public SiemensDevpThread(DevpSlave slave, SiemensS7Net siemensS7Net, Map<Integer, StaProtocol> station) {
    public SiemensDevpThread(DevpSlave slave, SiemensS7Net siemensS7Net, StationService stationService) {
        this.slave = slave;
        this.siemensS7Net = siemensS7Net;
        this.station = station;
        this.stationService = stationService;
    }
@@ -92,13 +92,12 @@
            log.warn("PLC未连接,跳过读取 [id:{}]", slave.getId());
            return;
        }
        if (station == null) {
            StationService stationService = SpringContextUtil.getBean(StationService.class);
            if (stationService != null) {
                station = stationService.getStationMap(slave.getId());
            }
            log.warn("站点未连接,跳过读取 [id:{}]", slave.getId());
            return;
        Map<Integer, StaProtocol> stationMap = null;
        if (stationService == null) {
            stationService = SpringContextUtil.getBean(StationService.class);
            stationMap = stationService.getStationMap(slave.getId());
        } else {
            stationMap = stationService.getStationMap(slave.getId());
        }
        List<Integer> staNos = slave.getStaNos();
@@ -116,28 +115,30 @@
        byte[] content = result.Content;
        for (int i = 0; i < staNoSize; i++) {
            StaProtocol staProtocol = station.get(staNos.get(i));
            StaProtocol staProtocol = stationMap.get(staNos.get(i));
            parseStationStatus(content, i, staProtocol);
        }
        // 读取条码
        readBarcodes();
        readBarcodes(stationMap);
        // 称重
        readWeight();
        readWeight(stationMap);
        // 读取外形检测错误
        readDimensionErrors();
        readDimensionErrors(stationMap);
        // 读取PLC故障
        readPlcAlarms(staNos, staNoSize);
        readPlcAlarms(stationMap, staNos, staNoSize);
        // 读取安全交互信号
        readSaleSingle(slave.getPutSta(), slave.getTakeSta());
        readSaleSingle(stationMap, slave.getPutSta(), slave.getTakeSta());
        // 定期更新数据库(降低频率)
        updateDatabaseIfNeeded();
        updateDatabaseIfNeeded(stationMap);
    }
    /**
@@ -187,7 +188,7 @@
    /**
     * 读取条码信息
     */
    private void readBarcodes() {
    private void readBarcodes(Map<Integer, StaProtocol> stationMap) {
        if (slave.getBarcode() == null || !slave.getBarcode()) {
            return;
        }
@@ -211,7 +212,7 @@
                    DeviceField.BARCODE.getByteLength() - seg[1], "UTF-8").trim();
            if (!Cools.isEmpty(barcode) && !barcode.contains("Default") && !barcode.contains("Error") && staNo != 0) {
                StaProtocol staProtocol = station.get(staNo);
                StaProtocol staProtocol = stationMap.get(staNo);
                if (staProtocol == null) {
                    log.warn("扫码站点不存在 [id:{}] [staNo:{}]", slave.getId(), staNo);
                    continue;
@@ -225,7 +226,7 @@
    /**
     * 读取重量信息
     */
    private void readWeight() {
    private void readWeight(Map<Integer, StaProtocol> stationMap) {
        if (slave.getWeight() == null || !slave.getWeight()) {
            return;
        }
@@ -246,7 +247,7 @@
            Double weight = (double) siemensS7Net.getByteTransform().TransSingle(
                    content, seg[1] + i * DeviceField.WEIGHT.getByteLength());
            if (!Cools.isEmpty(weight) && staNo != 0) {
                StaProtocol staProtocol = station.get(staNo);
                StaProtocol staProtocol = stationMap.get(staNo);
                if (staProtocol == null) {
                    log.warn(" [id:{}] [staNo:{}]", slave.getId(), staNo);
                    continue;
@@ -259,7 +260,7 @@
    /**
     * 读取外形检测错误
     */
    private void readDimensionErrors() {
    private void readDimensionErrors(Map<Integer, StaProtocol> stationMap) {
        if (slave.getStaNosError() == null || !slave.getStaNosError()) {
            return;
        }
@@ -277,9 +278,9 @@
        for (int i = 0; i < DeviceField.DIMENSION_WORD.getArrLength(); i++) {
            int[] seg = DeviceField.DIMENSION_WORD.getSeg();
            int staNo = siemensS7Net.getByteTransform().TransInt16(
                    content, seg[0]);
                    content, seg[0] + i * DeviceField.DIMENSION_WORD.getByteLength());
            if (staNo != 0) {
                StaProtocol staProtocol = station.get(staNo);
                StaProtocol staProtocol = stationMap.get(staNo);
                if (staProtocol == null) {
                    log.warn("异常站点不存在 [id:{}] [staNo:{}]", slave.getId(), staNo);
                    continue;
@@ -309,7 +310,7 @@
    /**
     * 读取PLC故障信息
     */
    private void readPlcAlarms(List<Integer> staNos, int staNoSize) {
    private void readPlcAlarms(Map<Integer, StaProtocol> stationMap, List<Integer> staNos, int staNoSize) {
        OperateResultExOne<byte[]> result = siemensS7Net.Read(
                PlcAlarmDefinition.ALL.buildAddress(),
                (short) (staNoSize * PlcAlarmDefinition.ALL.getByteLength()));
@@ -322,7 +323,7 @@
        byte[] content = result.Content;
        for (int i = 0; i < staNoSize; i++) {
            Integer siteId = staNos.get(i);
            StaProtocol staProtocol = station.get(siteId);
            StaProtocol staProtocol = stationMap.get(siteId);
            if (staProtocol == null) {
                log.warn("站点不存在 [id:{}] [staNo:{}]", slave.getId(), siteId);
                continue;
@@ -345,7 +346,7 @@
    /**
     * 读取安全交互信号
     */
    private void readSaleSingle(List<DevpSlave.Sta> putSta, List<DevpSlave.Sta> takeSta) {
    private void readSaleSingle(Map<Integer, StaProtocol> stationMap, List<DevpSlave.Sta> putSta, List<DevpSlave.Sta> takeSta) {
        int staNoSize = putSta.size();
        OperateResultExOne<byte[]> result = siemensS7Net.Read(
                SafeSignalField.SAFE_SIGNAL_FROM_CONVEYOR.buildAddress(),
@@ -361,8 +362,8 @@
        for (int i = 0; i < staNoSize; i++) {
            Integer put = putSta.get(i).getStaNo();
            Integer take = takeSta.get(i).getStaNo();
            StaProtocol staProtocolPut = station.get(put);
            StaProtocol staProtocolTake = station.get(take);
            StaProtocol staProtocolPut = stationMap.get(put);
            StaProtocol staProtocolTake = stationMap.get(take);
            if (staProtocolPut == null || staProtocolTake == null) {
                log.warn("站点不存在 [id:{}] [staNo:{},{}]", slave.getId(), put, take);
                continue;
@@ -403,7 +404,7 @@
    /**
     * 按需更新数据库(降低更新频率)
     */
    private void updateDatabaseIfNeeded() {
    private void updateDatabaseIfNeeded(Map<Integer, StaProtocol> stationMap) {
        long currentTime = System.currentTimeMillis();
        if (currentTime - lastDbUpdateTime < DB_UPDATE_INTERVAL_MS) {
            return;
@@ -413,7 +414,7 @@
            List<Integer> staNos = slave.getStaNos();
            List<Devp> devps = new ArrayList<>(staNos.size());
            for (Integer siteId : staNos) {
                StaProtocol staProtocol = station.get(siteId);
                StaProtocol staProtocol = stationMap.get(siteId);
                if (staProtocol != null) {
                    devps.add(staProtocol.toSqlModel());
                }