-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
67 lines (48 loc) · 1.07 KB
/
main.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
65
66
67
package main
import (
"github.com/lyimmi/usbrelay"
"log"
"time"
)
func main() {
devices, err := usbrelay.Enumerate()
if len(devices) < 1 {
log.Fatalln("no device detected")
}
device := devices[0]
log.Println(device.GetSerialNumber())
err = device.Open(true)
if err != nil {
log.Fatal(err)
}
defer device.Close()
if err = device.On(usbrelay.R_ALL); err != nil {
log.Fatalln(err)
}
time.Sleep(500 * time.Millisecond)
if err = device.Off(usbrelay.R_ALL); err != nil {
log.Fatalln(err)
}
time.Sleep(500 * time.Millisecond)
for i := 1; i <= device.RelayCount(); i++ {
ch := usbrelay.RelayNumber(i)
if err = device.On(ch); err != nil {
log.Fatalln(err)
}
time.Sleep(100 * time.Millisecond)
if err := device.Off(ch); err != nil {
log.Fatalln(err)
}
}
time.Sleep(500 * time.Millisecond)
for i := device.RelayCount(); i > 0; i-- {
ch := usbrelay.RelayNumber(i)
if err = device.Toggle(ch); err != nil {
log.Fatalln(err)
}
time.Sleep(100 * time.Millisecond)
if err := device.Toggle(ch); err != nil {
log.Fatalln(err)
}
}
}