forked from popons/go-libusb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
libusb_test.go
64 lines (51 loc) · 1.32 KB
/
libusb_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package libusb
import "fmt"
import "os"
import "testing"
type method func()
func enum() {
Init()
for i, info := range Enum() {
fmt.Printf("======================================================\n")
fmt.Printf(" %10d : BUS:%s DEVICE:%s VID:%04x PID:%04x\n", i, info.Bus, info.Device, info.Vid, info.Pid)
dev := Open(info.Vid, info.Pid)
if dev != nil {
fmt.Printf(" Vendor : %s\n", dev.Vendor())
fmt.Printf(" Product : %s\n", dev.Product())
fmt.Printf(" Last Error : %s\n", dev.LastError())
dev.Close()
} else {
os.Exit(1)
}
}
}
func conf() {
vid, pid := 0x04b4, 0x8613
Init()
device := Open(vid, pid)
println("dev=", device)
println("dev.bus=", device.Bus)
println("dev.dev=", device.Device)
println("dev.handle=", device.handle)
fmt.Printf(" Last Error : %s\n", device.LastError())
var r int
r = device.Configuration(1)
println("Configuration=", r)
fmt.Printf(" Last Error : %s\n", device.LastError())
device.Interface(0)
println("Interface=", r)
fmt.Printf(" Last Error : %s\n", device.LastError())
device.Close()
}
var methods = []method{
enum,
//conf,
}
func TestAll(t *testing.T) {
for i, method := range methods {
println("==============================================")
println("========= test ", i)
println("==============================================")
method()
}
}