回复:相同逻辑的程序做成FB后总是异常出错

mkas

  • 帖子

    125
  • 精华

    2
  • 被关注

    12

论坛等级:侠士

注册时间:2013-08-04

普通 普通 如何晋级?

发布于 2018-09-10 20:27:51

1楼

FB上传的程序如下:

TYPE "UDT_ACC_UNLOAD"

VERSION : 0.1

   STRUCT

      PLC : Struct   // PLC -> ACC - Unloading process control flags

         CheckSum : Int;   // Checksum of data (XOR of N_REAL array)

         PartTypeID : Int;   // Part type ID extracted from part type description

         Result : Struct   // Results

            Component_0 : String[100];   // Serial number - Housing(string -> struct)

            Component_1 : String[100];   // Serial number - Component 1(string -> struct)

            Component_2 : String[100];   // Serial number - Component 1(string -> struct)

            Component_3 : String[100];   // Serial number - Component 1(string -> struct)

            Component_4 : String[100];   // Serial number - Component 1(string -> struct)

            StatusBits : DInt;   // Logic OK results of process

            FailureBits : DInt;   // Logic NOK results of process

            N_REAL : Array[1..50] of Real;   // Array - Numerical result for processes (IU system)

         END_STRUCT;

      END_STRUCT;

      ACC : Struct   // ACC -> PLC - Unloading process control flags

         ErrorCode : Int;   // Process error code

         ErrorMsg : String[50];   // Error message(string -> struct)

      END_STRUCT;

   END_STRUCT;


END_TYPE


FUNCTION "FC_ACC_CKS" : Word

{ S7_Optimized_Access := 'TRUE' }

VERSION : 0.1

   VAR_INPUT 

      AREA : Byte;   // 16#81:I,16#82:Q,16#83:M,16#84:DB

      DB_NUMBER : Int;   // 非DB=0

      START_BYTE : Int;   // 读取位置起始字节

      STEP_OFFSET : Int;   // 循环偏移

      STEP_COUNT : Int;   // 执行步数

   END_VAR


   VAR_TEMP 

      i : Int;   // step Index

      tRead : Word;   // 读取字

      tResult : Word;   // 中间结果

   END_VAR



BEGIN

(* CHECK_SUM  *)

IF #STEP_OFFSET > 0 AND #STEP_COUNT > 0 THEN

    #tResult := 0;

        FOR #i := 1 TO #STEP_COUNT DO                                               (*  从位数#START_BIT..位数#BYTE_LEN*)

            #tRead := PEEK_WORD(area := #AREA,                                      (*  源数据类型:16#81:I,16#82:Q,16#83:M,16#84:DB  *)

                                dbNumber := #DB_NUMBER,                             (*  源数据块:非DB=0  *)

                                byteOffset := #START_BYTE + #STEP_OFFSET * (#i - 1));     (*  源数据起始位号  *)

            #tResult := #tRead XOR #tResult;

        END_FOR;

           (*返回最终值*)

END_IF;

#FC_ACC_CKS := #tResult;

END_FUNCTION


FUNCTION_BLOCK "ACC_Unload"

{ S7_Optimized_Access := 'TRUE' }

VERSION : 0.1

   VAR_INPUT 

      iReset : Bool;

      iResult : DInt;

      GT1_Value : Real;

      GT2_Value : Real;

      GT3_Value : Real;

      iPartTypeID : Int;

      iDB_Number : Int;

      iStart_Byte : Int;

      iStep_Offset : Int;

      iStep_Count : Int;

      iCode : String[100];

   END_VAR


   VAR_OUTPUT 

      oUnload_OK : Bool;

      oUnload_NOK : Bool;

      oUnload_TimeOut : Bool;

      oUnload_ErrorCode : Int;

      oUnload_Msg : String[50];

      oStatus : Int;

   END_VAR


   VAR_IN_OUT 

      ioACC_Com_PLC_Unload_0 : Bool;

      ioACC_Com_ACC_Unload_0 : Bool;

      ioACC_Com_ACC_Unload_1 : Bool;

      ioACC_Unload : "UDT_ACC_UNLOAD";

      ioRequest : Bool;

   END_VAR


   VAR 

      s_Step : Int;

      s_Delay : Int;

   END_VAR


   VAR_TEMP 

      index : Int;

   END_VAR



BEGIN

#ioACC_Unload.PLC.CheckSum := WORD_TO_INT("FC_ACC_CKS"(AREA := 16#84,

                                             DB_NUMBER := #iDB_Number,

                                             START_BYTE := #iStart_Byte,

                                             STEP_OFFSET := #iStep_Offset,

                                             STEP_COUNT := #iStep_Count

                                          ));

IF #iReset AND #oStatus <> 0   THEN

    #oStatus := 0;

    #ioACC_Com_PLC_Unload_0 := 0;

    #s_Step := 0;

END_IF;

CASE #s_Step OF

    0:

        #oUnload_NOK := 0;

        #oUnload_OK := 0;

        #oUnload_TimeOut := 0;

        #oUnload_ErrorCode := 0;

        #oUnload_Msg := '';

        #s_Delay := 0;

        IF #ioRequest THEN

            #ioRequest := 0;

            #s_Step := 1;

        END_IF;

    1:

        #ioACC_Com_ACC_Unload_0 := 0;

        #ioACC_Com_ACC_Unload_1 := 0;

        #ioACC_Com_PLC_Unload_0 := 0;

        #ioACC_Unload.PLC.PartTypeID := 0;

        #ioACC_Unload.PLC.Result.Component_0 := '';

        #ioACC_Unload.PLC.Result.Component_1 := '';

        #ioACC_Unload.PLC.Result.Component_2 := '';

        #ioACC_Unload.PLC.Result.Component_3 := '';

        #ioACC_Unload.PLC.Result.Component_4 := '';

        #ioACC_Unload.PLC.Result.StatusBits := 0;

        #ioACC_Unload.PLC.Result.FailureBits := 0;

        FOR #index := 1 TO 50 DO

            #ioACC_Unload.PLC.Result.N_REAL[#index] := 0.0;

        END_FOR;

        #s_Step := 2;

    2:

        #ioACC_Unload.PLC.Result.N_REAL[1] := #GT1_Value;

        #ioACC_Unload.PLC.Result.N_REAL[2] := #GT2_Value;

        #ioACC_Unload.PLC.Result.N_REAL[3] := #GT3_Value;

        #ioACC_Unload.PLC.PartTypeID := #iPartTypeID;

        #ioACC_Unload.PLC.Result.Component_0 := #iCode;

        #ioACC_Unload.PLC.Result.StatusBits := #iResult;

        #s_Delay := #s_Delay + 1;

        IF #s_Delay >= 50 THEN

            #ioACC_Com_PLC_Unload_0 := 1;

            #s_Delay := 0;

            #s_Step := 3;

        END_IF;

    3:

        

        IF #ioACC_Com_ACC_Unload_0 THEN

            #oUnload_OK := 1;

            #oUnload_ErrorCode := 0;

            #oUnload_Msg := 'PartType UnLoading OK';

            #s_Step := 4;

        

        ELSIF #ioACC_Com_ACC_Unload_1 THEN

            #oUnload_NOK := 1;

            #oUnload_ErrorCode := #ioACC_Unload.ACC.ErrorCode;

            #oUnload_Msg := #ioACC_Unload.ACC.ErrorMsg;

            #s_Step := 4;

            

        ELSE

            #s_Delay := #s_Delay + 1;

            IF #s_Delay >= 2000 THEN

                #oUnload_TimeOut := 1;

                #s_Delay := 0;

                #oStatus := 1;

                #oUnload_ErrorCode := 9999;

                #oUnload_Msg := 'PartType UnLoading Timeout';

                #s_Step := 5;

            END_IF;

        END_IF;

    4:

        #ioACC_Com_PLC_Unload_0 := 0;

        #s_Step := 0;

END_CASE;

END_FUNCTION_BLOCK


好好学习,天天向上
评论
编辑推荐: 关闭

请填写推广理由:

本版热门话题

SIMATIC S7-1500系列

共有10844条技术帖

相关推荐

热门标签

相关帖子推荐

guzhang

恭喜,你发布的帖子

评为精华帖!

快扫描右侧二维码晒一晒吧!

再发帖或跟帖交流2条,就能晋升VIP啦!开启更多专属权限!

  • 分享

  • 只看
    楼主

top
X 图片
您收到0封站内信:
×
×
信息提示
很抱歉!您所访问的页面不存在,或网址发生了变化,请稍后再试。