From 65e4b3f13317068bbdaa62fef63f2bb7b1e64fb2 Mon Sep 17 00:00:00 2001 From: Philip Z Date: Sun, 15 Jul 2018 23:57:36 +0800 Subject: [PATCH 01/15] Update open_linux.go --- serial/open_linux.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/serial/open_linux.go b/serial/open_linux.go index ccce12c..5496ee0 100644 --- a/serial/open_linux.go +++ b/serial/open_linux.go @@ -27,7 +27,7 @@ import ( const ( kTCSETS2 = 0x402C542B kBOTHER = 0x1000 - kNCCS = 19 + kNCCS = 23 //fix for openwrt ) // From 29d9bc2b0a51debde6161cb0b07181246f8885a7 Mon Sep 17 00:00:00 2001 From: Philip Z Date: Sun, 15 Jul 2018 23:58:28 +0800 Subject: [PATCH 02/15] Update README.markdown --- README.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.markdown b/README.markdown index e635e50..228c21e 100644 --- a/README.markdown +++ b/README.markdown @@ -17,11 +17,11 @@ Installation Simply use `go get`: - go get github.com/jacobsa/go-serial/serial + go get github.com/philipgreat/go-serial/serial To update later: - go get -u github.com/jacobsa/go-serial/serial + go get -u github.com/philipgreat/go-serial/serial Use From 71a01158241969e5e5c3b89ae06132595bb3fa0b Mon Sep 17 00:00:00 2001 From: Philip Z Date: Sun, 15 Jul 2018 23:58:54 +0800 Subject: [PATCH 03/15] Update README.markdown --- README.markdown | 75 ++++++++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 32 deletions(-) diff --git a/README.markdown b/README.markdown index 228c21e..cb9497d 100644 --- a/README.markdown +++ b/README.markdown @@ -30,38 +30,49 @@ Use Set up a `serial.OpenOptions` struct, then call `serial.Open`. For example: ````go - import "fmt" - import "log" - import "github.com/jacobsa/go-serial/serial" - - ... - - // Set up options. - options := serial.OpenOptions{ - PortName: "/dev/tty.usbserial-A8008HlV", - BaudRate: 19200, - DataBits: 8, - StopBits: 1, - MinimumReadSize: 4, - } - - // Open the port. - port, err := serial.Open(options) - if err != nil { - log.Fatalf("serial.Open: %v", err) - } - - // Make sure to close it later. - defer port.Close() - - // Write 4 bytes to the port. - b := []byte{0x00, 0x01, 0x02, 0x03} - n, err := port.Write(b) - if err != nil { - log.Fatalf("port.Write: %v", err) - } - - fmt.Println("Wrote", n, "bytes.") + package main + +//env GOOS=linux GOARCH=mips go build -ldflags "-s -w" mem.go +import ( + "fmt" + "log" + + "github.com/philipgreat/go-serial/serial" +) + +func main() { + // Below is an example of using our PrintMemUsage() function + // Print our starting memory usage (should be around 0mb) + options := serial.OpenOptions{ + PortName: "/dev/ttyUSB0", + BaudRate: 38400, + DataBits: 8, + StopBits: 1, + MinimumReadSize: 4, + } + port, err := serial.Open(options) + if err != nil { + log.Fatalf("serial.Open: %v", err) + } + defer port.Close() + b := []byte{0x28, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, + 0x00, 0x00, 0x80, 0x05, 0x98, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x1F, 0x00, 0x08, 0x12, 0x21, 0x00, 0x00, 0x64, 0x00, 0x64, 0x00, + 0x64, 0x00, 0x64, 0x00, 0x64, 0x00, 0xFC, 0x63} + n, err := port.Write(b) + if err != nil { + log.Fatalf("port.Write: %v", err) + } + + fmt.Println("Wrote", n, "bytes.") + buf := make([]byte, 128) + n, err = port.Read(buf) + if err != nil { + log.Fatalf("port.Write: %v", err) + } + +} + ```` See the documentation for the `OpenOptions` struct in `serial.go` for more From f2b1cf89793e0e0e3a1a3d3bf3c434254b77fbd6 Mon Sep 17 00:00:00 2001 From: Philip Z Date: Mon, 16 Jul 2018 00:12:21 +0800 Subject: [PATCH 04/15] Update open_linux.go --- serial/open_linux.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/serial/open_linux.go b/serial/open_linux.go index 5496ee0..d9e0fa5 100644 --- a/serial/open_linux.go +++ b/serial/open_linux.go @@ -25,11 +25,17 @@ import ( // } // const ( - kTCSETS2 = 0x402C542B - kBOTHER = 0x1000 + kTCSETS2 = 0x8030542B + kBOTHER = 0x00001000 kNCCS = 23 //fix for openwrt ) +/* +TCSETS2 = 0x8030542B +BOTHER = 0x00001000 + +NCCS = 23 +*/ // // Types from asm-generic/termbits.h // From 30bb59c5c300c812e3d0dfadc9c08edd194212f7 Mon Sep 17 00:00:00 2001 From: Philip Z Date: Mon, 16 Jul 2018 00:33:25 +0800 Subject: [PATCH 05/15] Update README.markdown --- README.markdown | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/README.markdown b/README.markdown index cb9497d..a51ae06 100644 --- a/README.markdown +++ b/README.markdown @@ -11,6 +11,32 @@ Currently this package works only on OS X, Linux and Windows. It could probably to other Unix-like platforms simply by updating a few constants; get in touch if you are interested in helping and have hardware to test with. +The master works with OpenWrt With the following change +````go +// #include +// #include +// #include +// +// int main(int argc, const char **argv) { +// printf("TCSETS2 = 0x%08X\n", TCSETS2); +// printf("BOTHER = 0x%08X\n", BOTHER); +// printf("NCCS = %d\n", NCCS); +// return 0; +// } +// +const ( + kTCSETS2 = 0x402C542B + kBOTHER = 0x1000 + kNCCS = 19 +) +following works with PC linux +TCSETS2 = 0x402C542B +BOTHER = 0x00001000 +NCCS = 19 + + + +```` Installation ------------ @@ -24,6 +50,7 @@ To update later: go get -u github.com/philipgreat/go-serial/serial + Use --- From 59720b46ec4067bbfe3d9fb532196e12e2fc2bf1 Mon Sep 17 00:00:00 2001 From: Philip Z Date: Mon, 16 Jul 2018 00:48:19 +0800 Subject: [PATCH 06/15] Update open_linux.go --- serial/open_linux.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/serial/open_linux.go b/serial/open_linux.go index d9e0fa5..14d4d18 100644 --- a/serial/open_linux.go +++ b/serial/open_linux.go @@ -25,9 +25,9 @@ import ( // } // const ( - kTCSETS2 = 0x8030542B - kBOTHER = 0x00001000 - kNCCS = 23 //fix for openwrt + kTCSETS2 = unix.TCSETS2 //0x8030542B + kBOTHER = unix.BOTHER//0x00001000 + kNCCS = unix.NCCS //fix for openwrt ) /* TCSETS2 = 0x8030542B From d7c27e81ce2b6618238b692539285ac2a7a9a51e Mon Sep 17 00:00:00 2001 From: Philip Z Date: Mon, 16 Jul 2018 00:51:03 +0800 Subject: [PATCH 07/15] Update open_linux.go --- serial/open_linux.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/serial/open_linux.go b/serial/open_linux.go index 14d4d18..c8e419e 100644 --- a/serial/open_linux.go +++ b/serial/open_linux.go @@ -27,7 +27,7 @@ import ( const ( kTCSETS2 = unix.TCSETS2 //0x8030542B kBOTHER = unix.BOTHER//0x00001000 - kNCCS = unix.NCCS //fix for openwrt + kNCCS = 23 // unix.NCCS //fix for openwrt ) /* TCSETS2 = 0x8030542B From a56faaa20d8cb403e1af9ad46b6c1432471ee7fe Mon Sep 17 00:00:00 2001 From: Philip Z Date: Mon, 16 Jul 2018 01:17:22 +0800 Subject: [PATCH 08/15] Update open_linux.go --- serial/open_linux.go | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/serial/open_linux.go b/serial/open_linux.go index c8e419e..dfef211 100644 --- a/serial/open_linux.go +++ b/serial/open_linux.go @@ -24,10 +24,50 @@ import ( // return 0; // } // +/*386 +amd64 +amd64p32 +arm +armbe +arm64 +arm64be +ppc64 +ppc64le +mips +mipsle +mips64 +mips64le +mips64p32 +mips64p32le +ppc +s390 +s390x +sparc +sparc64 +and reference +https://github.com/mojo-runtime/lib-linux/blob/6dbfa74d17beda9be9c6e3b595c76f8df3cbb077/c/struct-termios.h +*/ +func nccs() int { + if runtime.GOARCH == "mips" { + return 23 + } + if runtime.GOARCH == "mipsle" { + return 23 + } + if runtime.GOARCH == "spark" { + return 17 + } + if runtime.GOARCH == "sparc64" { + return 17 + } + return 19 + +} + const ( kTCSETS2 = unix.TCSETS2 //0x8030542B kBOTHER = unix.BOTHER//0x00001000 - kNCCS = 23 // unix.NCCS //fix for openwrt + kNCCS = nccs() // unix.NCCS //fix for openwrt ) /* TCSETS2 = 0x8030542B From 121cb61d61ccb98e7fdac479039b104dbd791c49 Mon Sep 17 00:00:00 2001 From: Philip Z Date: Wed, 18 Jul 2018 00:52:45 +0800 Subject: [PATCH 09/15] Update open_linux.go --- serial/open_linux.go | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/serial/open_linux.go b/serial/open_linux.go index dfef211..7b6928c 100644 --- a/serial/open_linux.go +++ b/serial/open_linux.go @@ -47,20 +47,12 @@ sparc64 and reference https://github.com/mojo-runtime/lib-linux/blob/6dbfa74d17beda9be9c6e3b595c76f8df3cbb077/c/struct-termios.h */ +nccsValueMap := map[string]int{"mips": 23, "mips64": 23, "spark": 17, "spark64": 24, "other": 19} func nccs() int { - if runtime.GOARCH == "mips" { - return 23 + const value = nccsValueMap[runtime.GOARCH] + if value == nil{ + return 19 } - if runtime.GOARCH == "mipsle" { - return 23 - } - if runtime.GOARCH == "spark" { - return 17 - } - if runtime.GOARCH == "sparc64" { - return 17 - } - return 19 } From 9552173c649901bf79e3bdb22e2f580faad25a82 Mon Sep 17 00:00:00 2001 From: Philip Z Date: Wed, 18 Jul 2018 01:23:16 +0800 Subject: [PATCH 10/15] Update open_linux.go --- serial/open_linux.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/serial/open_linux.go b/serial/open_linux.go index 7b6928c..98b6642 100644 --- a/serial/open_linux.go +++ b/serial/open_linux.go @@ -47,13 +47,13 @@ sparc64 and reference https://github.com/mojo-runtime/lib-linux/blob/6dbfa74d17beda9be9c6e3b595c76f8df3cbb077/c/struct-termios.h */ -nccsValueMap := map[string]int{"mips": 23, "mips64": 23, "spark": 17, "spark64": 24, "other": 19} func nccs() int { - const value = nccsValueMap[runtime.GOARCH] - if value == nil{ + var nccsValueMap = map[string]int{"mips": 23, "mips64": 23, "spark": 17, "spark64": 24, "other": 19} + var value = nccsValueMap[runtime.GOARCH] + if value == 0 { return 19 } - + return value } const ( From 2099e3a2e4bb87792dbde866693bd9ae8c29530e Mon Sep 17 00:00:00 2001 From: Philip Z Date: Mon, 5 Aug 2019 07:32:27 +0800 Subject: [PATCH 11/15] Update open_linux.go --- serial/open_linux.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/serial/open_linux.go b/serial/open_linux.go index 98b6642..58efc92 100644 --- a/serial/open_linux.go +++ b/serial/open_linux.go @@ -59,7 +59,7 @@ func nccs() int { const ( kTCSETS2 = unix.TCSETS2 //0x8030542B kBOTHER = unix.BOTHER//0x00001000 - kNCCS = nccs() // unix.NCCS //fix for openwrt + kNCCS = 23 // 23 is the value fix for MIPS. most of the OpenWrt routers installed with MIPS cpu. ) /* TCSETS2 = 0x8030542B From 232b503e61ee5dd76dd2f190718d36c0546a55e9 Mon Sep 17 00:00:00 2001 From: Philip Z Date: Mon, 5 Aug 2019 07:36:29 +0800 Subject: [PATCH 12/15] Update README.markdown --- README.markdown | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.markdown b/README.markdown index a51ae06..1cd112d 100644 --- a/README.markdown +++ b/README.markdown @@ -4,6 +4,12 @@ go-serial This is a package that allows you to read from and write to serial ports in Go. +CPU and OS support +---------- + +This fork works only with MIPS cpu, most openwrt routers equipped with MIPS CPU. + + OS support ---------- From d0650f32a1557355744fdfc7765c58a752e5ac1c Mon Sep 17 00:00:00 2001 From: Philip Z Date: Mon, 5 Aug 2019 07:37:18 +0800 Subject: [PATCH 13/15] Update README.markdown --- README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index 1cd112d..f471087 100644 --- a/README.markdown +++ b/README.markdown @@ -4,7 +4,7 @@ go-serial This is a package that allows you to read from and write to serial ports in Go. -CPU and OS support +CPU Support ---------- This fork works only with MIPS cpu, most openwrt routers equipped with MIPS CPU. From c9ab32cd599adb78d4d44ae34c9fc8163f3b66d9 Mon Sep 17 00:00:00 2001 From: Philip Z Date: Mon, 5 Aug 2019 07:37:34 +0800 Subject: [PATCH 14/15] Update README.markdown --- README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index f471087..b8e047f 100644 --- a/README.markdown +++ b/README.markdown @@ -4,7 +4,7 @@ go-serial This is a package that allows you to read from and write to serial ports in Go. -CPU Support +CPU Support(MIPS only) ---------- This fork works only with MIPS cpu, most openwrt routers equipped with MIPS CPU. From a2595c455831b6f90ad03cdef19d9c3c09eb5114 Mon Sep 17 00:00:00 2001 From: Philip Z Date: Mon, 30 Aug 2021 01:22:15 +0800 Subject: [PATCH 15/15] Update open_linux.go --- serial/open_linux.go | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/serial/open_linux.go b/serial/open_linux.go index 58efc92..79c74b5 100644 --- a/serial/open_linux.go +++ b/serial/open_linux.go @@ -47,14 +47,7 @@ sparc64 and reference https://github.com/mojo-runtime/lib-linux/blob/6dbfa74d17beda9be9c6e3b595c76f8df3cbb077/c/struct-termios.h */ -func nccs() int { - var nccsValueMap = map[string]int{"mips": 23, "mips64": 23, "spark": 17, "spark64": 24, "other": 19} - var value = nccsValueMap[runtime.GOARCH] - if value == 0 { - return 19 - } - return value -} + const ( kTCSETS2 = unix.TCSETS2 //0x8030542B