B&R配方机制例程

  1. 添加库文件 MpWebXs,MpFile,MpRecipe

  2. 添加mapp文件夹

    configuration->PC_any->mapp文件夹

  3. 添加MpRecipe配置
    mapp文件夹右击添加XML Recipe文件

  4. 添加程序

  5. 在程序中添加MpRecipeXml功能块,配置功能块

    PROGRAM _CYCLIC
        (* Insert code here *)
        MpRecipeXml_0.MpLink := ADR(gRecipeXml);
        MpRecipeXml_0.Enable := 1;
        MpRecipeXml_0.DeviceName := ADR('address');
        MpRecipeXml_0.FileName := ADR('recipe');
        MpRecipeXml_0();
    END_PROGRAM
    
  6. 创建文件存储地址

    Physical View->PC_any右击->Configuration->File devices->右击添加

  7. 创建需要保存的数据,放在一个结构体里面

  8. 声明结构体变量,在初始化程序中初始化

    PROGRAM _INIT
        (* Insert code here *)
        saveParameter.saveBOOL := 1;
        saveParameter.saveREAL := 3.14;
        saveParameter.saveSTRING := 'this is a test program by Z.K.';
        saveParameter.saveUDINT := 120;
    END_PROGRAM
    
  9. 在程序中添加MpRecipeRegPar功能块并在程序中配置功能块

    PROGRAM _CYCLIC
        MpRecipeRegPar_0.MpLink := ADR(gRecipeXml);
        MpRecipeRegPar_0.PVname := ADR('Program:saveParameter');
        MpRecipeRegPar_0.Enable := 1;
        MpRecipeRegPar_0();
    END_PROGRAM
    
  10. 测试程序

  11. PROGRAM _INIT
        (* Insert code here *)
        saveParameter.saveBOOL := 1;
        saveParameter.saveREAL := 3.14;
        saveParameter.saveSTRING := 'this is a test program by Z.K.';
        saveParameter.saveUDINT := 120;
    
    END_PROGRAM
    PROGRAM _CYCLIC
        (* Insert code here *)
        MpRecipeXml_0.MpLink := ADR(gRecipeXml);
        MpRecipeXml_0.Enable := 1;
        MpRecipeXml_0.DeviceName := ADR('address');
        MpRecipeXml_0.FileName := ADR('recipe');
        MpRecipeXml_0();
    
    
        MpRecipeRegPar_0.MpLink :=  ADR(gRecipeXml);
        MpRecipeRegPar_0.PVName := ADR('Program:saveParameter');
        MpRecipeRegPar_0.Enable := 1;
        MpRecipeRegPar_0(); 
    
    END_PROGRAM