-
admin
2024-05-17 68f0c8f92fb7c82dc447b9aaed2d23760c546f25
jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java
@@ -3,6 +3,7 @@
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -16,6 +17,8 @@
import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService;
import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection;
import com.jcdm.main.da.passingStationCollection.service.IDaPassingStationCollectionService;
import com.jcdm.main.da.testDeviceInterface.domain.DaTestDeviceInterface;
import com.jcdm.main.da.testDeviceInterface.service.IDaTestDeviceInterfaceService;
import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfo;
import com.jcdm.main.om.productionOrde.service.IOmProductionOrdeInfoService;
import com.jcdm.main.plcserver.conf.OPCElement;
@@ -42,7 +45,7 @@
    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");
@@ -74,16 +77,21 @@
    public static IOmProductionOrdeInfoService omProductionOrdeInfoService;
    private static IDaTestDeviceInterfaceService daTestDeviceInterfaceService;
    public OPCUaSubscription(MiloService miloService,
                             IDaPassingStationCollectionService daPassingStationCollectionService,
                             IDaCollectionParamConfService collectionParamConfService,
                             IDaParamCollectionService daParamCollectionService,
                             IOmProductionOrdeInfoService omProductionOrdeInfoService) {
                             IOmProductionOrdeInfoService omProductionOrdeInfoService,
                             IDaTestDeviceInterfaceService daTestDeviceInterfaceService) {
        OPCUaSubscription.miloService = miloService;
        this.daPassingStationCollectionService = daPassingStationCollectionService;
        OPCUaSubscription.collectionParamConfService = collectionParamConfService;
        OPCUaSubscription.daParamCollectionService = daParamCollectionService;
        OPCUaSubscription.omProductionOrdeInfoService = omProductionOrdeInfoService;
        OPCUaSubscription.daTestDeviceInterfaceService = daTestDeviceInterfaceService;
    }
@@ -181,16 +189,33 @@
                            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;
//
//                                if (ObjectUtil.isNotNull(packCodeObject)) {
//                                    String modelCode = packCodeObject.toString();
//                                    deviceInterfaceOne = daTestDeviceInterfaceService.getOne(new LambdaQueryWrapper<DaTestDeviceInterface>()
//                                            .eq(DaTestDeviceInterface::getProductNum, modelCode)
//                                            .eq(DaTestDeviceInterface::getStationCode, device));
//                                }
//
//                                if (deviceInterfaceOne != null && "1".equals(deviceInterfaceOne.getTotalResult())) {
//                                    writeToOpc(RecordDataDoneAddress, (short) 21);
//                                } else {
//                                    writeToOpc(RecordDataDoneAddress, (short) 22);
//                                }
                                writeToOpc(RecordDataDoneAddress, (short) 21);
                            }
                        }
                    }else {
                        System.out.println("^");
@@ -543,4 +568,12 @@
        return;
    }
    private static void writeToOpc(String identifier, short value) {
        try {
            miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(identifier).value(value).build());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}