{"id":12410,"date":"2023-06-12T11:50:50","date_gmt":"2023-06-12T03:50:50","guid":{"rendered":"https:\/\/www.modbus.cn\/?p=12410"},"modified":"2023-06-12T11:51:37","modified_gmt":"2023-06-12T03:51:37","slug":"gomodbus-v2-yi-ge-qiang-da-de-go-yu-yan-modbus-ku-zhi-chi-rtuascii-he-tcp","status":"publish","type":"post","link":"https:\/\/www.modbus.cn\/en\/12410.html","title":{"rendered":"gomodbus\/v2: \u4e00\u4e2a\u5f3a\u5927\u7684Go\u8bed\u8a00Modbus\u5e93\uff0c\u652f\u6301RTU\u3001ASCII\u548cTCP"},"content":{"rendered":"<p>\u5728\u5de5\u4e1a\u81ea\u52a8\u5316\u548c\u63a7\u5236\u7cfb\u7edf\u5f00\u53d1\u4e2d\uff0cModbus\u534f\u8bae\u7684\u5e94\u7528\u5e7f\u6cdb\u3002\u5bf9\u4e8e\u4f7f\u7528Go\u8bed\u8a00\u8fdb\u884c\u5f00\u53d1\u7684\u4eba\u6765\u8bf4\uff0c\u9009\u62e9\u4e00\u4e2a\u5f3a\u5927\u3001\u7075\u6d3b\u4e14\u6613\u7528\u7684Modbus\u5e93\u662f\u81f3\u5173\u91cd\u8981\u7684\u3002\u4eca\u5929\uff0c\u6211\u8981\u5411\u5927\u5bb6\u63a8\u8350\u7684\u5c31\u662fgomodbus\/v2\u3002<\/p>\n<p>gomodbus\/v2\u662f\u4e00\u4e2a\u4e3aGo\u8bed\u8a00\u5f00\u53d1\u8005\u51c6\u5907\u7684Modbus\u5e93\uff0c\u652f\u6301Modbus RTU\u3001ASCII\u548cTCP\u7684\u4e3b\u5e93\uff0c\u540c\u65f6\u4e5f\u652f\u6301TCP\u4ece\u5c5e\u3002\u8fd9\u4e2a\u5e93\u6709\u7740\u4ee5\u4e0b\u7684\u7279\u70b9\uff1a<\/p>\n<p>1. \u652f\u6301\u591a\u79cd\u683c\u5f0f\uff1a\u65e0\u8bba\u4f60\u9700\u8981Modbus\u4e32\u884c\uff08RTU\uff0cASCII\uff09\u5ba2\u6237\u7aef\uff0c\u8fd8\u662fModbus TCP\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\uff0cgomodbus\/v2\u90fd\u53ef\u4ee5\u6ee1\u8db3\u4f60\u7684\u9700\u6c42\u3002<\/p>\n<p>2. \u5bf9\u8c61\u6c60\u8bbe\u8ba1\uff1a\u8fd9\u4e2a\u5e93\u91c7\u7528\u4e86\u5bf9\u8c61\u6c60\u8bbe\u8ba1\uff0c\u5927\u5927\u51cf\u5c11\u4e86\u5185\u5b58\u7684\u5206\u914d\u548c\u56de\u6536\uff0c\u63d0\u5347\u4e86\u6027\u80fd\u3002<\/p>\n<p>3. \u5feb\u901f\u7f16\u7801\u548c\u89e3\u7801\uff1agomodbus\/v2\u63d0\u4f9b\u4e86\u9ad8\u6548\u7684\u7f16\u7801\u548c\u89e3\u7801\u529f\u80fd\uff0c\u53ef\u4ee5\u5feb\u901f\u5730\u8fdb\u884cModbus\u6d88\u606f\u7684\u5904\u7406\u3002<\/p>\n<p>4. \u7b80\u5355\u7684API\uff1agomodbus\/v2\u7684API\u8bbe\u8ba1\u7b80\u6d01\u660e\u4e86\uff0c\u6613\u4e8e\u7406\u89e3\u548c\u4f7f\u7528\u3002\u540c\u65f6\uff0c\u5b83\u4e5f\u652f\u6301\u539f\u59cb\u6570\u636eAPI\uff0c\u53ef\u4ee5\u6ee1\u8db3\u66f4\u591a\u590d\u6742\u7684\u9700\u6c42\u3002<\/p>\n<p>\u5b89\u88c5gomodbus\/v2\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u8981\u6267\u884c\u4e0b\u9762\u7684\u547d\u4ee4\uff1a<\/p>\n<p>&#8220;`bash<br \/>\ngo get github.com\/thinkgos\/gomodbus\/v2<br \/>\n&#8220;`<\/p>\n<p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u4f60\u53ef\u4ee5\u5728\u4f60\u7684\u4ee3\u7801\u4e2d\u5bfc\u5165gomodbus\u5305\uff0c\u5982\u4e0b\uff1a<\/p>\n<p>&#8220;`go<br \/>\nimport modbus &#8220;github.com\/thinkgos\/gomodbus\/v2&#8221;<br \/>\n&#8220;`<\/p>\n<p>gomodbus\/v2\u652f\u6301\u6240\u6709\u5e38\u89c1\u7684Modbus\u64cd\u4f5c\uff0c\u5305\u62ec\uff1a<\/p>\n<p>&#8211; \u529f\u80fd\u4f4d\u8bbf\u95ee\uff1a\u8bfb\u53d6\u79bb\u6563\u8f93\u5165\u3001\u8bfb\/\u5199\u7ebf\u5708<br \/>\n&#8211; 16\u4f4d\u8bbf\u95ee\uff1a\u8bfb\/\u5199\u8f93\u5165\u5bc4\u5b58\u5668\u548c\u6682\u6302\u5bc4\u5b58\u5668\u3001\u8bfb\/\u5199\u591a\u4e2a\u5bc4\u5b58\u5668\u3001\u8bfb\/\u5199FIFO\u961f\u5217<\/p>\n<p>\u73b0\u5728\uff0c\u6211\u5c06gomodbus\/v2\u548c\u76f8\u5173\u7684\u4f9d\u8d56\u5305\u90fd\u6253\u5305\u6210\u4e86\u4e00\u4e2a\u538b\u7f29\u5305\uff0c\u4e3a\u4e86\u652f\u6301\u6211\u7ee7\u7eed\u63d0\u4f9b\u8fd9\u6837\u7684\u8d44\u6e90\uff0c\u6211\u51b3\u5b9a\u5bf9\u8fd9\u4e2a\u538b\u7f29\u5305\u8fdb\u884c\u4ed8\u8d39\u4e0b\u8f7d\u3002\u8d2d\u4e70\u8fd9\u4e2a\u538b\u7f29\u5305\u540e\uff0c\u4f60\u53ef\u4ee5\u76f4\u63a5\u5c06\u6240\u6709\u7684\u9879\u76ee\u5bfc\u5165\u5230\u4f60\u7684\u5f00\u53d1\u73af\u5883\u4e2d\uff0c\u8282\u7701\u4f60\u7684\u65f6\u95f4\uff0c\u63d0\u9ad8\u4f60\u7684\u5f00\u53d1\u6548\u7387\u3002<\/p>\n<p><img data-dominant-color=\"f6f5f5\" data-has-transparency=\"false\" style=\"--dominant-color: #f6f5f5;\" loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-12414 not-transparent\" src=\"https:\/\/image.modbus.cn\/wp-content\/uploads\/2023\/06\/2023061203512046-800x485.png\"  width=\"800\" height=\"485\" ><\/p>\n<p>\u6240\u4ee5\uff0c\u5982\u679c\u4f60\u6b63\u5728\u5bfb\u627e\u4e00\u4e2a\u5f3a\u5927\u3001\u7075\u6d3b\u4e14\u6613\u7528\u7684Go\u8bed\u8a00Modbus\u5e93\uff0c\u90a3\u4e48gomodbus\/v2\u5c06\u662f\u4f60\u7684\u6700\u4f73\u9009\u62e9\u3002\u8d76\u5feb\u8d2d\u4e70\u8fd9\u4e2a\u538b\u7f29\u5305\uff0c\u5f00\u59cb\u4f60\u7684Modbus\u5f00\u53d1\u4e4b\u65c5\u5427\uff01<\/p>\n<span id=\"magicpostMarker\"><\/span>","protected":false},"excerpt":{"rendered":"<p>\u5728\u5de5\u4e1a\u81ea\u52a8\u5316\u548c\u63a7\u5236\u7cfb\u7edf\u5f00\u53d1\u4e2d\uff0cModbus\u534f\u8bae\u7684\u5e94\u7528\u5e7f\u6cdb\u3002\u5bf9&#8230;<\/p>","protected":false},"author":1,"featured_media":12414,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_members_access_role":[],"_members_access_error":""},"categories":[691],"tags":[643,1657,1659,1083,1658,241],"class_list":["post-12410","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-modbus-code-base","tag-ascii","tag-gomodbus-v2","tag-go","tag-modbus","tag-rtu"],"_links":{"self":[{"href":"https:\/\/www.modbus.cn\/en\/wp-json\/wp\/v2\/posts\/12410","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.modbus.cn\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.modbus.cn\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.modbus.cn\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.modbus.cn\/en\/wp-json\/wp\/v2\/comments?post=12410"}],"version-history":[{"count":0,"href":"https:\/\/www.modbus.cn\/en\/wp-json\/wp\/v2\/posts\/12410\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.modbus.cn\/en\/wp-json\/wp\/v2\/media\/12414"}],"wp:attachment":[{"href":"https:\/\/www.modbus.cn\/en\/wp-json\/wp\/v2\/media?parent=12410"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.modbus.cn\/en\/wp-json\/wp\/v2\/categories?post=12410"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.modbus.cn\/en\/wp-json\/wp\/v2\/tags?post=12410"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}