tyd / libserial

Serial library for Go (no cgo)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

libserial

Build Status GoDoc GoReportCard codecov

Serial library for golang (no cgo)

Prerequisite

  • Go 1.9+ (for type alias)
  • Git (required by Go)

Supported Platform

  • darwin (tested on amd64, thanks to travis)
    • arm64 amd64 arm 386
  • linux (tested on amd64, thanks to travis)
    • all go supported arch
  • windows (not tested, see issue #1)
    • all go supported arch
  • freebsd (not tested)
    • all go supported arch
  • netbsd (not tested)
    • all go supported arch
  • openbsd (not tested)
    • all go supported arch

Usage

TL;DR: you can find a demo cli app in cmd/libserial/main.go

0.Get this package with go get or git clone

go get -u github.com/goiiot/libserial
# git clone https://github.com/goiiot/libserial

1.Import this package

import (
    // ...
    "github.com/goiiot/libserial"
)

2.Open serial connection and check error

// open serial port with default settings (9600 8N1)
conn, err := libserial.Open("/dev/serial0")

if err != nil {
    panic("hmm, how cloud it fail")
}

Note: You can add options when opening serial port, see godoc - Option

3.Read/Write data from serial connection

buf := make([]byte, 64)

_, err := conn.Read(buf[:])
if err != nil { }

_, err := conn.Write([]byte("{data}"))
if err != nil { }

Command line demo

You can download and install libserial to your $GOPATH/bin for quick demo test (GOPATH required)

go get -u github.com/goiiot/libserial/cmd/libserial

References

LICENSE

GitHub license

Copyright Go-IIoT (https://github.com/goiiot)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

Serial library for Go (no cgo)

License:Apache License 2.0


Languages

Language:Go 81.3%Language:Makefile 16.2%Language:Shell 2.5%