Provides communication with USB Human Interface Devices.

This package is discontinued This package does not work with Go1.6+. I won't be updating this package since a better alternative is already available, please take a look at karalabe/hid.

go.hid

This go package wraps the signal11/hidapi and provides communication with USB Human Interface Devices.

This package is not completely tested yet!

Installation:

This project depends on libhidapi, which must be installed manually.

git clone [email protected]:signal11/hidapi.git
cd hidapi
./bootstrap
./configure

Now change directory depending on your OS.

For linux + hidraw: cd linux. (requires libudev. Package libudev-dev on debian/ubuntu.)

For linux + libusb: cd libusb. (requires libusb. Package libusb-1.0-0-dev on debian/ubuntu.)

For mac: cd mac.

For windows: cd windows.

Make and install. For linux/mac:

make
sudo make install

For windows:

run some wizzard, probably.. (PR on readme is very welcome)

Lastly, for linux only: Create a symlink pointing libhidapi.so to the version you chose:

For linux + hidraw: cd /usr/local/lib; sudo ln -s libhidapi-hidraw.so libhidapi.so

For linux + libusb: cd /usr/local/lib; sudo ln -s libhidapi-libusb.so libhidapi.so

For more instructions on libhidapi, please visit signal11/hidapi.

When you have installed hidapi lib, install this package with go get github.com/GeertJohan/go.hid.

Documentation:

godoc.org/github.com/GeertJohan/go.hid

Example:

This is a simple example on how to use feature reports. For a working example view GeertJohan/mgl.

package main

import(
	"log"
	"github.com/GeertJohan/go.hid"
)

func main() {
	// open the MSI GT leds device
	leds, err := hid.Open(0x1770, 0xff00, "")
	if err != nil {
		log.Fatalf("Could not open leds device: %s", err)
	}
	defer leds.Close()

	// create a feature report. This is always 8*n+1 bytes long, where n is >1.
	data := make([]byte, 9)
	data[0] = 0x42  // report ID
	data[1] = 0x00  // dummy data
	data[2] = 0x01  // dummy data
	data[3] = 0x02  // dummy data
	data[4] = 0x03  // dummy data
	data[5] = 0x04  // dummy data
	data[6] = 0x05  // dummy data
	data[7] = 0x06  // dummy data
	data[8] = 0x07  // dummy data

	_, err := leds.SendFeatureReport(data)
	if err != nil {
		log.Fatalf("Could not send feature report to do dummy action. %s\n", err)
	}
}

License:

The go code in this project is licenced under a a Simplified BSD license. Please read the LICENSE file.

TODO:

At this point, the package works for linux with hidraw. hidapi itself is already cross-platform, so making this package work cross-platform shouldn't be a lot of work.

  • Make this package work cross-platform.
  • Add better support for hidapi init() and exit(). (At this time hidapi's init() is called once on first Open() call)
  • Add tests (find if there is a usb-hid dummy device that has expected input/output and works consistently within an OS (we can write a test file for each OS seperated))
  • Better example (preferably with a dummy test device)

History:

I started this project to be able to communicate with the MSI leds device in the MSI GT780DX laptop. For more information about that project, visit GeertJohan/mgl.

Comments
  • Fails to run with Golang 1.6+

    Fails to run with Golang 1.6+

    Unfortunately, this fails to run with the latest Golang:

    panic: runtime error: cgo argument has Go pointer to Go pointer

    goroutine 1 [running]: panic(0x4100900, 0xc82005c270) /usr/local/Cellar/go/1.6/libexec/src/runtime/panic.go:464 +0x3e6 github.com/GeertJohan/cgo%2ewchar.convertWcharStringToGoString(0xc82007c100, 0xa, 0x10, 0x0, 0x0, 0x0, 0x0) /Users/weingart/src/github.com/GeertJohan/cgo.wchar/convert.go:150 +0x521 github.com/GeertJohan/cgo%2ewchar.WcharStringPtrToGoString(0x4309800, 0x0, 0x0, 0x0, 0x0) /Users/weingart/src/github.com/GeertJohan/cgo.wchar/wchar.go:141 +0x91 github.com/GeertJohan/go%2ehid.Enumerate(0xc800000000, 0x0, 0x0, 0x0, 0x0, 0x0) /Users/weingart/src/github.com/GeertJohan/go.hid/hid.go:211 +0x3e6

    sadface

  • include hidapi sources in tree

    include hidapi sources in tree

    Hi Geert!

    I ended up with including HIDAPI sources directly in my copy of go.hid. This allows Go to leverage conditional compilation because of the various suffixes of source files. This means that "go build" will work without any problems on every platform (Windows, Linux, Mac) out of the box, without the need for any manual steps (which are different for each platform).

    I thought you might be interested in this change so I created a pull request for you.

  • Please don't include hidapi inside your source

    Please don't include hidapi inside your source

    hidapi is a cross-platform library, the included version is only for linux/hidraw. By doing so, you limit unnecessarily the scope of your library.

    Download and compile hidapi separately, then compile/install your project.

  • Any interest in libusb?

    Any interest in libusb?

    This is a fantastic Go library for HID devices! Finally, after 6+ years of sitting on some unique USB HID devices, I saw this repo and sniffed out the commands for my device (though there are other types and models out there).

    As I started to use go.hid, I quickly ran up against the limitations of the hidapi library! In particular:

    http://stackoverflow.com/questions/17706853/using-hidapi-how-can-you-query-the-raw-report-descriptor

    HIDAPI does not provide functions for getting or parsing the report descriptor. Since HIDAPI is 
    for talking to a custom devices, these devices will likely contain all or mostly vendor-defined 
    report items anyway.
    

    That's a bummer as I was attempting to query for and then enumerate over all report IDs and their descriptors as that's what my device uses.

    So I am back to investigating into the libusb C++ cross-platform project.

    https://github.com/libusb/libusb

  • Set Manufacturer to an empty string when there is an error converting it.

    Set Manufacturer to an empty string when there is an error converting it.

    Seen when enumerating the HID devices while an Xbox 360 controller is plugged in.

    Could not list devices: Could not convert *C.wchar_t manufacturer_string from hid_device_info to go string. Error: illegal byte sequence

  • Some serial number can't be decoded

    Some serial number can't be decoded

    For instance:

    FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
    

    (16x)

    this raises an error from libiconv: illegal byte sequence.

  • Errors on Linux ARM (R-Pi)

    Errors on Linux ARM (R-Pi)

    Conversion fails for some reason on raspberry pi (running linux arm and using libusb). Errors are shown below. These changes tested on linux (arm) and osx.

    ./go.hid/hid.go:597: cannot convert ws.Pointer() (type *wchar.Wchar) to type *C.wchar_t ./go.hid/hid.go:624: cannot convert ws.Pointer() (type *wchar.Wchar) to type *C.wchar_t ./go.hid/hid.go:651: cannot convert ws.Pointer() (type *wchar.Wchar) to type *C.wchar_t ./go.hid/hid.go:679: cannot convert ws.Pointer() (type *wchar.Wchar) to type *C.wchar_t

Related tags
scrapligo -- is a Go library focused on connecting to devices, specifically network devices (routers/switches/firewalls/etc.) via SSH and NETCONF.
scrapligo -- is a Go library focused on connecting to devices, specifically network devices (routers/switches/firewalls/etc.) via SSH and NETCONF.

scrapligo -- scrap(e c)li (but in go!) -- is a Go library focused on connecting to devices, specifically network devices (routers/switches/firewalls/etc.) via SSH and NETCONF.

Jan 4, 2023
A simple cli tool to convert unix timestamps or human readable dates.

now A simple cli tool to convert unix timestamps or human readable dates. Install go install github.com/gloomyzerg/now Usage now #output now unix time

Nov 23, 2021
protoCURL is cURL for Protobuf: The command-line tool for interacting with Protobuf over HTTP REST endpoints using human-readable text formats

protoCURL protoCURL is cURL for Protobuf: The command-line tool for interacting with Protobuf over HTTP REST endpoints using human-readable text forma

Jan 6, 2023
A library for communication with solar power inverters of the RCT power brand, not endorsed by or affiliated with the eponymous company.

rct A library for communication with solar power inverters of the RCT power brand. Tested with the RCT PS 6.0 solar power inverter, battery and grid p

Dec 21, 2022
Transport to allow go-libp2p applications to natively use i2p for communication

I2P Transport for go-libp2p This library can be used to build go-libp2p applications using the i2p network. Look at transport_test.go for example usag

Sep 15, 2022
Simple & Primitive multi client communication system

What is this Simple & Primitive multi client communication system. e.g. chat system for larning Supported Broadcast message Unicast message Not Suppor

Dec 3, 2021
Episode VII: The DB Awakens (fully stablished JSON communication system)

APITrials0.7 Episode VII: The DB Awakens (fully stablished JSON communication system) Captain's log: Im too deep into the rabbit hole now. This seems

Jan 10, 2022
ACN - Agent Communication Network

The libp2p_node is an integral part of the ACN. ACN - Agent Communication Network The agent communication network (ACN) provides a system for agents t

Sep 28, 2022
Furui - A process-based communication control system for containers

furui Communication control of the container runtime environment(now only docker

Mar 26, 2022
Jazigo is a tool written in Go for retrieving configuration for multiple devices, similar to rancid, fetchconfig, oxidized, Sweet.

Table of Contents About Jazigo Supported Platforms Features Requirements Quick Start - Short version Quick Start - Detailed version Global Settings Im

Jan 5, 2023
mdmb is a tool for simulating Apple devices interacting with Apple MDM servers.

mdmb mdmb — short for MDM Benchmark, à la ab — is a tool for simulating Apple devices interacting with Apple MDM servers. mdmb creates sets of fake Ap

Dec 1, 2022
communicate with iOS devices implemented with Golang

Golang-iDevice much more easy to use ?? electricbubble/gidevice-cli Installation go get github.com/electricbubble/gidevice Devices package main impor

Dec 18, 2022
Automatically compress podcasts to tiny file sizes for bandwidth constrained devices like cellular.
Automatically compress podcasts to tiny file sizes for bandwidth constrained devices like cellular.

tinycast Automatically compress podcasts to tiny file sizes for bandwidth constrained connections like cellular or satellite.

Sep 18, 2022
Connect your devices into a single private WireGuard®-based mesh network.

Wiretrustee A WireGuard®-based mesh network that connects your devices into a single private network. Why using Wiretrustee? Connect multiple devices

Dec 31, 2022
Tool for monitoring network devices (mainly using SNMP) - monitoring check plugin
Tool for monitoring network devices (mainly using SNMP) - monitoring check plugin

Thola Description A tool for monitoring network devices written in Go. It features a check mode which complies with the monitoring plugins development

Dec 29, 2022
Prometheus exporter for counting connected devices to a network using nmap

nmapprom Prometheus exporter for counting the hosts connected to a network using nmap · Report Bug · Request Feature Table of Contents About The Proje

Oct 17, 2021
Manage SwOS devices

swosman Manage SwOS devices This application for management MikroTik devices running of SWoS TODO Link Getting setting Save new setting Getting status

Dec 7, 2022
Demo of EdgeX Foundry Ireland (or Jakarta) release with real Modbus, SNMP and GPIO pin devices

Ireland Demo This demo shows the Ireland (or Jakarta - it works for both) release of EdgeX with the following devices: Comet Systems T0310 temperature

Nov 6, 2021
Nomad plugin for reserving device mappings used by ebs devices.

Nomad Skeleton Device Plugin Skeleton project for Nomad device plugins. This project is intended for bootstrapping development of a new device plugin.

Jan 5, 2022