package main
import (
"fmt"
"github.com/karalabe/hid"
)
func main() {
// Ledger Nano S Vendor ID and Product ID
vendorID := uint16(0x2c97)
productID := uint16(0x1015)
// Enumerate devices to find the Ledger
devices := hid.Enumerate(vendorID, productID)
if len(devices) == 0 {
fmt.Println("No Ledger Nano S found.")
return
}
// Open the first found Ledger device
device, err := devices[0].Open()
if err != nil {
fmt.Printf("Failed to open device: %v\n", err)
return
}
defer device.Close()
fmt.Println("Device successfully opened.")
}
Output:
Failed to open device: hidapi: failed to open device
While it is possible to open/connect using homebrew's hidapi like this:
package main
/*
#cgo CFLAGS: -I/opt/homebrew/Cellar/hidapi/0.14.0/include/hidapi
#cgo LDFLAGS: -L/opt/homebrew/Cellar/hidapi/0.14.0/lib -lhidapi
#include <hidapi.h>
*/
import "C"
import (
"fmt"
)
func main() {
// Initialize the HIDAPI library
res := C.hid_init()
if res != 0 {
fmt.Println("Failed to initialize HIDAPI")
return
}
defer C.hid_exit()
// Open the device using Vendor ID and Product ID
vendorID := C.ushort(0x2c97)
productID := C.ushort(0x1015)
device := C.hid_open(vendorID, productID, nil)
if device == nil {
fmt.Println("Failed to open device")
return
}
defer C.hid_close(device)
// Your HID interaction code here
fmt.Println("Device opened successfully")
}
I tried with this minimal test program:
Output:
While it is possible to open/connect using homebrew's hidapi like this:
Output: