IO的資料集使用案例

不愿透露姓名的小村村發表於2024-04-30
  1. 用AQ2ST和AI4ST做迴環測試,主要是驗證AQ2和AI4手冊上的DS資料集

  2. DS引數寫入

REGION params input
    IF NOT #In_SelectedChannel THEN
        #params_AQ2ST.RDREC.index := 64;
        #params_AQ2ST.WRREC.index := 64;
        #params_AI4ST.RDREC.index := 0;
        #params_AI4ST.WRREC.index := 0;
        
    ELSE
        #params_AQ2ST.RDREC.index := 65;
        #params_AQ2ST.WRREC.index := 65;
        #params_AI4ST.RDREC.index := 1;
        #params_AI4ST.WRREC.index := 1;
    END_IF;
    #params_AQ2ST.RDREC.id := #In_AQhwio;
    #params_AI4ST.RDREC.id := #In_AIhwio;
    #params_AQ2ST.WRREC.id := #In_AQhwio;
    #params_AI4ST.WRREC.id := #In_AIhwio;
    
END_REGION
  1. 通道型別切換選擇
REGION type choice
    CASE #In_TypeChoic OF
        11:
            #params_AQ2ST.recorddata[2] := 2#00000001;//voltage
            #params_AQ2ST.recorddata[3] := 2#00000000;//-10.0v-10.0v
            #params_AQ2ST.recorddata[4] := 2#11000101;//voltage diagnotic
            #params_AI4ST.recorddata[2] := 2#00000001;//voltage
            #params_AI4ST.recorddata[3] := 2#00001001;//-10.0v-10.0v
        12:
            #params_AQ2ST.recorddata[2] := 2#00000001;//voltage
            #params_AQ2ST.recorddata[3] := 2#00000010;//0.0v-10.0v
            #params_AQ2ST.recorddata[4] := 2#11000101;//voltage diagnotic
            #params_AI4ST.recorddata[2] := 2#00000001;//voltage
            #params_AI4ST.recorddata[3] := 2#00001001;//-10.0v-10.0v(no 0.0to10.0v)
        13:
            #params_AQ2ST.recorddata[2] := 2#00000001;//voltage
            #params_AQ2ST.recorddata[3] := 2#00000011;//1.0v-5.0v
            #params_AQ2ST.recorddata[4] := 2#11000101;//voltage diagnotic
            #params_AI4ST.recorddata[2] := 2#00000001;//voltage
            #params_AI4ST.recorddata[3] := 2#00001010;//1.0v-5.0v
        21:
            #params_AQ2ST.recorddata[2] := 2#00000010;//current
            #params_AQ2ST.recorddata[3] := 2#00000000;//-20.0mato20.0ma
            #params_AQ2ST.recorddata[4] := 2#11010001;//current diagnotic
            #params_AI4ST.recorddata[2] := 2#00000010;//current(4-wire)
            #params_AI4ST.recorddata[3] := 2#00000100;//-20.0mato20.0ma
        22:
            #params_AQ2ST.recorddata[2] := 2#00000010;//current
            #params_AQ2ST.recorddata[3] := 2#00000001;//0.0mato20.0ma
            #params_AQ2ST.recorddata[4] := 2#11010001;//current diagnotic
            #params_AI4ST.recorddata[2] := 2#00000010;//current(4-wire)
            #params_AI4ST.recorddata[3] := 2#00000010;//0.0mato20.0ma
        23:
            #params_AQ2ST.recorddata[2] := 2#00000010;//current
            #params_AQ2ST.recorddata[3] := 2#00000010;//4.0mato20.0ma
            #params_AQ2ST.recorddata[4] := 2#11010001;//current diagnotic
            #params_AI4ST.recorddata[2] := 2#00000010;//current(4-wire)
            #params_AI4ST.recorddata[3] := 2#00000011;//4.0mato20.0ma
        ELSE
            //default voltage
            #params_AQ2ST.recorddata[2] := 2#00000001;//voltage
            #params_AQ2ST.recorddata[3] := 2#00000000;//-10.0v-10.0v
            #params_AQ2ST.recorddata[4] := 2#00000000;//no diagnostic
            #params_AI4ST.recorddata[2] := 2#00000001;//voltage
            #params_AI4ST.recorddata[3] := 2#00001001;//-10.0v-10.0v
    END_CASE;
    
END_REGION
  1. 切換使能
REGION Operate enable
    IF #In_OperateEnable AND NOT #paluse_bool THEN
        #stepInt := 10;
    END_IF;
    #paluse_bool := #In_OperateEnable;
    
    CASE #stepInt OF
        10:
            //read AQ2
            #params_AQ2ST.RDREC.req := true;
            IF #params_AQ2ST.RDREC.valid THEN
                #stepInt := 20;
            ELSIF #params_AQ2ST.RDREC.error THEN
                #Status_Error := true;
            END_IF;
        20:
            //read AI4
            #params_AQ2ST.RDREC.req := FALSE;
            #params_AI4ST.RDREC.req := true;
            IF #params_AI4ST.RDREC.valid THEN
                #stepInt := 30;
            ELSIF #params_AI4ST.RDREC.error THEN
                #Status_Error := true;
            END_IF;
        30:
            //write AQ2
            #params_AI4ST.RDREC.req := FALSE;
            #params_AQ2ST.WRREC.req := TRUE;
            IF #params_AQ2ST.WRREC.done THEN
                #stepInt := 40;
            ELSIF #params_AQ2ST.WRREC.error THEN
                #Status_Error := true;
            END_IF;
        40:
            //write ai4
            #params_AQ2ST.WRREC.req := FALSE;
            #params_AI4ST.WRREC.req := TRUE;
            IF #params_AI4ST.WRREC.done THEN
                #stepInt := 50;
            ELSIF #params_AI4ST.WRREC.error THEN
                #Status_Error := true;
            END_IF;
        50:
            //write finish
            #Status_Done := true;
            #params_AQ2ST.RDREC.req := false;
            #params_AQ2ST.WRREC.req := false;
            #params_AI4ST.RDREC.req := false;
            #params_AI4ST.WRREC.req := false;
            #stepInt := 0;
    END_CASE;
    
    IF NOT #In_OperateEnable THEN
        #Status_Done := false;
        #Status_Error := false;
        #params_AQ2ST.RDREC.req := false;
        #params_AQ2ST.WRREC.req := false;
        #params_AI4ST.RDREC.req := false;
        #params_AI4ST.WRREC.req := false;
        #stepInt := 0;
    END_IF;
    
END_REGION
  1. 執行
REGION execute 
    //AQ2ST
    #RdrecControl_AQ2ST(REQ := #params_AQ2ST.RDREC.req,
                        ID := #params_AQ2ST.RDREC.id,
                        INDEX := #params_AQ2ST.RDREC.index,
                        VALID => #params_AQ2ST.RDREC.valid,
                        ERROR => #params_AQ2ST.RDREC.error,
                        LEN => #params_AQ2ST.RDREC.len,
                        RECORD := #params_AQ2ST.recorddata);
    
    #WrrecControl_AQ2ST(REQ := #params_AQ2ST.WRREC.req,
                        ID := #params_AQ2ST.WRREC.id,
                        INDEX := #params_AQ2ST.WRREC.index,
                        LEN := 8,
                        DONE => #params_AQ2ST.WRREC.done,
                        ERROR => #params_AQ2ST.WRREC.error,
                        RECORD := #params_AQ2ST.recorddata);
    //AI4ST
    #RdrecControl_AI4ST(REQ := #params_AI4ST.RDREC.req,
                        ID := #params_AI4ST.RDREC.id,
                        INDEX := #params_AI4ST.RDREC.index,
                        VALID => #params_AI4ST.RDREC.valid,
                        ERROR => #params_AI4ST.RDREC.error,
                        LEN => #params_AI4ST.RDREC.len,
                        RECORD := #params_AI4ST.recorddata);
    
    #WrrecControl_AI4ST(REQ := #params_AI4ST.WRREC.req,
                        ID := #params_AI4ST.WRREC.id,
                        INDEX := #params_AI4ST.WRREC.index,
                        LEN := 28,
                        DONE => #params_AI4ST.WRREC.done,
                        ERROR => #params_AI4ST.WRREC.error,
                        RECORD := #params_AI4ST.recorddata);
END_REGION
  1. 輸出
REGION output
    #Out_Status_Error := #Status_Error;
    #Out_Status_Done := #Status_Done;
    
END_REGION

相關文章