1
zhang
2 天以前 ccc7db768baea9df601574a9e2afd52a26a8577d
zy-asc-conveyor/src/main/java/com/zy/acs/conveyor/core/thread/SiemensDevpThread.java
@@ -158,14 +158,13 @@
     * 读取条码信息
     */
    private void readBarcodes() {
        List<Integer> barcodeArr = slave.getBarcodeArr();
        if (barcodeArr == null || barcodeArr.isEmpty()) {
        if (slave.getBarcode() == null || !slave.getBarcode()) {
            return;
        }
        OperateResultExOne<byte[]> result = siemensS7Net.Read(
                DeviceField.BARCODE.buildAddress(),
                (short) (barcodeArr.size() * DeviceField.BARCODE.getByteLength()));
                (short) (DeviceField.BARCODE.getByteLength() * DeviceField.BARCODE.getArrLength()));
        if (!result.IsSuccess) {
            log.warn("读取条码失败 [id:{}]", slave.getId());
@@ -173,15 +172,18 @@
        }
        byte[] content = result.Content;
        for (int i = 0; i < barcodeArr.size(); i++) {
        for (int i = 0; i < DeviceField.BARCODE.getArrLength(); i++) {
            int[] seg = DeviceField.BARCODE.getSeg();
            int staNo = siemensS7Net.getByteTransform().TransInt16(
                    content, seg[0] + i * DeviceField.BARCODE.getByteLength());
            String barcode = siemensS7Net.getByteTransform().TransString(
                    content, i * DeviceField.BARCODE.getByteLength(),
                    DeviceField.BARCODE.getByteLength(), "UTF-8");
                    content, seg[1] + i * DeviceField.BARCODE.getByteLength(),
                    DeviceField.BARCODE.getByteLength() - seg[1], "UTF-8");
            if (!Cools.isEmpty(barcode)) {
                StaProtocol staProtocol = station.get(barcodeArr.get(i));
            if (!Cools.isEmpty(barcode) && staNo != 0) {
                StaProtocol staProtocol = station.get(staNo);
                if (staProtocol == null) {
                    log.warn("站点不存在 [id:{}] [staNo:{}]", slave.getId(), barcodeArr.get(i));
                    log.warn("扫码站点不存在 [id:{}] [staNo:{}]", slave.getId(), staNo);
                    continue;
                }
                staProtocol.setBarcode(barcode);
@@ -191,30 +193,36 @@
    }
    /**
     * 读取条码信息
     * 读取重量信息
     */
    private void readWeight() {
        List<Integer> weightArr = slave.getWeightArr();
        if (weightArr == null || weightArr.isEmpty()) {
        if (slave.getWeight() == null || !slave.getWeight()) {
            return;
        }
        OperateResultExOne<byte[]> result = siemensS7Net.Read(
                DeviceField.WEIGHT.buildAddress(),
                (short) (weightArr.size() * DeviceField.WEIGHT.getByteLength()));
                (short) (DeviceField.WEIGHT.getArrLength() * DeviceField.WEIGHT.getByteLength()));
        if (!result.IsSuccess) {
            log.warn("读取重量失败 [id:{}]", slave.getId());
            return;
        }
        for (int i = 0; i < weightArr.size(); i++) {
            StaProtocol staProtocol = station.get(weightArr.get(i));
            if (staProtocol == null) {
                log.warn("站点不存在 [id:{}] [staNo:{}]", slave.getId(), weightArr.get(i));
                continue;
        byte[] content = result.Content;
        for (int i = 0; i < DeviceField.WEIGHT.getArrLength(); i++) {
            int[] seg = DeviceField.WEIGHT.getSeg();
            int staNo = siemensS7Net.getByteTransform().TransInt16(
                    content, seg[0] + i * DeviceField.WEIGHT.getByteLength());
            Double weight = (double) siemensS7Net.getByteTransform().TransSingle(
                    content, seg[1] + i * DeviceField.WEIGHT.getByteLength());
            if (!Cools.isEmpty(weight) && staNo != 0) {
                StaProtocol staProtocol = station.get(staNo);
                if (staProtocol == null) {
                    log.warn("称重站点不存在 [id:{}] [staNo:{}]", slave.getId(), staNo);
                    continue;
                }
                staProtocol.setWeight(BigDecimal.valueOf(weight).setScale(4, RoundingMode.HALF_UP).doubleValue());
            }
            double weight = siemensS7Net.getByteTransform().TransSingle(result.Content, i * DeviceField.WEIGHT.getByteLength());
            staProtocol.setWeight(BigDecimal.valueOf(weight).setScale(4, RoundingMode.HALF_UP).doubleValue());
        }
    }
@@ -222,14 +230,13 @@
     * 读取外形检测错误
     */
    private void readDimensionErrors() {
        List<Integer> staNosError = slave.getStaNosError();
        if (staNosError == null || staNosError.isEmpty()) {
        if (slave.getStaNosError() == null || !slave.getStaNosError()) {
            return;
        }
        OperateResultExOne<byte[]> result = siemensS7Net.Read(
                DeviceField.DIMENSION_WORD.buildAddress(),
                (short) (staNosError.size() * DeviceField.DIMENSION_WORD.getByteLength()));
                (short) (DeviceField.DIMENSION_WORD.getArrLength() * DeviceField.DIMENSION_WORD.getByteLength()));
        if (!result.IsSuccess) {
            log.warn("读取外形检测错误失败 [id:{}]", slave.getId());
@@ -237,30 +244,35 @@
        }
        byte[] content = result.Content;
        for (int i = 0; i < staNosError.size(); i++) {
            Integer siteId = staNosError.get(i);
            StaProtocol staProtocol = station.get(siteId);
            if (staProtocol == null){
                log.warn("站点不存在 [id:{}] [staNo:{}]", slave.getId(), staNosError.get(i));
                continue;
        for (int i = 0; i < DeviceField.DIMENSION_WORD.getArrLength(); i++) {
            int[] seg = DeviceField.DIMENSION_WORD.getSeg();
            int staNo = siemensS7Net.getByteTransform().TransInt16(
                    content, seg[0]);
            if (staNo != 0) {
                StaProtocol staProtocol = station.get(staNo);
                if (staProtocol == null) {
                    log.warn("异常站点不存在 [id:{}] [staNo:{}]", slave.getId(), staNo);
                    continue;
                }
                boolean[] status = siemensS7Net.getByteTransform().TransBool(
                        content, seg[1] + i * DeviceField.DIMENSION_WORD.getByteLength(),
                        1);
//未使用,预留
//                boolean[] status1 = siemensS7Net.getByteTransform().TransBool(
//                        content, seg[1]+i * DeviceField.DIMENSION_WORD.getByteLength()+1,
//                        1);
                staProtocol.setLeftErr(status[0]);
                staProtocol.setRightErr(status[1]);
                staProtocol.setFrontErr(status[2]);
                staProtocol.setBackErr(status[3]);
                staProtocol.setHighErr(status[4]);
                staProtocol.setLoadErr(status[5]);
                staProtocol.setWeightErr(status[6]);
                staProtocol.setBarcodeErr(status[7]);
            }
            short i1 = siemensS7Net.getByteTransform().TransInt16(
                    content, 0);
            boolean[] status = siemensS7Net.getByteTransform().TransBool(
                    content, 2+i * DeviceField.DIMENSION_WORD.getByteLength(),
                    1);
            boolean[] status1 = siemensS7Net.getByteTransform().TransBool(
                    content, 2+i * DeviceField.DIMENSION_WORD.getByteLength()+1,
                    1);
            staProtocol.setFrontErr(status[0]);
            staProtocol.setBackErr(status[1]);
            staProtocol.setHighErr(status[2]);
            staProtocol.setLeftErr(status[3]);
            staProtocol.setRightErr(status[4]);
            staProtocol.setWeightErr(status[5]);
            staProtocol.setBarcodeErr(status[6]);
        }
    }