{"id":51511,"date":"2026-08-04T20:24:45","date_gmt":"2026-08-04T12:24:45","guid":{"rendered":"https:\/\/www.modbus.cn\/51511.html"},"modified":"2026-08-04T20:24:45","modified_gmt":"2026-08-04T12:24:45","slug":"visualhmi-ota-%e5%8d%87%e7%ba%a7%ef%bc%9aota_init-ota_write-%e4%b8%8e-sd-%e5%8d%a1%e8%87%aa%e5%8a%a8%e5%8d%87%e7%ba%a7","status":"publish","type":"post","link":"http:\/\/www.modbus.cn\/en\/51511.html","title":{"rendered":"VisualHMI OTA \u5347\u7ea7\uff1aota_init\/ota_write \u4e0e SD \u5361\u81ea\u52a8\u5347\u7ea7"},"content":{"rendered":"<p>\u901a\u8fc7 LUA \u5b9e\u73b0\u8fdc\u7a0b\u56fa\u4ef6\u5347\u7ea7\uff08OTA\uff09\uff1a\u521d\u59cb\u5316\u3001\u5199\u5165\u3001\u6821\u9a8c\u3001\u89e3\u538b\u3001\u91cd\u542f\u3002\u5347\u7ea7\u5305\u653e\u5728 SD \u5361\uff0c\u63d2\u5361\u81ea\u52a8\u68c0\u6d4b\u89e6\u53d1\u3002<\/p>\n<h2>1. API<\/h2>\n<table border=\"1\" cellpadding=\"6\" style=\"border-collapse:collapse;font-size:14px\">\n<tr>\n<th>\u51fd\u6570<\/th>\n<th>\u8bf4\u660e<\/th>\n<\/tr>\n<tr>\n<td>ota_init(md5, filesize, addr)<\/td>\n<td>\u521d\u59cb\u5316\u5347\u7ea7\uff1amd5 \u4e3a\u56fa\u5b9a\u4e32 \u300c0123456789abcdef\u300d\uff1baddr \u2265 Flash \u603b\u91cf\u4e00\u534a<\/td>\n<\/tr>\n<tr>\n<td>ota_write(writeTb)<\/td>\n<td>\u5199\u5165\u5347\u7ea7\u6570\u636e\uff08\u5b57\u8282\u8868 \u22642048\uff0c\u4e0d\u8db3\u81ea\u52a8\u8865 0x00\uff09<\/td>\n<\/tr>\n<tr>\n<td>ota_check_upgrade(1)<\/td>\n<td>\u6821\u9a8c\u5e76\u5f00\u59cb\u5347\u7ea7<\/td>\n<\/tr>\n<tr>\n<td>ota_destory()<\/td>\n<td>\u64e6\u9664\u6b8b\u7559\u5347\u7ea7\u6570\u636e<\/td>\n<\/tr>\n<tr>\n<td>on_ota_progress(status, value)<\/td>\n<td>\u5347\u7ea7\u8fdb\u5ea6\u56de\u8c03<\/td>\n<\/tr>\n<\/table>\n<h2>2. Flash \u89c4\u5212\uff08\u4ee5 HMI80480M070 \u4e3a\u4f8b\uff09<\/h2>\n<p>16MB \u603b\u91cf\uff1a\u7cfb\u7edf 1MB + \u5de5\u7a0b 4.38MB = \u5df2\u7528 5.38MB\uff0c\u7a7a\u95f2\u7ea6 10.62MB\u3002\u4f46 <strong>OTA \u5fc5\u987b\u4ece \u22658MB\uff08\u540e\u534a\u90e8\u5206\uff09\u5f00\u59cb<\/strong>\uff0c\u9632\u6b62\u4e0e\u5de5\u7a0b\u533a\u4ea4\u53c9\u8986\u76d6\uff1bOTA \u5305\u5927\u5c0f\u987b\u5c0f\u4e8e Flash \u4e00\u534a\u3002\u5757\u5730\u5740\u5360\u7528\u9ad8\u5730\u5740\u533a\u4f1a\u5bfc\u81f4\u4e0d\u53ef\u5347\u7ea7\u3002<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.modbus.cn\/wp-content\/uploads\/2026\/08\/visualhmi\/lu015_1.png\" style=\"max-width:100%;border:1px solid #eee;margin:8px 0\" loading=\"lazy\" title=\"VisualHMI OTA \u5347\u7ea7\uff1aota_init\/ota_write \u4e0e SD \u5361\u81ea\u52a8\u5347\u7ea7\u63d2\u56fe\" alt=\"VisualHMI OTA \u5347\u7ea7\uff1aota_init\/ota_write \u4e0e SD \u5361\u81ea\u52a8\u5347\u7ea7\u63d2\u56fe\" \/><\/p>\n<h2>3. \u8fdb\u5ea6\u56de\u8c03\u72b6\u6001<\/h2>\n<table border=\"1\" cellpadding=\"6\" style=\"border-collapse:collapse;font-size:14px\">\n<tr>\n<th>status<\/th>\n<th>\u542b\u4e49<\/th>\n<th>value<\/th>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>\u6821\u9a8c\u5f00\u59cb<\/td>\n<td>0<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>\u6821\u9a8c\u7ed3\u679c<\/td>\n<td>0=\u5931\u8d25 \/ 1=\u6210\u529f<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>\u89e3\u538b\u8fdb\u5ea6<\/td>\n<td>0~100<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>\u89e3\u538b\u7ed3\u679c<\/td>\n<td>0=\u5931\u8d25 \/ 1=\u6210\u529f\uff08\u5373\u5c06\u91cd\u542f\uff09<\/td>\n<\/tr>\n<\/table>\n<h2>4. \u6848\u4f8b\uff1aSD \u5361\u81ea\u52a8\u5347\u7ea7<\/h2>\n<pre style=\"background:#f5f5f5;padding:10px;border-radius:4px\">_otaFile = \"1:\/a.bin\"   -- \u91cf\u4ea7\u65f6 ota.bin \u6539\u540d a.bin\n\nfunction on_sd_inserted(dir)\n  -- SD\u5361\u63d2\u5165, \u68c0\u67e5\u5347\u7ea7\u5305\n  list_dir(\"1:\/\")\nend\n\nfunction on_list_dir(path, filename, type, fsize)\n  if filename == \"a.bin\" then\n    start_ota()\n  end\nend\n\nfunction start_ota()\n  file_open(_otaFile, 0)\n  local fsize = file_size()\n  -- addr \u53d6 Flash \u540e\u534a\u90e8\u5206: 16MB \u53d6 8MB=0x800000\n  ota_init(\"0123456789abcdef\", fsize, 0x800000)\n  local remain = fsize\n  while remain &gt; 0 do\n    local n = (remain &gt; 2048) and 2048 or remain\n    local buf = file_read(n)\n    ota_write(buf)\n    remain = remain - n\n  end\n  file_close()\n  ota_check_upgrade(1)\nend\n\nfunction on_ota_progress(status, value)\n  if status == 2 then\n    if value == 0 then\n      print(\"OTA \u6821\u9a8c\u5931\u8d25\")\n      ota_destory()\n    end\n  elseif status == 4 then\n    if value == 0 then print(\"OTA \u89e3\u538b\u5931\u8d25\") end\n  end\nend<\/pre>\n<div class=\"tip\" style=\"border-left:4px solid #f7941e;padding:10px 14px;background:#fff8ef;margin:14px 0\">OTA \u4e09\u6761\u7ea2\u7ebf\uff1a<strong>\u2460md5 \u53c2\u6570\u5fc5\u987b\u7528\u5b98\u65b9\u56fa\u5b9a\u4e32 \u300c0123456789abcdef\u300d\uff1b\u2461\u8d77\u59cb\u5730\u5740\u5fc5\u987b \u2265 Flash \u4e00\u534a\uff0c\u5426\u5219\u4f1a\u8986\u76d6\u5de5\u7a0b\u533a\u628a\u5c4f\u5237\u6210\u7816\uff1b\u2462\u5347\u7ea7\u5305\u592a\u5927\uff08\u2265\u4e00\u534a Flash\uff09\u4e0d\u53ef\u5347\u7ea7\uff0c\u5148\u67e5\u6587\u4ef6\u5927\u5c0f\u518d\u5f00\u59cb<\/strong>\u3002<\/div>\n<p style=\"color:#888;font-size:13px\">\u6574\u7406\u81ea \u5e7f\u5dde\u5927\u5f69\u79d1\u6280 VisualHMI \u5f00\u53d1\u6587\u6863\uff08hmi-doc.gz-dc.com\uff09LUA \u6559\u7a0b\u300cOTA \u5347\u7ea7\u300d\uff0c\u7248\u6743\u5f52\u5927\u5f69\u79d1\u6280\u6240\u6709\u3002<\/p>\n<span id=\"magicpostMarker\"><\/span>","protected":false},"excerpt":{"rendered":"<p>\u901a\u8fc7 LUA \u5b9e\u73b0\u8fdc\u7a0b\u56fa\u4ef6\u5347\u7ea7\uff08OTA\uff09\uff1a\u521d\u59cb\u5316\u3001\u5199\u5165\u3001\u6821\u9a8c&#8230;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_members_access_role":[],"_members_access_error":""},"categories":[3131,3126],"tags":[3372,3369,3370,3371,3134,3163],"class_list":["post-51511","post","type-post","status-publish","format-standard","hentry","category-hmi-lua","category-hmi-dev","tag-flash","tag-ota","tag-ota_init","tag-ota_write","tag-visualhmi","tag-3163"],"_links":{"self":[{"href":"http:\/\/www.modbus.cn\/en\/wp-json\/wp\/v2\/posts\/51511","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.modbus.cn\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.modbus.cn\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.modbus.cn\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.modbus.cn\/en\/wp-json\/wp\/v2\/comments?post=51511"}],"version-history":[{"count":0,"href":"http:\/\/www.modbus.cn\/en\/wp-json\/wp\/v2\/posts\/51511\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.modbus.cn\/en\/wp-json\/wp\/v2\/media?parent=51511"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.modbus.cn\/en\/wp-json\/wp\/v2\/categories?post=51511"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.modbus.cn\/en\/wp-json\/wp\/v2\/tags?post=51511"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}