Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/9elements/go-ser2net
A golang replacement for ser2net
https://github.com/9elements/go-ser2net
Last synced: 6 days ago
JSON representation
A golang replacement for ser2net
- Host: GitHub
- URL: https://github.com/9elements/go-ser2net
- Owner: 9elements
- Created: 2020-08-03T06:11:28.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-09-11T13:53:15.000Z (2 months ago)
- Last Synced: 2024-11-04T17:47:25.157Z (9 days ago)
- Language: Go
- Size: 29.3 KB
- Stars: 14
- Watchers: 9
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
go-ser2net
========================A serial to telnet client and library as replacement for ser2net.
# How to use the library
To spawn a telnet server on port 5555 and redirect to ttyS0 running at 115200N8 use this code
example:```
import (
"github.com/9elements/go-ser2net/pkg/ser2net"
)w, _ := ser2net.NewSerialWorker("/dev/ttyS0")
// Run serial worker in new routine
go w.Worker()// Start telnet on port 5555 and serve forever
err := w.StartTelnet("", 5555)
if nil != err {
panic(err)
}// Start GoTTY on port 5556 and serve forever
err = w.StartGoTTY("", 5556, "")
if nil != err {
panic(err)
}
```To use an io.ReadWriter do:
```
import (
"github.com/9elements/go-ser2net/pkg/ser2net"
)w, _ := ser2net.NewSerialWorker("/dev/ttyS0")
// Run serial worker in new routine
go w.Worker()// Get a ReadWriteCloser interface
i, err := w.NewIoReadWriteCloser()
if nil != err {
panic(err)
}
defer i.Close()// Copy serial out to stdout
go func() {
p := make([]byte, 1)
for {
n, err := i.Read(p)
if err != nil {
break
}
fmt.Printf("%s", string(p[:n]))
}
}()// Copy stdin to serial
reader := bufio.NewReader(os.Stdin)
p := make([]byte, 1)
for {
_, err := reader.Read(p)
if err != nil {
break
}_, err = i.Write(p)
if err != nil {
break
}
}
```