blob: d9b3d4df3ac617c5a116b542d714107a2409d9b7 (
plain) (
blame)
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
|
package main
import (
"io"
"log"
"os"
"snix.ir/userial"
)
// we need something to read, so we gonna mess with terminal..
const cisco_router_cmd = `
enable
show ip int br
conf t
int gig0/0
ip addr 192.168.122.200 255.255.255.0
no shut
do show ip int br
`
func main() {
// default conf
p, err := serial.NewSerial().OpenPort("/dev/ttyACM0")
// serial port with custom config
//
// p_dev := "/dev/ttyACM0"
// s := serial.NewSerial().SetBuadRate(serial.B0019200)
// p, err = s.SetParity(serial.ParityEvn).OpenPort(p_dev)
if err != nil {
log.Fatal(err)
}
defer p.Close()
if _, err := p.Write([]byte(cisco_router_cmd)); err != nil {
panic(err)
}
if _, err := io.Copy(os.Stdout, p); err != nil {
panic(err)
}
}
|