gocomm

package module
v0.0.0-...-89aa4fc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

README

Example

package main

import (
	"fmt"

	gocomm "github.com/mv-kan/go-comm"
)

func main() {
	fmt.Println("I am writer")
	p, err := gocomm.NewPort("/dev/", 115200, 0)
	if err != nil {
		panic(err)
	}
	input := make(chan string)
	conn, msgChan, err := gocomm.NewConnection(p, input, 0, "\n", "\n")
	if err != nil {
		panic(err)
	}
	defer conn.Close()
	msg := <-msgChan
	fmt.Println("msg.Data=", msg.Data)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDevice       = errors.New("device error")
	ErrNotConnected = errors.New("not connected")
)

Functions

This section is empty.

Types

type Connection

type Connection interface {
	Close() error
}

func NewConnection

func NewConnection(
	p Port,
	input <-chan string,
	writeInterval time.Duration,
	delimRead string,
	delimWrite string,
) (Connection, <-chan Message, error)

type Message

type Message struct {
	Data string
	Err  error
}

type Port

type Port interface {
	Close() error
	Flush() error
	Read(b []byte) (n int, err error)
	Write(b []byte) (n int, err error)
	Reopen() error
}

func NewPort

func NewPort(devPath string, baud int, readTimeout time.Duration) (Port, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL