panic: invalid or incomplete multibyte or wide character #762

Closed
opened 2025-11-19 01:03:56 -06:00 by hiifong · 0 comments
hiifong commented 2025-11-19 01:03:56 -06:00 (Migrated from github.com)

demo code:

package main

import (
        "fmt"
        "log"

        "github.com/sstallion/go-hid"
)

func main() {
        b := make([]byte, 65)

        // Initialize the hid package.
        if err := hid.Init(); err != nil {
                log.Fatal(err)
        }

        // Open the device using the VID and PID.
        d, err := hid.OpenFirst(0xe0f, 0x03)
        if err != nil {
                log.Fatal(err)
        }

        // Read the Manufacturer String.
        s, err := d.GetMfrStr()
        if err != nil {
                log.Fatal(err)
        }
        fmt.Printf("Manufacturer String: %s\n", s)

        // Read the Product String.
        s, err = d.GetProductStr()
        if err != nil {
                log.Fatal(err)
        }
        fmt.Printf("Product String: %s\n", s)

        // Read the Serial Number String.
        s, err = d.GetSerialNbr()
        if err != nil {
                log.Fatal(err)
        }
        fmt.Printf("Serial Number String: %s\n", s)

        // Read Indexed String 1.
        s, err = d.GetIndexedStr(1)
        if err != nil {
                log.Fatal(err)
        }
        fmt.Printf("Indexed String 1: %s\n", s)

        // Toggle LED (cmd 0x80). The first byte is the report number (0x0).
        b[0] = 0x0
        b[1] = 0x80
        if _, err := d.Write(b); err != nil {
                log.Fatal(err)
        }

        // Request state (cmd 0x81). The first byte is the report number (0x0).
        b[0] = 0x0
        b[1] = 0x81
        if _, err := d.Write(b); err != nil {
                log.Fatal(err)
        }

        // Read requested state.
        if _, err := d.Read(b); err != nil {
                log.Fatal(err)
        }
}

error:

Manufacturer String: VMware
Product String: VMware Virtual USB Mouse
panic: invalid or incomplete multibyte or wide character

goroutine 1 [running]:
github.com/sstallion/go-hid.wcstogo(0x266dbbb0)
        /home/kyle/go/pkg/mod/github.com/sstallion/go-hid@v0.15.0/wchar.go:75 +0x1b0
github.com/sstallion/go-hid.(*Device).GetSerialNbr(0xc0000140c0)
        /home/kyle/go/pkg/mod/github.com/sstallion/go-hid@v0.15.0/hid.go:370 +0x171
main.main()
        /home/kyle/Desktop/workspace/hid-demo1/main.go:39 +0x225
demo code: ```go package main import ( "fmt" "log" "github.com/sstallion/go-hid" ) func main() { b := make([]byte, 65) // Initialize the hid package. if err := hid.Init(); err != nil { log.Fatal(err) } // Open the device using the VID and PID. d, err := hid.OpenFirst(0xe0f, 0x03) if err != nil { log.Fatal(err) } // Read the Manufacturer String. s, err := d.GetMfrStr() if err != nil { log.Fatal(err) } fmt.Printf("Manufacturer String: %s\n", s) // Read the Product String. s, err = d.GetProductStr() if err != nil { log.Fatal(err) } fmt.Printf("Product String: %s\n", s) // Read the Serial Number String. s, err = d.GetSerialNbr() if err != nil { log.Fatal(err) } fmt.Printf("Serial Number String: %s\n", s) // Read Indexed String 1. s, err = d.GetIndexedStr(1) if err != nil { log.Fatal(err) } fmt.Printf("Indexed String 1: %s\n", s) // Toggle LED (cmd 0x80). The first byte is the report number (0x0). b[0] = 0x0 b[1] = 0x80 if _, err := d.Write(b); err != nil { log.Fatal(err) } // Request state (cmd 0x81). The first byte is the report number (0x0). b[0] = 0x0 b[1] = 0x81 if _, err := d.Write(b); err != nil { log.Fatal(err) } // Read requested state. if _, err := d.Read(b); err != nil { log.Fatal(err) } } ``` error: ```go Manufacturer String: VMware Product String: VMware Virtual USB Mouse panic: invalid or incomplete multibyte or wide character goroutine 1 [running]: github.com/sstallion/go-hid.wcstogo(0x266dbbb0) /home/kyle/go/pkg/mod/github.com/sstallion/go-hid@v0.15.0/wchar.go:75 +0x1b0 github.com/sstallion/go-hid.(*Device).GetSerialNbr(0xc0000140c0) /home/kyle/go/pkg/mod/github.com/sstallion/go-hid@v0.15.0/hid.go:370 +0x171 main.main() /home/kyle/Desktop/workspace/hid-demo1/main.go:39 +0x225 ```
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-libusb/hidapi#762
No description provided.