{"id":207622,"date":"2025-07-08T10:03:31","date_gmt":"2025-07-08T02:03:31","guid":{"rendered":"https:\/\/server.hk\/cnblog\/207622\/"},"modified":"2025-07-08T10:03:31","modified_gmt":"2025-07-08T02:03:31","slug":"%e4%bb%8e-go-%e4%bd%bf%e7%94%a8-siusbxp-%e7%9a%84%e6%ad%a3%e7%a1%ae%e6%96%b9%e6%b3%95%e6%98%af%e4%bb%80%e4%b9%88%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/207622\/","title":{"rendered":"\u4ece Go \u4f7f\u7528 SIUSBXP \u7684\u6b63\u786e\u65b9\u6cd5\u662f\u4ec0\u4e48\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>\u4ece Go \u4f7f\u7528 SIUSBXP \u7684\u6b63\u786e\u65b9\u6cd5\u662f\u4ec0\u4e48\uff1f<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-24 08:33:35<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u201c\u7eb5\u6709\u75be\u98ce\u6765\uff0c\u4eba\u751f\u4e0d\u8a00\u5f03\u201d\uff0c\u8fd9\u53e5\u8bdd\u9001\u7ed9\u6b63\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">Golang<\/span>\u7684\u670b\u53cb\u4eec\uff0c\u4e5f\u5e0c\u671b\u5728\u9605\u8bfb\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u4ece Go \u4f7f\u7528 SIUSBXP \u7684\u6b63\u786e\u65b9\u6cd5\u662f\u4ec0\u4e48\uff1f\u300b<\/span>\u540e\uff0c\u80fd\u591f\u771f\u7684\u5e2e\u52a9\u5230\u5927\u5bb6\u3002\u6211\u4e5f\u4f1a\u5728\u540e\u7eed\u7684\u6587\u7ae0\u4e2d\uff0c\u9646\u7eed\u66f4\u65b0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">Golang<\/span>\u76f8\u5173\u7684\u6280\u672f\u6587\u7ae0\uff0c\u6709\u597d\u7684\u5efa\u8bae\u6b22\u8fce\u5927\u5bb6\u5728\u8bc4\u8bba\u7559\u8a00\uff0c\u975e\u5e38\u611f\u8c22\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u6709\u4e00\u4e2a\u53ef\u901a\u8fc7 SIUSBXP (Silicon Labs) \u8bbf\u95ee\u7684\u786c\u4ef6\u3002<\/p>\n<p>\u6709\u6ca1\u6709\u529e\u6cd5\u76f4\u63a5\u4ece Go \u8bbf\u95ee\u786c\u4ef6\uff1f <\/p>\n<p>\u6216\u8005\u6211\u5e94\u8be5\u7f16\u5199\u4e00\u4e2a C\/C++ \u5305\u88c5\u5668\u5e76\u5c06\u5176\u94fe\u63a5\u5230\u6211\u7684 Go \u7a0b\u5e8f\uff1f<\/p>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>\u7279\u522b\u662f\u5173\u4e8e\u8fd9\u4e2a dll\uff0c\u6211\u8ba9\u8fd9\u4e2a\u52a8\u7269\u53d1\u6325\u4f5c\u7528\uff1a<\/p>\n<pre>siusbxp                      = syscall.mustloaddll(\"siusbxp.dll\")\nsigetnumdevices              = siusbxp.mustfindproc(\"si_getnumdevices\")\nsigetproductstring           = siusbxp.mustfindproc(\"si_getproductstring\")\n.\n.\n.\n... and so on...<\/pre>\n<p>\u8fd9\u6837\uff0cdll \u7531\u7b2c\u4e00\u884c\u52a0\u8f7d\uff0c\u6240\u9700\u7684\u51fd\u6570\u5728\u5176\u4ed6\u884c\u4e2d\u5f15\u7528\u3002<\/p>\n<p>\u8c03\u7528\u51fd\u6570\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>func GetNumDevices() int {\nvar lpdwNumDevices int\nr1, _, _ := SIGetNumDevices.Call(uintptr(unsafe.Pointer(&amp;lpdwNumDevices)))\n\nif int(r1) == StatusSISUCCESS {\n    if lpdwNumDevices == 1 {\n        log.Println(lpdwNumDevices,\"hardware(s) found\")\n    }\n    return lpdwNumDevices\n}\n\nreturn -1\n}<\/pre>\n<p>\u636e\u6211\u6240\u77e5\uff0c\u5f53\u60a8\u9700\u8981\u4e0e\u53e6\u4e00\u4e2a dll \u901a\u4fe1\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u8fd9\u79cd\u4ee3\u7801\u3002<\/p>\n<p>\u8bf7\u6ce8\u610f\uff0c\u6211\u6ca1\u6709\u4f7f\u7528 cgo\u3002<\/p>\n<p>\u7ec8\u4e8e\u4ecb\u7ecd\u5b8c\u5566\uff01\u5c0f\u4f19\u4f34\u4eec\uff0c\u8fd9\u7bc7\u5173\u4e8e\u300a\u4ece Go \u4f7f\u7528 SIUSBXP \u7684\u6b63\u786e\u65b9\u6cd5\u662f\u4ec0\u4e48\uff1f\u300b\u7684\u4ecb\u7ecd\u5e94\u8be5\u8ba9\u4f60\u6536\u83b7\u591a\u591a\u4e86\u5427\uff01\u6b22\u8fce\u5927\u5bb6\u6536\u85cf\u6216\u5206\u4eab\u7ed9\u66f4\u591a\u9700\u8981\u5b66\u4e60\u7684\u670b\u53cb\u5427~\u516c\u4f17\u53f7\u4e5f\u4f1a\u53d1\u5e03Golang\u76f8\u5173\u77e5\u8bc6\uff0c\u5feb\u6765\u5173\u6ce8\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-207622","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207622","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=207622"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207622\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=207622"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=207622"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=207622"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}