From b3280d431ea42f46afe020782b677b11d504be31 Mon Sep 17 00:00:00 2001
From: 1 <1>
Date: 星期三, 14 一月 2026 13:32:38 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/thread/SiemensDevpThread.java |  162 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 162 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/SiemensDevpThread.java b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
index c2ea24f..b605d29 100644
--- a/src/main/java/com/zy/core/thread/SiemensDevpThread.java
+++ b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -1010,6 +1010,168 @@
             News.info("SiemensDevp"+" - 5"+" - 杈撻�佺嚎鍛戒护涓嬪彂 [id:{}] >>>>> 鍛戒护涓嬪彂锛� {}",  slave.getId(), JSON.toJSON(staProtocol));
         }
     }
+//    /**
+//     * 鍐欏叆 ID + 鐩爣绔� =====> 鍗曠珯鐐瑰啓鍏ワ紙甯﹁鍥炴牎楠� + 閲嶈瘯鏈哄埗锛�
+//     */
+//    private void write(StaProtocol staProtocol) throws InterruptedException {
+//        if (staProtocol == null) {
+//            return;
+//        }
+//
+//        Integer siteId = staProtocol.getSiteId();
+//        Integer offset = siteOffsetMap.get(siteId);
+//        if (offset == null) {
+//            log.warn("绔欑偣 {} 娌℃湁瀹氫箟鍋忕Щ閲忥紝璺宠繃鍐欏叆", siteId);
+//            return;
+//        }
+//
+//        Integer offset2 = getOffsetBySiteId(siteId);
+//        Integer offset3 = getOffsetBySiteId2(siteId); // 铏界劧鏈柟娉曚富瑕佺敤涓嶅埌锛屼絾淇濈暀浠ラ槻鍚庣画鎵╁睍
+//
+//        // 鍑嗗鏈熸湜鍐欏叆鐨勫�硷紙鐢ㄤ簬鍚庣画姣斿锛�
+//        final long expectWorkNo = staProtocol.getWorkNo();
+//        final long expectStaNo = staProtocol.getStaNo() != null ? staProtocol.getStaNo().intValue() : 0;
+//
+//        boolean isSpecial2 = specialSites2.contains(siteId);
+//        final long expectStaNoOffset = isSpecial2 ? (offset + offset2 + 48) : (offset + offset2 + 12);
+//
+//        // 纭畾瑕佹搷浣滅殑 DB 鍧�
+//        String dbName;
+//        if (siteId < 1029) {
+//            dbName = "DB100.";
+//        } else if (siteId < 1042) {
+//            dbName = "DB101.";
+//        } else if (siteId < 1054) {
+//            dbName = "DB104.";
+//        } else if (siteId < 1080) {
+//            dbName = "DB103.";
+//        } else if (siteId < 1111) {
+//            dbName = "DB102.";
+//        } else if (siteId < 2031) {
+//            dbName = "DB200.";
+//        } else if (siteId < 2121) {
+//            dbName = "DB201.";
+//        } else if (siteId < 4000) {
+//            // 2妤糚DA鏉$爜绔欑偣鐗规畩澶勭悊锛堢洰鍓嶄笉鍋氳鍥為噸璇曪級
+//            Integer offsetBarcode = site2lBarcodeOffsetMap.get(siteId);
+//            if (offsetBarcode == null) {
+//                log.warn("绔欑偣 {} 娌℃湁瀹氫箟2妤兼潯鐮佸亸绉婚噺锛岃烦杩囨潯鐮佸啓鍏�", siteId);
+//                return;
+//            }
+//            OperateResult writeBarcode = siemensS7Net.Write("DB202." + offsetBarcode, staProtocol.getBarcode());
+//            if (writeBarcode.IsSuccess) {
+//                log.info("2妤糚DA鏉$爜鍐欏叆鎴愬姛 site={}, barcode={}", siteId, staProtocol.getBarcode());
+//            } else {
+//                log.error("2妤糚DA鏉$爜鍐欏叆澶辫触 site={}, barcode={}", siteId, staProtocol.getBarcode());
+//            }
+//            return;
+//        } else {
+//            dbName = "DB400.";
+//        }
+//
+//        String addrWorkNo = dbName + (offset + offset2);
+//        String addrStaNo = dbName + expectStaNoOffset;
+//
+//        int maxRetry = 5;
+//        int tryCount = 0;
+//        boolean success = false;
+//
+//        while (tryCount < maxRetry && !success) {
+//            tryCount++;
+//
+//            // 1. 灏濊瘯鍐欏叆
+//            OperateResult writeWork = siemensS7Net.Write(addrWorkNo, expectWorkNo);
+//            writeWork = siemensS7Net.Write("DB100." + (offset + offset2), staProtocol.getWorkNo());    // 宸ヤ綔鍙�
+//
+//            Thread.sleep(80);
+//
+//            OperateResult writeSta = siemensS7Net.Write(addrStaNo, expectStaNo);
+//            Thread.sleep(120);
+//
+//            if (!writeWork.IsSuccess || !writeSta.IsSuccess) {
+//                log.warn("绗瑊}娆″啓鍏ュけ璐� site={}, workNo={}, targetSta={}",
+//                        tryCount, siteId, expectWorkNo, expectStaNo);
+//                Thread.sleep(300);
+//                continue;
+//            }
+//
+//            // 2. 璇诲洖鏍¢獙锛堣嚦灏戣64瀛楄妭锛岀‘淇濊鐩栨墍闇�瀛楁锛�
+//            OperateResultExOne<byte[]> readResult = siemensS7Net.Read(dbName + (offset + offset2), (short) 64);
+//            if (!readResult.IsSuccess || readResult.Content == null || readResult.Content.length < 64) {
+//                log.warn("绗瑊}娆¤鍥炲け璐ワ紝鏃犳硶鏍¢獙 site={}", tryCount, siteId);
+//                Thread.sleep(300);
+//                continue;
+//            }
+//
+//            byte[] data = readResult.Content;
+//
+//            // 璁$畻鐩稿鍋忕Щ杩涜璇诲彇
+//            int relativeWorkNoOffset = 0;
+//            int relativeStaNoOffset = (int) (expectStaNoOffset - (offset + offset2));
+//
+//            int actualWorkNo = siemensS7Net.getByteTransform().TransInt32(data, relativeWorkNoOffset);
+//            int actualStaNo = siemensS7Net.getByteTransform().TransInt32(data, relativeStaNoOffset);
+//
+//            boolean match = (actualWorkNo == expectWorkNo) && (actualStaNo == expectStaNo);
+//
+//            if (match) {
+//                success = true;
+//                log.info("鍐欏叆骞舵牎楠屾垚鍔� site={}, workNo={}, targetSta={}, 绗瑊}娆″皾璇�",
+//                        siteId, expectWorkNo, expectStaNo, tryCount);
+//            } else {
+//                log.warn("绗瑊}娆℃牎楠屽け璐� site={}, 鏈熸湜[workNo={},staNo={}], 瀹為檯[workNo={},staNo={}]",
+//                        tryCount, siteId, expectWorkNo, expectStaNo, actualWorkNo, actualStaNo);
+//                Thread.sleep(300);
+//            }
+//        }
+//
+//        // 鏈�缁堢粨鏋滃鐞�
+//        if (success) {
+//            log.info("杈撻�佺嚎鍛戒护涓嬪彂骞舵牎楠屾垚鍔� [plc:{}] site:{} workNo:{} target:{}",
+//                    slave.getId(), siteId, expectWorkNo, expectStaNo);
+//
+//            OutputQueue.DEVP.offer(MessageFormat.format(
+//                    "銆恵0}銆戣緭閫佺嚎鍛戒护涓嬪彂骞舵牎楠屾垚鍔� [id:{1}] >>>>> site:{2} workNo:{3} target:{4}",
+//                    DateUtils.convert(new Date()), slave.getId(), siteId, expectWorkNo, expectStaNo));
+//
+//            News.info("SiemensDevp - 5 - 杈撻�佺嚎鍛戒护涓嬪彂骞舵牎楠屾垚鍔� [id:{}] >>>>> {}",
+//                    slave.getId(), JSON.toJSON(staProtocol));
+//        } else {
+//            log.error("缁忚繃{}娆″皾璇曪紝鍐欏叆骞舵牎楠屼粛鐒跺け璐ワ紒plc={} site={} workNo棰勬湡={} target棰勬湡={}",
+//                    maxRetry, slave.getId(), siteId, expectWorkNo, expectStaNo);
+//
+//            OutputQueue.DEVP.offer(MessageFormat.format(
+//                    "銆恵0}銆戠粡杩噞1}娆″皾璇曪紝杈撻�佺嚎鍐欏叆鏍¢獙澶辫触锛� [id:{2}] site:{3} workNo:{4} target:{5}",
+//                    DateUtils.convert(new Date()), maxRetry, slave.getId(), siteId, expectWorkNo, expectStaNo));
+//
+//            News.error("SiemensDevp - 4 - 澶氭灏濊瘯鍚庡啓鍏ユ牎楠屽け璐ワ紒site={} workNo={} target={}",
+//                    siteId, expectWorkNo, expectStaNo);
+//        }
+//
+//        // 鎿嶄綔鏃ュ織璁板綍锛堟棤璁烘垚鍔熷け璐ラ兘璁板綍锛�
+//        try {
+//            BasDevpOptService bean = SpringUtils.getBean(BasDevpOptService.class);
+//            BasDevpOpt basDevpOpt = new BasDevpOpt(
+//                    staProtocol.getWorkNo(),
+//                    new Date(),
+//                    staProtocol.getSiteId(),
+//                    (int) staProtocol.getStaNo(),
+//                    new Date(),
+//                    String.valueOf(staProtocol.isLoading()),
+//                    staProtocol.getBarcode(),
+//                    staProtocol.isFrontErr() ? 1L : 0L,
+//                    staProtocol.isBackErr() ? 1L : 0L,
+//                    staProtocol.isHighErr() ? 1L : 0L,
+//                    staProtocol.isLeftErr() ? 1L : 0L,
+//                    staProtocol.isRightErr() ? 1L : 0L,
+//                    staProtocol.isBarcodeErr() ? 1L : 0L,
+//                    staProtocol.getErrCode()
+//            );
+//            bean.insert(basDevpOpt);
+//        } catch (Exception e) {
+//            log.warn("鍐欏叆鎿嶄綔鏃ュ織澶辫触 site={}", siteId, e);
+//        }
+//    }
 
     // 鏇存柊鍏ュ嚭搴撴ā寮�
     private void updateIoMode() throws InterruptedException {

--
Gitblit v1.9.1