Working with USB in Go

huangapple go评论114阅读模式
英文:

Working with USB in Go

问题

有人可以提供一个使用go-libusb(或者其他在Golang中与USB一起工作的库)的示例吗?

  1. 我已经创建了libusb包。
  2. 从https://github.com/popons/go-libusb/blob/main/libusb.go复制了内容。

出现了一个错误:

未解析的符号:'_Cstruct_usb_device_descriptor'

谢谢。

英文:

Can somebody provide an example of using go-libusb (or may be any other lib working with USB in Golang) .

  1. I have created package libusb
  2. Copied the content from https://github.com/popons/go-libusb/blob/main/libusb.go

There is an error:

Unresolved symbol: '_Cstruct_usb_device_descriptor' 

Thank you.

答案1

得分: 3

首先,你需要从http://www.libusb.org/wiki/libusb-win32安装libusb,然后将// #include<usb.h>更改为:

/*
    #cgo LDFLAGS: -lusb
    #include <usb.h>
*/

descriptor _Cstruct_usb_device_descriptor更改为descriptor C.struct_usb_device_descriptor

或者从https://github.com/OneOfOne/go-libusb拉取我的分支,我已经发送了一个带有更改的拉取请求。

英文:

First you have to install libusb from http://www.libusb.org/wiki/libusb-win32, then either change // #include<usb.h> to:

/*
    #cgo LDFLAGS: -lusb
    #include <usb.h>
*/

And descriptor _Cstruct_usb_device_descriptor to descriptor C.struct_usb_device_descriptor.

Or pull my fork from https://github.com/OneOfOne/go-libusb, I already sent a pull request with the changes.

答案2

得分: 3

go-libusb包是由popons开发的一个对libusb-0.1基于C语言的USB驱动程序的封装。libusb-0.1已经被宣布为“废弃且不再维护”。[来源:libusb API版本概述]

如果要在Go中使用USB,我建议使用一个libusb 1.0GitHub上的源代码),例如:

  • gousb — 最初由Kyle Lemons创建。还有一些更新的分支,比如truveris的分支。
  • libusb声明:我是原始创建者。

上述两个Go驱动程序都需要安装C版本的libusb。在Windows上安装,请参考libusb Windows驱动程序安装说明,该说明建议使用Zadig。你也可以查看SO问题在Windows 7上安装libusb-1.0,但唯一的答案似乎只展示了如何安装libusb-0.1而不是libusb-1.0。

作为Windows用户,我知道这对你没有帮助,但对于OS X用户,可以使用Homebrew来安装libusb:

$ brew install libusb
英文:

The go-libusb package by popons is a wrapper for the libusb-0.1 C-based USB driver. libusb-0.1 is "deprecated and unmaintained." [Source: libusb API version overview]

For using USB with Go, I'd recommend using a libusb 1.0 (source on GitHub) Go-driver, such as:

  • gousb — Originally created by Kyle Lemons. There are newer forks, such as the one by truveris.
  • libusbDiscloure: I'm the original creator.

Both of the above Go drivers require having the C-version of libusb installed. To install on Windows, take a look at the libusb Windows driver installation instructions, which recommend using Zadig. You could also look at the SO question Installing libusb-1.0 on Windows 7, but the only answer appears to show how to install libusb-0.1 not libusb-1.0.

As a Windows user, I know this doesn't help you, but for OS X users, libusb can be installed using Homebrew:

$ brew install libusb

huangapple
  • 本文由 发表于 2014年7月12日 03:24:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/24705072.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定