| | |
| | | package com.mes.job; |
| | | |
| | | import com.github.xingshuangs.iot.common.buff.ByteReadBuff; |
| | | import com.github.xingshuangs.iot.common.buff.EByteBuffFormat; |
| | | import com.github.xingshuangs.iot.protocol.modbus.service.ModbusTcp; |
| | | import com.github.xingshuangs.iot.utils.ByteUtil; |
| | | import com.kangaroohy.milo.model.ReadWriteEntity; |
| | | import com.kangaroohy.milo.service.MiloService; |
| | | import com.mes.hollow.entity.vo.HollowGlassFormulaVO; |
| | |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.nio.charset.Charset; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | |
| | | hollowRemoveChildTask("CMJ2.CMJ2."); |
| | | } |
| | | |
| | | public String readString(ModbusTcp modbusTcp, int address) { |
| | | // |
| | | byte[] bytes = new byte[20]; |
| | | for (int i = 0; i < 10; i++) { |
| | | int res = modbusTcp.readUInt16(address + i); |
| | | |
| | | bytes[i * 2 + 1] = (byte) ((res >> 8) & 0xFF); |
| | | bytes[i * 2] = (byte) (res & 0xFF); |
| | | } |
| | | int endIndex = 0; |
| | | while (endIndex < bytes.length) { |
| | | if (bytes[endIndex] == 0) { |
| | | break; |
| | | } |
| | | endIndex++; |
| | | } |
| | | // 截取有效部分 |
| | | return new String(bytes, 0, endIndex); |
| | | } |
| | | |
| | | private void hollowRemoveChildTask(String cell) throws Exception { |
| | | ModbusTcp modbusTcp = null; |
| | | if ("CMJ1.CMJ1.".equals(cell)) { |
| | |
| | | log.info("除膜机{}未连接", cell); |
| | | return; |
| | | } |
| | | String glassIdEntitys = readString(modbusTcp, 42003 - offset); |
| | | log.info("除膜{}获取当前的玻璃id:{}", cell, glassIdEntitys); |
| | | // byte[] res = CMJ1ModbusTcp.readHoldRegister(1, 42003, 14); |
| | | // String glassId1 = ByteReadBuff.newInstance(res, 0, false, EByteBuffFormat.CD_AB).getString(10); |
| | | // String glassId2 = ByteReadBuff.newInstance(res, 0, false, EByteBuffFormat.AB_CD).getString(10); |
| | | // String glassId3 = ByteReadBuff.newInstance(res, 0, false, EByteBuffFormat.BA_DC).getString(10); |
| | | // String glassId4 = ByteReadBuff.newInstance(res, 0, false, EByteBuffFormat.DC_BA).getString(10); |
| | | // log.info("获取{}当前的玻璃id1:{}", cell, glassId1); |
| | | // log.info("获取{}当前的玻璃id2:{}", cell, glassId2); |
| | | // log.info("获取{}当前的玻璃id3:{}", cell, glassId3); |
| | | // log.info("获取{}当前的玻璃id4:{}", cell, glassId4); |
| | | Integer requestEntity = modbusTcp.readUInt16(42001 - offset); |
| | | // ReadWriteEntity requestEntity = miloService.readFromOpcUa(cell + "mesControl"); |
| | | // if ("0".equals(requestEntity.getValue() + "")) { |
| | |
| | | log.info("当前未收到请求玻璃id数据,结束任务"); |
| | | return; |
| | | } |
| | | String glassIdEntity = modbusTcp.readString(42003 - offset, 20); |
| | | |
| | | |
| | | // String glassIdEntity = modbusTcp.readString(42003 - offset, 20); |
| | | String glassIdEntity = readString(modbusTcp, 42003 - offset); |
| | | // String glassIdEntity = ByteReadBuff.newInstance(res, 0, false, EByteBuffFormat.CD_AB).getString(10); |
| | | //你删了? |
| | | log.info("除膜{}获取当前的信号为:{},玻璃id:{}", cell, flagRequest, glassIdEntity); |
| | | if (null == glassIdEntity || StringUtils.isBlank(glassIdEntity)) { |
| | | // ReadWriteEntity glassIdEntity = miloService.readFromOpcUa(cell + "glassId"); |