| | |
| | | import com.kangaroohy.milo.model.ReadWriteEntity; |
| | | import com.kangaroohy.milo.runner.subscription.SubscriptionCallback; |
| | | import com.kangaroohy.milo.service.MiloService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | |
| | | @Slf4j |
| | | @Component |
| | | public class OPCUaSubscription implements SubscriptionCallback { |
| | | |
| | | private static final Logger logger = LoggerFactory.getLogger("sys-user"); |
| | | |
| | | public SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | |
| | |
| | | public List<String> automaticList = Arrays.asList("OP280","OP310A","OP310B", "OP300A","OP300B", "OP320A","OP320B", "OP340A","OP340B", "OP350A","OP350B", "OP360","OP365","OP370", "OP390", "OP470"); |
| | | |
| | | //采集模组工位 ModuleCode |
| | | public List<String> moduleCodeList = Arrays.asList("OP300A","OP300B","OP320A","OP320B","OP340A","OP340B","OP365", "OP350A", "OP350B", "OP330"); |
| | | public List<String> moduleCodeList = Arrays.asList("OP300A","OP310A","OP310B","OP300B","OP320A","OP320B","OP340A","OP340B","OP365", "OP350A", "OP350B", "OP330"); |
| | | |
| | | //区分模组型号工位 |
| | | public List<String> distinguishingModules = Arrays.asList("OP300","OP310", "OP340", "OP350", "OP330"); |
| | |
| | | @Override |
| | | public void onSubscribe(String identifier, Object value) { |
| | | |
| | | logger.info("地址:"+identifier+"值:"+value); |
| | | try { |
| | | if(null != value && Integer.valueOf(value.toString())!= 0) { |
| | | String[] nodes = identifier.split("[.]"); |
| | |
| | | } |
| | | }else { |
| | | //手动工位处理逻辑 |
| | | WebSocketUsers.sendMessageToUserByText(map.get(device), "IN"); |
| | | String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone"; |
| | | |
| | | miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(11).build()); |
| | | // if (map.containsKey(device)){ |
| | | WebSocketUsers.sendMessageToUserByText(map.get(device), "IN"); |
| | | String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone"; |
| | | miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(11).build()); |
| | | // } |
| | | } |
| | | |
| | | |
| | |
| | | miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(Integer.valueOf(recordDataDoneValue)).build()); |
| | | }else { |
| | | //手动工位 |
| | | if(device.contains("OP330")){ |
| | | String str = device.substring(0,5); |
| | | WebSocketUsers.sendMessageToUserByText(map.get(str), "END"); |
| | | }else { |
| | | // if(device.contains("OP330")){ |
| | | // String str = device.substring(0,5); |
| | | // WebSocketUsers.sendMessageToUserByText(map.get(str), "END"); |
| | | // }else { |
| | | WebSocketUsers.sendMessageToUserByText(map.get(device), "END"); |
| | | } |
| | | // } |
| | | if(testList.stream().anyMatch(s -> s.equals(device))){ |
| | | String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone"; |
| | | miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(21).build()); |
| | | // Object packCodeObject = miloService.readFromOpcUa(thoroughfare + "." + device + ".ModuleCode").getValue(); |
| | | // DaTestDeviceInterface deviceInterfaceOne = null; |
| | | // |
| | |
| | | // } else { |
| | | // writeToOpc(RecordDataDoneAddress, (short) 22); |
| | | // } |
| | | writeToOpc(RecordDataDoneAddress, (short) 21); |
| | | // writeToOpc(RecordDataDoneAddress, (short) 21); |
| | | } |
| | | |
| | | |
| | |
| | | List<Object> collect = list1.stream().map(ReadWriteEntity::getValue).collect(Collectors.toList()); |
| | | String joinedString = String.join(",", collect.toString()); |
| | | WebSocketUsers.sendMessageToUserByText(map.get(device), TightenTheConversionOkNg(joinedString)); |
| | | if(device.contains("270") || device.contains("260")){ |
| | | logger.info("读取到工位{}的Scaner数据:{}",device,TightenTheConversionOkNg(joinedString)); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | |
| | | logger.info("订阅方法报错:{}"+e.getMessage()); |
| | | logger.error("订阅方法报错",e); |
| | | } |
| | | } |
| | | |
| | |
| | | read = read + "ModuleCode"; |
| | | if(device.equals("OP365")){ |
| | | try { |
| | | // result = saveStationInfo365(thoroughfare,device); |
| | | // return result; |
| | | saveStationInfo365(thoroughfare,device); |
| | | // return result; |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | |
| | | result = "21"; |
| | | |
| | | } |
| | | |
| | | |
| | | }catch (Exception e) { |
| | | System.out.println(e.getMessage()); |
| | |
| | | * 保存过站采集 |
| | | */ |
| | | public void saveStationInfo365(String thoroughfare,String device) throws Exception { |
| | | String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone"; |
| | | String prefix = thoroughfare+"."+device+"."; |
| | | List<DaPassingStationCollection> passingStationCollections = new ArrayList<>(); |
| | | String ModuleCodeA = miloService.readFromOpcUa(prefix + "ModuleCodeA").getValue().toString(); |
| | | String ModuleCodeB = miloService.readFromOpcUa(prefix + "ModuleCodeB").getValue().toString(); |
| | | String StationStatusA = miloService.readFromOpcUa(prefix + "StationStatusA").getValue().toString(); |
| | | String StationStatusB = miloService.readFromOpcUa(prefix + "StationStatusB").getValue().toString(); |
| | | String[] modeles = {ModuleCodeA,ModuleCodeB}; |
| | | String[] StationStatus = {StationStatusA,StationStatusB}; |
| | | String ModuleCodeA = ""; |
| | | String ModuleCodeB = ""; |
| | | String StationStatusA = ""; |
| | | String StationStatusB = ""; |
| | | |
| | | String startTime = miloService.readFromOpcUa(prefix + "StartTime").getValue().toString(); |
| | | String stopTime = miloService.readFromOpcUa(prefix + "StopTime").getValue().toString(); |
| | | for (int i = 0; i < 2; i++) { |
| | | DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection(); |
| | | String strt = TimeUtil.stringProcessing(startTime); |
| | | String end = TimeUtil.stringProcessing(stopTime); |
| | | daPassingStationCollection.setInboundTime(format.parse(TimeUtil.test(strt)));//入站时间 |
| | | daPassingStationCollection.setOutboundTime(format.parse(TimeUtil.test(end)));//出站时间 |
| | | daPassingStationCollection.setSfcCode(modeles[i]); |
| | | daPassingStationCollection.setLocationCode(device); |
| | | daPassingStationCollection.setOutRsSign(StationStatus[i]);//出站是否合格 |
| | | passingStationCollections.add(daPassingStationCollection); |
| | | Object objectModuleCodeA = miloService.readFromOpcUa(prefix + "ModuleCodeA").getValue(); |
| | | Object objectModuleCodeB = miloService.readFromOpcUa(prefix + "ModuleCodeB").getValue(); |
| | | Object objectStationStatusA = miloService.readFromOpcUa(prefix + "StationStatusA").getValue(); |
| | | Object objectStationStatusB = miloService.readFromOpcUa(prefix + "StationStatusB").getValue(); |
| | | |
| | | if(ObjectUtil.isNotNull(objectModuleCodeA) && ObjectUtil.isNotNull(objectStationStatusA) && ObjectUtil.isNotNull(objectModuleCodeB) && ObjectUtil.isNotNull(objectStationStatusB)){ |
| | | ModuleCodeA = objectModuleCodeA.toString(); |
| | | ModuleCodeB = objectModuleCodeB.toString(); |
| | | StationStatusA = objectStationStatusA.toString(); |
| | | StationStatusB = objectStationStatusB.toString(); |
| | | |
| | | String[] modeles = {ModuleCodeA,ModuleCodeB}; |
| | | String[] StationStatus = {StationStatusA,StationStatusB}; |
| | | |
| | | String startTime = miloService.readFromOpcUa(prefix + "StartTime").getValue().toString(); |
| | | String stopTime = miloService.readFromOpcUa(prefix + "StopTime").getValue().toString(); |
| | | for (int i = 0; i < 2; i++) { |
| | | DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection(); |
| | | String strt = TimeUtil.stringProcessing(startTime); |
| | | String end = TimeUtil.stringProcessing(stopTime); |
| | | daPassingStationCollection.setInboundTime(format.parse(TimeUtil.test(strt)));//入站时间 |
| | | daPassingStationCollection.setOutboundTime(format.parse(TimeUtil.test(end)));//出站时间 |
| | | daPassingStationCollection.setSfcCode(modeles[i]); |
| | | daPassingStationCollection.setLocationCode(device); |
| | | daPassingStationCollection.setOutRsSign(StationStatus[i]);//出站是否合格 |
| | | passingStationCollections.add(daPassingStationCollection); |
| | | } |
| | | daPassingStationCollectionService.saveBeachDaPassingStationCollection(passingStationCollections); |
| | | miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(21).build()); |
| | | // return "21"; |
| | | }else { |
| | | miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(22).build()); |
| | | // return "22"; |
| | | } |
| | | daPassingStationCollectionService.saveBeachDaPassingStationCollection(passingStationCollections); |
| | | String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone"; |
| | | miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(21).build()); |
| | | return; |
| | | } |
| | | |
| | | private static void writeToOpc(String identifier, short value) { |