| | |
| | | import lombok.Data; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | // 读取条码 |
| | | readBarcodes(); |
| | | |
| | | // 称重 |
| | | readWeight(); |
| | | |
| | | // 读取外形检测错误 |
| | | readDimensionErrors(); |
| | | |
| | |
| | | |
| | | if (!Cools.isEmpty(barcode)) { |
| | | StaProtocol staProtocol = station.get(barcodeArr.get(i)); |
| | | if (staProtocol == null) { |
| | | continue; |
| | | } |
| | | staProtocol.setBarcode(barcode); |
| | | News.info("料箱码:{}", barcode); |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * 读取条码信息 |
| | | */ |
| | | private void readWeight() { |
| | | List<Integer> weightArr = slave.getWeightArr(); |
| | | if (weightArr == null || weightArr.isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | OperateResultExOne<byte[]> result = siemensS7Net.Read( |
| | | DeviceField.WEIGHT.buildAddress(), |
| | | (short) (weightArr.size() * 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) { |
| | | continue; |
| | | } |
| | | double weight = siemensS7Net.getByteTransform().TransSingle(result.Content, i * 4); |
| | | staProtocol.setWeight(BigDecimal.valueOf(weight).setScale(2, RoundingMode.HALF_UP).doubleValue()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 读取外形检测错误 |
| | | */ |
| | | private void readDimensionErrors() { |