| | |
| | | package com.mes.job; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.github.xingshuangs.iot.protocol.s7.serializer.S7Serializer; |
| | | import com.kangaroohy.milo.model.ReadWriteEntity; |
| | | import com.kangaroohy.milo.service.MiloService; |
| | | import com.mes.glassinfo.entity.GlassInfo; |
| | | import com.mes.glassinfo.service.GlassInfoService; |
| | | import com.mes.s7.entity.S7DataMBExtra; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Qualifier; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.StringUtils; |
| | |
| | | @Autowired(required = false) |
| | | MiloService miloService; |
| | | |
| | | @Autowired |
| | | @Qualifier("s7SerializerMBExtra") |
| | | private S7Serializer s7SerializerMBExtra; |
| | | |
| | | @Resource |
| | | GlassInfoService glassInfoService; |
| | | |
| | |
| | | } |
| | | |
| | | private void startEdgTaskChild(String cell) throws Exception { |
| | | ReadWriteEntity request = miloService.readFromOpcUa("MB04.MB04.request" + cell); |
| | | if (null == request || "0".equals(request.getValue() + "")) { |
| | | S7DataMBExtra s7DataMBExtra = s7SerializerMBExtra.read(S7DataMBExtra.class); |
| | | |
| | | // ReadWriteEntity request = miloService.readFromOpcUa("MB04.MB04.request" + cell); |
| | | // if (null == request || "0".equals(request.getValue() + "")) { |
| | | String request = ""; |
| | | String glassIdEntity = ""; |
| | | if ("01".equals(cell)) { |
| | | request = s7DataMBExtra.getRequestOne().toString(); |
| | | glassIdEntity = s7DataMBExtra.getPlcGlassIdOne(); |
| | | } else { |
| | | request = s7DataMBExtra.getRequestTwo().toString(); |
| | | glassIdEntity = s7DataMBExtra.getPlcGlassIdTwo(); |
| | | } |
| | | if (null == request || "0".equals(request)) { |
| | | log.info("未收到玻璃请求,结束本次任务"); |
| | | return; |
| | | } |
| | | ReadWriteEntity glassIdEntity = miloService.readFromOpcUa("MB04.MB04.plc_glass_id_" + cell); |
| | | |
| | | if (null == glassIdEntity || StringUtils.isEmpty(glassIdEntity.getValue() + "")) { |
| | | // ReadWriteEntity glassIdEntity = miloService.readFromOpcUa("MB04.MB04.plc_glass_id_" + cell); |
| | | // if (null == glassIdEntity || StringUtils.isEmpty(glassIdEntity.getValue() + "")) { |
| | | if (null == glassIdEntity || StringUtils.isEmpty(glassIdEntity)) { |
| | | log.info("有请求但玻璃id为空,结束本次任务"); |
| | | return; |
| | | } |
| | | String glassId = glassIdEntity.getValue() + ""; |
| | | // String glassId = glassIdEntity.getValue() + ""; |
| | | String glassId = glassIdEntity; |
| | | log.info("获取到{}线的玻璃id:{}", cell, glassId); |
| | | GlassInfo glassInfo = glassInfoService.getOne(new LambdaQueryWrapper<GlassInfo>().eq(GlassInfo::getGlassId, glassId).last("limit 1")); |
| | | |
| | | List<ReadWriteEntity> ualist = new ArrayList<>(); |
| | | ualist.add(generateReadWriteEntity("MB04.MB04.width" + cell, (int) Math.max(glassInfo.getWidth() * 10, glassInfo.getHeight() * 10))); |
| | | ualist.add(generateReadWriteEntity("MB04.MB04.height" + cell, (int) Math.min(glassInfo.getWidth() * 10, glassInfo.getHeight() * 10))); |
| | | ualist.add(generateReadWriteEntity("MB04.MB04.thickness" + cell, (int) glassInfo.getThickness() * 10)); |
| | | miloService.writeToOpcWord(ualist); |
| | | miloService.writeToOpcUa(generateReadWriteEntity("MB04.MB04.mes_glass_Id_" + cell, glassId)); |
| | | // List<ReadWriteEntity> ualist = new ArrayList<>(); |
| | | // ualist.add(generateReadWriteEntity("MB04.MB04.width" + cell, (int) Math.max(glassInfo.getWidth() * 10, glassInfo.getHeight() * 10))); |
| | | // ualist.add(generateReadWriteEntity("MB04.MB04.height" + cell, (int) Math.min(glassInfo.getWidth() * 10, glassInfo.getHeight() * 10))); |
| | | // ualist.add(generateReadWriteEntity("MB04.MB04.thickness" + cell, (int) glassInfo.getThickness() * 10)); |
| | | // miloService.writeToOpcWord(ualist); |
| | | // miloService.writeToOpcUa(generateReadWriteEntity("MB04.MB04.mes_glass_Id_" + cell, glassId)); |
| | | |
| | | if ("01".equals(cell)) { |
| | | s7SerializerMBExtra.write( |
| | | S7DataMBExtra.builder() |
| | | .widthOne((short) Math.max(glassInfo.getWidth() * 10, glassInfo.getHeight() * 10)) |
| | | .heightOne((short) Math.min(glassInfo.getWidth() * 10, glassInfo.getHeight() * 10)) |
| | | .thicknessOne((short) (glassInfo.getThickness() * 10)) |
| | | .build() |
| | | ); |
| | | s7SerializerMBExtra.write( |
| | | S7DataMBExtra.builder().mesGlassIdOne(glassId).build() |
| | | ); |
| | | } else { |
| | | s7SerializerMBExtra.write( |
| | | S7DataMBExtra.builder() |
| | | .widthTwo((short) Math.max(glassInfo.getWidth() * 10, glassInfo.getHeight() * 10)) |
| | | .heightTwo((short) Math.min(glassInfo.getWidth() * 10, glassInfo.getHeight() * 10)) |
| | | .thicknessTwo((short) (glassInfo.getThickness() * 10)) |
| | | .build() |
| | | ); |
| | | s7SerializerMBExtra.write( |
| | | S7DataMBExtra.builder().mesglassIdTwo(glassId).build() |
| | | ); |
| | | } |
| | | } |
| | | |
| | | private ReadWriteEntity generateReadWriteEntity(String identifier, Object value) { |