#
Junjie
2024-06-12 7180e7e7c548c78f327a9f66c2bc89af64039e7e
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/SiemensDevpThread.java
@@ -13,11 +13,8 @@
import com.zy.asrs.wcs.core.service.StationService;
import com.zy.asrs.wcs.core.utils.RedisUtil;
import com.zy.asrs.wcs.rcs.News;
import com.zy.asrs.wcs.rcs.cache.MessageQueue;
import com.zy.asrs.wcs.rcs.cache.OutputQueue;
import com.zy.asrs.wcs.rcs.entity.Device;
import com.zy.asrs.wcs.rcs.model.Task;
import com.zy.asrs.wcs.rcs.model.enums.SlaveType;
import com.zy.asrs.wcs.rcs.model.protocol.StaProtocol;
import com.zy.asrs.wcs.rcs.thread.DevpThread;
import lombok.extern.slf4j.Slf4j;
@@ -69,38 +66,21 @@
    @Override
    @SuppressWarnings("InfiniteLoopStatement")
    public void run() {
        connect();
        News.info("{}号输送线线程启动", device.getDeviceNo());
        this.connect();
        while (true) {
            try {
                int step = 1;
                Task task = MessageQueue.poll(SlaveType.Devp, device.getId().intValue());
                if (task != null) {
                    step = task.getStep();
                }
                switch (step) {
                    // 读数据
                    case 1:
                        read();
                        break;
                    default:
                        break;
                }
                // 心跳
//                heartbeat();
                Thread.sleep(400);
                read();
                Thread.sleep(500);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    private void read() throws InterruptedException {
        ArrayList<Station> staNos = getStaNo();
        int staNoSize = staNos.size();
        if (station.isEmpty()) {
            return;
        }
        OperateResultExOne<byte[]> result = siemensS7Net.Read("DB101.0", (short) (staNoSize*8));
        if (result.IsSuccess) {
            for (int i = 0; i < staNoSize; i++) {
@@ -132,20 +112,6 @@
            }
        }
        // 条码扫描器
        Thread.sleep(200);
        OperateResultExOne<byte[]> result2 = null;
        result2 = siemensS7Net.Read("DB101.840.0", (short) (barcodeSize * 8));
        if (result2.IsSuccess) {
            for (int i = 0; i < barcodeSize; i++) {
                String barcode = siemensS7Net.getByteTransform().TransString(result2.Content, i * 8, 8, "UTF-8");
//                BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, i + 1);
//                if (!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) {
//                    barcodeThread.setBarcode(barcode);
//                }
            }
        }
        Thread.sleep(200);
        ArrayList<Station> errorStaNo = getStaNo();
        OperateResultExOne<byte[]> result3 = siemensS7Net.Read("DB101.800.0", (short) (errorStaNo.size() * 4));
@@ -165,7 +131,7 @@
            }
        }
        if (result.IsSuccess && !Cools.isEmpty(result) && result.IsSuccess) {
        if (!Cools.isEmpty(result) && result.IsSuccess) {
            OutputQueue.DEVP.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), device.getId()));
@@ -264,6 +230,28 @@
    }
    @Override
    public boolean writeWorkSta(int siteId, short staNo, short workNo) {
        int index = findStaNosIndex(siteId);
        OperateResult write1 = siemensS7Net.Write("DB100." + index*6, workNo);    // 工作号
        OperateResult write2 = siemensS7Net.Write("DB100." + (index*6+4), staNo);    // 目标站
        if (!(write1.IsSuccess && write2.IsSuccess)) {
            StaProtocol staProtocol = station.get(siteId);
            if (staProtocol.getWorkNo() == 0 && staProtocol.getStaNo() ==0) {
                staProtocol.setPakMk(true);
            }
            OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线站点数据失败。输送线plc编号={1},站点数据={2}", device.getId(), JSON.toJSON(staProtocol)));
            log.error("写入输送线站点数据失败。输送线plc编号={},站点数据={}", device.getId(), JSON.toJSON(staProtocol));
        } else {
            OutputQueue.DEVP.offer(MessageFormat.format("【{0}】 输送线命令下发 [id:{1}] >>>>> {2}", DateUtils.convert(new Date()), device.getId(), JSON.toJSON(staNo)));
            log.info("输送线命令下发 [id:{}] >>>>> 命令下发: {}",  device.getId(), JSON.toJSON(staNo));
            return true;
        }
        return false;
    }
    @Override
    public Map<Integer, StaProtocol> getStation() {
        return this.station;
    }
@@ -281,4 +269,15 @@
        }
        return index;
    }
    /**
     * 设置入库标记
     */
    @Override
    public void setPakMk(Integer siteId, boolean pakMk) {
        StaProtocol staProtocol = station.get(siteId);
        if (null != staProtocol) {
            staProtocol.setPakMk(pakMk);
        }
    }
}