{"id":202,"date":"2021-09-22T21:47:40","date_gmt":"2021-09-22T13:47:40","guid":{"rendered":"http:\/\/www.sanburs.xyz\/?p=202"},"modified":"2021-09-22T21:49:14","modified_gmt":"2021-09-22T13:49:14","slug":"how_to_cleardb_in_siemensplc","status":"publish","type":"post","link":"https:\/\/www.sanburs.xyz\/index.php\/2021\/09\/22\/how_to_cleardb_in_siemensplc\/","title":{"rendered":"\u5982\u4f55\u5728\u897f\u95e8\u5b50PLC\u4e2d\u6e05\u9664\u4e00\u6574\u4e2a\u6570\u636e\u5757"},"content":{"rendered":"<h1>\u5982\u4f55\u5728\u897f\u95e8\u5b50PLC\u4e2d\u6e05\u9664\u4e00\u6574\u4e2a\u6570\u636e\u5757<\/h1>\n<h2>1500\u7cfb\u5217\u7248\u672c<\/h2>\n<pre><code class=\"\">FUNCTION \"F_ClearDB\" : Void\n{ S7_Optimized_Access := 'FALSE' }\nVERSION : 1.0\n   VAR_INPUT \n      IN0 : DB_ANY;\n   END_VAR\n\n   VAR_TEMP \n      TEMP1 : Int;\n   END_VAR\n\n\nBEGIN\nNETWORK\nTITLE = \n\n\n      LAR1 P#DBX0.0;\n      OPN #IN0;\n      L DBLG;\n      L 2;\n      \/I;\nM001:      T #TEMP1;\n      L 0;\n      T W[ AR1, P#0.0];\n      +AR1 P#2.0;\n      L #TEMP1;\n      LOOP M001;\n\n\nEND_FUNCTION\n<\/code><\/pre>\n<p>\u56e0\u4e3a1500\u7cfb\u5217\u652f\u6301STL\u8bed\u8a00,\u800cSTL\u8bed\u8a00\u4e2d\u6709\u4e00\u4e2a\u5f88\u597d\u7528\u7684\u6307\u4ee4 <code>L DBLG<\/code>,\u8fd9\u4e2a\u6307\u4ee4\u5c06\u4f1a\u8fd4\u56deDB\u5757\u7684\u957f\u5ea6(in Bytes) in Runtime.\u77e5\u9053DB\u5757\u7684\u957f\u5ea6\u5c31\u53ef\u4ee5\u6e05\u9664\u8fd9\u4e2a\u6570\u636e\u5757\u7684\u6570\u636e\u4e86.<\/p>\n<h2>1200\u7248\u672c<\/h2>\n<pre><code class=\"\">FUNCTION \"F_ClearDB\" : Void\n{ S7_Optimized_Access := 'TRUE' }\nVERSION : 0.1\n   VAR_INPUT \n      \"DB\" : DB_ANY;\n   END_VAR\n\n   VAR_TEMP \n      db_index : UInt;\n      i : UInt;\n      Size : UInt;   \/\/  default db size=0\n      db_byte : Byte;\n      max_index : UInt;\n      err_id : Word;\n      zero : Byte;\n   END_VAR\n\n\nBEGIN\n    \/\/-------------------------------------------------------------------\n    #db_index := 0;      \/\/ initialize\n    #zero := 0;\n    #max_index := 2000;  \/\/ set a constraint to prevent watchdog timeouts\n    \/\/===================================================================\n    \/\/ not strictly required to handle errors internally\n    \/\/ but if a FW or service pack or update suddenly causes errors,\n    \/\/ this should prevent cpu crashes\n    \/\/ ==================================================================\n    \/\/\n    \/\/ clear out any existing error conditions\n    #err_id := GET_ERR_ID();\n    \/\/ emulates TRY ... CATCH ... found in other computer languages\n    REPEAT\n        ENO := TRUE;  \/\/ required to make it work\n        \/\/ try to look at byte @ db_index\n\n        #db_byte := PEEK_BYTE(area := 16#84, dbNumber := #DB, byteOffset := #db_index);\n        #db_index += 1;\n    UNTIL (#db_index &gt;= #max_index) OR (NOT ENO) END_REPEAT;\n    IF NOT ENO THEN\n        #Size := #db_index - 1;  \/\/ copy count when ENO went off (before inc(1) )\n    ELSE\n       #Size := 0;            \/\/ DB does not exist or is very large\n    END_IF;\n    REPEAT\n        POKE(area := 16#84,\n             dbNumber := #DB,\n             byteOffset := #i,\n             value := #zero);\n        #i += 1;\n    UNTIL (#i &gt;= #Size)  END_REPEAT;\n    \/\/ FOR #i := 0 TO #Size BY 1 DO\n    \/\/     ;\n    \/\/ END_FOR;\nEND_FUNCTION\n\n\n<\/code><\/pre>\n<p>1200\u7cfb\u5217\u4e0d\u652f\u6301STL\u8bed\u8a00,\u90a3\u4e48\u83b7\u53d6DB\u5757\u957f\u5ea6\u5c31\u8981\u4f7f\u7528\u4e00\u70b9\u6280\u5de7\u4e86,\u8fd9\u91cc\u4f7f\u7528\u7684\u662fENO<\/p>\n<pre><code class=\"\">REPEAT\n        ENO := TRUE;  \/\/ required to make it work\n        \/\/ try to look at byte @ db_index\n\n        #db_byte := PEEK_BYTE(area := 16#84, dbNumber := #DB, byteOffset := #db_index);\n        #db_index += 1;\nUNTIL (#db_index &gt;= #max_index) OR (NOT ENO) END_REPEAT;\n<\/code><\/pre>\n<p>\u4ee5\u4e0a\u8fd9\u4e00\u6bb5\u4ee3\u7801\u5c31\u5229\u7528\u4e86<code>ENO<\/code>\u7684\u7279\u6027,\u5f53<code>PEEK_BYTE<\/code>\u6307\u4ee4\u62a5\u9519\u65f6,\u8bf4\u660e\u5f53\u524d<code>#db_index<\/code>\u5df2\u7ecf\u8d85\u8fc7\u4e86\u6570\u636e\u5757\u7684\u6700\u5927\u957f\u5ea6,\u540c\u65f6\u5c06ENO\u7f6e\u4e3a0;<\/p>\n<p>\u8fd9\u6837\u6211\u4eec\u5c31\u83b7\u53d6\u4e86\u8be5\u6570\u636e\u5757\u7684\u957f\u5ea6<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5728\u897f\u95e8\u5b50PLC\u4e2d\u6e05\u9664\u4e00\u6574\u4e2a\u6570\u636e\u5757 1500\u7cfb\u5217\u7248\u672c FUNCTION &#8220;F_ClearDB&#8221; : Void { S7_Opti","protected":false},"author":1,"featured_media":161,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/www.sanburs.xyz\/index.php\/wp-json\/wp\/v2\/posts\/202"}],"collection":[{"href":"https:\/\/www.sanburs.xyz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sanburs.xyz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sanburs.xyz\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sanburs.xyz\/index.php\/wp-json\/wp\/v2\/comments?post=202"}],"version-history":[{"count":1,"href":"https:\/\/www.sanburs.xyz\/index.php\/wp-json\/wp\/v2\/posts\/202\/revisions"}],"predecessor-version":[{"id":203,"href":"https:\/\/www.sanburs.xyz\/index.php\/wp-json\/wp\/v2\/posts\/202\/revisions\/203"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.sanburs.xyz\/index.php\/wp-json\/wp\/v2\/media\/161"}],"wp:attachment":[{"href":"https:\/\/www.sanburs.xyz\/index.php\/wp-json\/wp\/v2\/media?parent=202"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sanburs.xyz\/index.php\/wp-json\/wp\/v2\/categories?post=202"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sanburs.xyz\/index.php\/wp-json\/wp\/v2\/tags?post=202"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}