serial

package
v0.0.0-...-683b059 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2022 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package serial allows communication with serial ports.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RemotePort

type RemotePort struct {
	// contains filtered or unexported fields
}

RemotePort allows communication with a serial port on a remote dut.

func (*RemotePort) Close

func (p *RemotePort) Close(ctx context.Context) error

Close the connection. The port should not be used afterwards.

func (*RemotePort) Flush

func (p *RemotePort) Flush(ctx context.Context) error

Flush un-read/written data on the port.

func (*RemotePort) Read

func (p *RemotePort) Read(ctx context.Context, b []byte) (n int, err error)

Read bytes into buffer and returns the number of bytes read. Bytes already written to the port shall be moved into buf, up to its size. In blocking mode (port opened without ReadTimeout), it blocks until at least one byte is read. In non-blocking mode, it may return an error with zero bytes read if ReadTimeout is exceeded, however this is not guaranteed on all platforms and so a context deadline exceeded error may be returned even though the deadline is greater than the ReadTimeout.

func (*RemotePort) Write

func (p *RemotePort) Write(ctx context.Context, b []byte) (n int, err error)

Write bytes in buffer and returns the number of bytes written successfully. It returns a non-nil error when n != len(b), nil otherwise.

type RemotePortOpener

type RemotePortOpener struct {
	// contains filtered or unexported fields
}

RemotePortOpener holds data needed to open a RemotePort.

func NewRemotePortOpener

func NewRemotePortOpener(client pb.SerialPortServiceClient, name string, baud int, readTimeout time.Duration) *RemotePortOpener

NewRemotePortOpener creates a RemotePortOpener.

Example:

rpcClient, err := rpc.Dial(ctx, s.DUT(), s.RPCHint())
defer rpcClient.Close(ctx)

if err != nil {
    s.Fatal("rpcDial: ", err)
}
defer rpcClient.Close(ctx)

serviceClient := pb.NewSerialPortServiceClient(rpcClient.Conn)

opener := NewRemotePortOpener(serviceClient, "/path/to/device", 115200, 2 * time.Second)
port := opener.OpenPort(ctx)

func (*RemotePortOpener) OpenPort

func (c *RemotePortOpener) OpenPort(ctx context.Context) (common.Port, error)

OpenPort opens and returns the port.

Jump to

Keyboard shortcuts

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