aboutsummaryrefslogtreecommitdiff
path: root/example/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'example/main.go')
-rw-r--r--example/main.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/example/main.go b/example/main.go
new file mode 100644
index 0000000..76b8079
--- /dev/null
+++ b/example/main.go
@@ -0,0 +1,51 @@
+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)
+ }
+
+}

Snix LLC Git Repository Holder Copyright(C) 2022 All Rights Reserved Email To Snix.IR