pang.jiabao
2026-04-14 e0865876435877f8f53d62a4a93c71cb1ac004db
src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -25,10 +25,7 @@
import lombok.extern.slf4j.Slf4j;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
/**
@@ -44,21 +41,54 @@
    private Map<Integer, StaProtocol> station = new ConcurrentHashMap<>();
    private short heartBeatVal = 1;
    private StaError1 staError1;
    public static final ArrayList<Integer> staNos = new ArrayList<Integer>() {{
        add(101);add(102);add(103);add(104);add(105);add(106);add(107);add(108);
    }};
    public static final ArrayList<Integer> BarcodeList = new ArrayList<Integer>() {{
    // 站点
    public static final ArrayList<Integer> staNos1 = new ArrayList<Integer>() {{
        for(int i = 1 ;i <= 20; i ++) {add(1100+i);}
    }};
    public static final ArrayList<Integer> staNos2 = new ArrayList<Integer>() {{
        for(int i = 1 ;i <= 20; i ++) {add(1200+i);}
    }};
    public static final ArrayList<Integer> staNos3 = new ArrayList<Integer>() {{
        for(int i = 1 ;i <= 20; i ++) {add(1300+i);}
    }};
    public static final ArrayList<Integer> staNos4 = new ArrayList<Integer>() {{
        for(int i = 1 ;i <= 20; i ++) {add(1400+i);}
    }};
    private ArrayList<Integer> getStaNo() {
        switch (this.slave.getId()) {
            case 1: return staNos1;
            case 2: return staNos2;
            case 3: return staNos3;
            case 4: return staNos4;
            default:
        }
        return new ArrayList<>();
    }
    // 条码扫描器
    public static final ArrayList<Integer> barcodeList1 = new ArrayList<Integer>(){{
        add(1); add(2);
    }};
    public static final ArrayList<Integer> staNosErrList = new ArrayList<Integer>() {{
        add(104); add(106);
    public static final ArrayList<Integer> barcodeList2 = new ArrayList<Integer>(){{
        add(3);
    }};
    /**
     * 条码数量
     */
    private int barcodeSize = 2;
    public static final ArrayList<Integer> barcodeList3 = new ArrayList<Integer>(){{
        add(4);
    }};
    public static final ArrayList<Integer> barcodeList4 = new ArrayList<Integer>(){{
        add(5);add(6);
    }};
    private ArrayList<Integer> getBarcodeList() {
        switch (this.slave.getId()) {
            case 1: return barcodeList1;
            case 2: return barcodeList2;
            case 3: return barcodeList3;
            case 4: return barcodeList4;
            default:
        }
        return new ArrayList<>();
    }
    /**
     * 入出库模式
@@ -72,10 +102,6 @@
    public SiemensDevpThread(DevpSlave slave) {
        this.slave = slave;
    }
    private ArrayList<Integer> getStaNo() {
        return staNos;
    }
    @Override
@@ -185,8 +211,8 @@
        // 站点信息
        OperateResultExOne<byte[]> result = siemensS7Net.Read("DB101.0", (short) (8*8));
        if (result.IsSuccess) {
            for (int i = 0; i < staNos.size(); i++) {
                Integer siteId = staNos.get(i); // 站点编号
            for (int i = 0; i < getStaNo().size(); i++) {
                Integer siteId = getStaNo().get(i); // 站点编号
                StaProtocol staProtocol = station.get(siteId);
                if (null == staProtocol) {
                    staProtocol = new StaProtocol();
@@ -220,11 +246,11 @@
        }
        // 条码扫描器
        OperateResultExOne<byte[]> barcodeResult = siemensS7Net.Read("DB101.400", (short) (BarcodeList.size() * 10));
        OperateResultExOne<byte[]> barcodeResult = siemensS7Net.Read("DB101.400", (short) (getBarcodeList().size() * 10));
        if (barcodeResult.IsSuccess) {
            for (int i = 0; i < BarcodeList.size(); i++) {
            for (int i = 0; i < getBarcodeList().size(); i++) {
                String barcode = siemensS7Net.getByteTransform().TransString(barcodeResult.Content,i*10 + 2,8, "UTF-8");
                BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, BarcodeList.get(i));
                BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, getBarcodeList().get(i));
                if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) {
                    barcodeThread.setBarcode(barcode);
                }
@@ -232,11 +258,11 @@
        }
        // 外形检测
        OperateResultExOne<byte[]> resultErr = siemensS7Net.Read("DB101.430", (short) (staNosErrList.size() *4)); // 不连续,多读中间一个
        OperateResultExOne<byte[]> resultErr = siemensS7Net.Read("DB101.430", (short) (getStaNo().size() *4)); // 不连续,多读中间一个
        if (resultErr.IsSuccess){
            for (int i = 0;i<staNosErrList.size();i++){
            for (int i = 0;i<getStaNo().size();i++){
                boolean[] status = siemensS7Net.getByteTransform().TransBool(resultErr.Content, i*4, 1);
                StaProtocol staProtocol = station.get(staNosErrList.get(i));
                StaProtocol staProtocol = station.get(getStaNo().get(i));
                staProtocol.setFrontErr(status[0]);
                staProtocol.setBackErr(status[1]);
                staProtocol.setHighErr(status[2]);
@@ -251,11 +277,11 @@
        }
        // 故障信息反馈
        OperateResultExOne<byte[]> resultErr2 = siemensS7Net.Read("DB101.442", (short) (staNos.size() * 4));
        OperateResultExOne<byte[]> resultErr2 = siemensS7Net.Read("DB101.442", (short) (getStaNo().size() * 4));
        if (resultErr2.IsSuccess) {
            for (int i = 0; i < staNos.size(); i++) {
            for (int i = 0; i < getStaNo().size(); i++) {
                boolean[] status = siemensS7Net.getByteTransform().TransBool(resultErr2.Content, i*4 + 2, 1);
                StaProtocol staProtocol = station.get(staNos.get(i)); // 站点编号
                StaProtocol staProtocol = station.get(getStaNo().get(i)); // 站点编号
                staProtocol.setBreakerErr(status[0]);
                staProtocol.setInfraredErr(status[1]);
                staProtocol.setOutTimeErr(status[2]);
@@ -275,7 +301,7 @@
            // 根据实时信息更新数据库
            try {
                List<BasDevp> basDevps = new ArrayList<>();
                for (Integer siteId : staNos) {
                for (Integer siteId : getStaNo()) {
                    StaProtocol staProtocol = station.get(siteId);
                    basDevps.add(staProtocol.toSqlModel());
                }
@@ -305,7 +331,7 @@
            return;
        }
        int address = staNos.indexOf(staProtocol.getSiteId()) * 4;
        int address = getStaNo().indexOf(staProtocol.getSiteId()) * 4;
        OperateResult write;
        OperateResult write1;