cl
2024-08-01 f3862f0f7387f97e642167c5cda98f7e10fc3065
修改采集参数
已修改3个文件
70 ■■■■■ 文件已修改
jcdm-main/src/main/java/com/jcdm/main/constant/Constants.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
jcdm-main/src/main/java/com/jcdm/main/plcserver/CustomRunner.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java 65 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
jcdm-main/src/main/java/com/jcdm/main/constant/Constants.java
@@ -30,6 +30,8 @@
    public static final String RECORD_CHECK_CODE_2= "RecordCheckCode2";
    public static final String RECORD_DATA= "RecordData";
    public static final String RECORD_SN= "RecordSN";
    public static final String SCREW = "Screw";
    public static final String ONE= "1";
    public static final String ZERO= "0";
    public static final String TWO= "2";
jcdm-main/src/main/java/com/jcdm/main/plcserver/CustomRunner.java
@@ -53,6 +53,9 @@
    @Override
    public void run(ApplicationArguments args) throws Exception {
        //PLC到MES物料转换
        Constants.materialMap.put("1","9900199052A");
        Constants.materialMap.put("2","9900199053B");
        OPCUaSubscription opcUaSubscription = new OPCUaSubscription(
                miloService,
                daPassingStationCollectionService,
jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java
@@ -104,6 +104,7 @@
            if (Constants.RECORD_DATA.equals(tab)) {  //出入站
                if (Constants.ONE.equals(valueString)) {//入站
                    Integer recordDataDone = 11;
                    miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".StartTime").value(new Date()).build());
                    miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(recordDataDone).build());
                } else if(Constants.TWO.equals(valueString)){//出站
                    Integer result = 21;
@@ -135,7 +136,6 @@
                }
            }else if (Constants.RECORD_SN.equals(tab)){//请求产品序列号
                if (Constants.ONE.equals(valueString)){
                    Integer result = 11;
                    //进站PLC给产品类型,MES读取产品类型
                    Object productTypeObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".ProductType").getValue();//产品类型
                    if (ObjectUtil.isNotNull(productTypeObjcet)){
@@ -146,10 +146,22 @@
                            receivingWorkOrders(thoroughfare, device,materialCode);
                        });
                    }else{
                        result = 12;
                        miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordSNDone").value(12).build());
                    }
                    miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordSNDone").value(result).build());
                }
            }else if(Constants.SCREW.equals(tab)){
                List<String> list = new ArrayList<>();
                String[] suffixes = {"Torque", "Angle", "TorqueResult", "AngleResult"};
                for (String suffix : suffixes) {
                    String string = thoroughfare + "." + device + "." + suffix;
                    list.add(string);
                }
                List<ReadWriteEntity> list1 = miloService.readFromOpcUa(list);
                List<Object> collect = list1.stream().map(ReadWriteEntity::getValue).collect(Collectors.toList());
                String joinedString = String.join(",", collect.toString());
                WebSocketUsers.sendMessageToUserByText(map.get(device), TightenTheConversionOkNg(joinedString));
            }
        }catch (Exception e) {
            log.error(e.getMessage());
@@ -334,6 +346,7 @@
            if(!productNum.isEmpty() && !orderNum.isEmpty()){
                miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".ModuleCode").value(productNum).build());
                miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".WorkOrderNumber").value(orderNum).build());
                miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordSNDone").value(11).build());
            }
        } catch (Exception e) {
@@ -384,4 +397,50 @@
            throw new RuntimeException(e);
        }
    }
    public static String TightenTheConversionOkNg(String param){
        // 去除首尾的方括号,然后按照逗号分割字符串
        String[] parts = param.substring(1, param.length() - 1).split(",");
        // 创建一个新的StringBuilder来构建替换后的字符串
        StringBuilder sb = new StringBuilder();
        sb.append('['); // 添加左方括号
        for (int i = 0; i < parts.length; i++) {
            String part = parts[i].trim(); // 去除可能的空格
            float value;
            try {
                value = Float.parseFloat(part); // 尝试将字符串转换为浮点数
                String replacement;
                if(i<2){
                    replacement = part;
                }else{
                    if (value == 1f) {
                        replacement = "OK";
                    } else{
                        replacement = "NG";
                    }
                }
            /*    if (value == 1f) {
                    replacement = "OK";
                } else if (value == 2f) {
                    replacement = "NG";
                } else {
                    replacement = part; // 如果不是1或2,则保持不变
                }*/
                sb.append(replacement);
                if (i < parts.length - 1) {
                    sb.append(','); // 添加逗号(除了最后一个元素)
                }
            } catch (NumberFormatException e) {
                // 如果转换失败,则保持原样(或进行其他错误处理)
                sb.append(part);
                if (i < parts.length - 1) {
                    sb.append(',');
                }
            }
        }
        sb.append(']'); // 添加右方括号
        return sb.toString();
    }
}