Skip to content

function read alway error on macOS #40

Description

@miniboom360

Hello, I tried exactly as the example (example the port name and add function read for recv data). I successfully write Byte array to port but failed to read from it. it alway return an error which called "read /dev/tty.usbserial1: interrupted system call". i've tried serveral time but Disappointing results. any suggestions? looking forward to your reply.

I running it on macOS sierra 10.12.6, here is the code:
`import (
"fmt"
"github.com/jacobsa/go-serial/serial"
"log"
"testing"
)

func TestSerialData(t *testing.T) {
// Set up options.
options := serial.OpenOptions{
PortName: "/dev/tty.usbserial1",
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}
w, err := port.Write(b)
if err != nil {
	log.Fatalf("port.Write: %v", err)
}

fmt.Println("Wrote", w, "bytes.")
buf := make([]byte, 128)
r, err := port.Read(buf)
if err != nil {
	fmt.Println(err)
	return
}
fmt.Println("Read", r, "bytes.")

}`

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions