aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorroot <sina@snix.ir>2022-05-09 21:20:21 +0000
committerroot <sina@snix.ir>2022-05-09 21:20:21 +0000
commitc48313b3056d78d79234ba0bfd8e9c5a52770dff (patch)
tree7418f48e3223e1711daf923fa3a899f720847961
parentdfc09eb52aaa0d171922e890fa8daac1647a2c8b (diff)
add Readme.md file
-rw-r--r--Readme.md82
1 files changed, 82 insertions, 0 deletions
diff --git a/Readme.md b/Readme.md
new file mode 100644
index 0000000..fddcffe
--- /dev/null
+++ b/Readme.md
@@ -0,0 +1,82 @@
+
+# userial
+
+linux serial package for handling serial ports with go, this package is just for serial ports and may not be suitable for all kind of terminals.. see [termios(3)](https://linux.die.net/man/3/termios)
+
+- this package should work with generic serial ports and standard baudrate
+- userial currently only works with linux (im not planing to use this with any other os'es)
+
+
+### how to use userial
+
+userial lives on [github](https://github.com/sina-ghaderi/userial) and [snix](https://git.snix.ir/userial) git repositories, in order to use this package you should run one of the following commands
+
+
+get userial from snix repository `go mod download snix.ir/userial` or github `go mod download github.com/sina-ghaderi/userial`
+
+### examples
+simple read and write with cisco router serial port
+```go
+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
+conf t
+int gig0/0
+ip addr 192.168.122.200 255.255.255.0
+no shut
+do show ip int br
+
+`
+
+func main() {
+ p, err := serial.NewSerial().OpenPort("/dev/ttyACM0")
+ 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)
+ }
+}
+
+```
+note that `/dev/ttyACM0` indicate serial port device which opened with default configuration.
+above program read data from serial port and write it on stdout..
+
+```
+
+Router>
+Router>
+Router>enable
+Router#conf t
+Enter configuration commands, one per line. End with CNTL/Z.
+Router(config)#int gig0/0
+Router(config-if)#ip addr 192.168.122.200 255.255.255.0
+Router(config-if)#no shut
+Router(config-if)#
+Router(config-if)#do show ip int br
+Interface IP-Address OK? Method Status Protocol
+Embedded-Service-Engine0/0 unassigned YES unset administratively down down
+GigabitEthernet0/0 192.168.122.200 YES manual down down
+GigabitEthernet0/1 unassigned YES unset administratively down down
+Router(config-if)#
+```
+
+### licence
+Copyright 2021 SNIX LLC sina@snix.ir
+This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation.
+This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

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