pang.jiabao
2026-04-24 7b8021d7ff94015d7034ead10fea5006d0032301
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,79 @@
    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>() {{
        add(1); add(2);
    // 站点
    public static final ArrayList<Integer> staNos1 = new ArrayList<Integer>() {{
        for(int i = 1 ;i <= 21; i ++) {add(1100+i);}
    }};
    public static final ArrayList<Integer> staNosErrList = new ArrayList<Integer>() {{
        add(104); add(106);
    public static final ArrayList<Integer> staNos2 = new ArrayList<Integer>() {{
        for(int i = 1 ;i <= 21; i ++) {add(1200+i);}
    }};
    public static final ArrayList<Integer> staNos3 = new ArrayList<Integer>() {{
        for(int i = 1 ;i <= 21; i ++) {add(1300+i);}
    }};
    public static final ArrayList<Integer> staNos4 = new ArrayList<Integer>() {{
        for(int i = 1 ;i <= 21; 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<>();
    }
    /**
     * 条码数量
     */
    private int barcodeSize = 2;
    // 条码扫描器
    public static final ArrayList<Integer> barcodeList1 = new ArrayList<Integer>(){{
        add(2);add(1);
    }};
    public static final ArrayList<Integer> barcodeList2 = new ArrayList<Integer>(){{
        add(3);
    }};
    public static final ArrayList<Integer> barcodeList3 = new ArrayList<Integer>(){{
        add(4);
    }};
    public static final ArrayList<Integer> barcodeList4 = new ArrayList<Integer>(){{
        add(6);add(5);
    }};
    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<>();
    }
    // 外形检测
    public static final ArrayList<Integer> shapeDetectionList1 = new ArrayList<Integer>(){{
        add(1112);add(1109);
    }};
    public static final ArrayList<Integer> shapeDetectionList2 = new ArrayList<Integer>(){{
        add(1209);
    }};
    public static final ArrayList<Integer> shapeDetectionList3 = new ArrayList<Integer>(){{
        add(1309);
    }};
    public static final ArrayList<Integer> shapeDetectionList4 = new ArrayList<Integer>(){{
        add(1407);add(1402);
    }};
    private ArrayList<Integer> getShapeDetectionList() {
        switch (this.slave.getId()) {
            case 1: return shapeDetectionList1;
            case 2: return shapeDetectionList2;
            case 3: return shapeDetectionList3;
            case 4: return shapeDetectionList4;
            default:
        }
        return new ArrayList<>();
    }
    /**
     * 入出库模式
@@ -72,10 +127,6 @@
    public SiemensDevpThread(DevpSlave slave) {
        this.slave = slave;
    }
    private ArrayList<Integer> getStaNo() {
        return staNos;
    }
    @Override
@@ -183,10 +234,10 @@
    private void read() {
        // 站点信息
        OperateResultExOne<byte[]> result = siemensS7Net.Read("DB101.0", (short) (8*8));
        OperateResultExOne<byte[]> result = siemensS7Net.Read("DB101.0", (short) (getStaNo().size()*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 +271,11 @@
        }
        // 条码扫描器
        OperateResultExOne<byte[]> barcodeResult = siemensS7Net.Read("DB101.400", (short) (BarcodeList.size() * 10));
        OperateResultExOne<byte[]> barcodeResult = siemensS7Net.Read("DB101.600", (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 +283,11 @@
        }
        // 外形检测
        OperateResultExOne<byte[]> resultErr = siemensS7Net.Read("DB101.430", (short) (staNosErrList.size() *4)); // 不连续,多读中间一个
        OperateResultExOne<byte[]> resultErr = siemensS7Net.Read("DB101.700", (short) (getShapeDetectionList().size() *6));
        if (resultErr.IsSuccess){
            for (int i = 0;i<staNosErrList.size();i++){
                boolean[] status = siemensS7Net.getByteTransform().TransBool(resultErr.Content, i*4, 1);
                StaProtocol staProtocol = station.get(staNosErrList.get(i));
            for (int i = 0;i<getShapeDetectionList().size();i++){
                boolean[] status = siemensS7Net.getByteTransform().TransBool(resultErr.Content, i*6+2, 1);
                StaProtocol staProtocol = station.get(getShapeDetectionList().get(i));
                staProtocol.setFrontErr(status[0]);
                staProtocol.setBackErr(status[1]);
                staProtocol.setHighErr(status[2]);
@@ -245,17 +296,17 @@
                staProtocol.setGroupSupportErr(status[5]);
                staProtocol.setBarcodeErr(status[6]);
                staProtocol.setWeightErr(status[7]);
                short goodsHeight = siemensS7Net.getByteTransform().TransInt16(resultErr.Content, i * 4 + 2);
                short goodsHeight = siemensS7Net.getByteTransform().TransInt16(resultErr.Content, i * 6 + 4);
                staProtocol.setGoodsHeight(goodsHeight);
            }
        }
        // 故障信息反馈
        OperateResultExOne<byte[]> resultErr2 = siemensS7Net.Read("DB101.442", (short) (staNos.size() * 4));
        OperateResultExOne<byte[]> resultErr2 = siemensS7Net.Read("DB101.400", (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 +326,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,15 +356,15 @@
            return;
        }
        int address = staNos.indexOf(staProtocol.getSiteId()) * 4;
        int address = getStaNo().indexOf(staProtocol.getSiteId()) * 6;
        OperateResult write;
        OperateResult write1;
        //任务下发次数
        int writeCount = 0;
        do {
            write = siemensS7Net.Write("DB100." + address, staProtocol.getWorkNo().shortValue());    // 工作号
            write1 = siemensS7Net.Write("DB100." + (address + 2), staProtocol.getStaNo());    // 目标站
            write = siemensS7Net.Write("DB100." + (address), staProtocol.getWorkNo());    // 工作号
            write1 = siemensS7Net.Write("DB100." + (address + 4), staProtocol.getStaNo());    // 目标站
            Thread.sleep(200);
            if(write.IsSuccess && write1.IsSuccess){
                break;