Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

read function always interrupted system call #99

Open
miniboom360 opened this issue Mar 22, 2019 · 1 comment
Open

read function always interrupted system call #99

miniboom360 opened this issue Mar 22, 2019 · 1 comment

Comments

@miniboom360
Copy link

miniboom360 commented Mar 22, 2019

Hello, I running on macOS sierra 10.12.6. I tried exactly as the example (except the port name, port name is cu.usbserial1 in my macBook). I sucessfully write string to the port but failed to read from it. it always return error. the error is called "read /dev/cu.usbserial1: interrupted system call", i've tried several times to send, but Disappointing results. any suggestions?

here is the code:

`import (
"fmt"
"github.com/tarm/serial"
"testing"
)

func TestTarmSerialDataRecvAndSend(t *testing.T) {
c := &serial.Config{
Name: "/dev/cu.usbserial1",
Baud: 9600,
}

s, err := serial.OpenPort(c)
if err != nil {
	fmt.Println(err)
	return
}

for i := 0; i < 10; i++ {
	n, err := s.Write([]byte("test"))
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Printf("send byte : %v",n)
}

fmt.Println("send over")

buf := make([]byte, 128)
n, err := s.Read(buf)
if err != nil{
	fmt.Println(err)
	return
}

fmt.Printf("%q", buf[:n])

}
`

@polomsky
Copy link

I have the same problem on linux arm with Go 1.14. Handling of syscall error EINTR should be ignored.

for {
	n, err := s.Read(buf)
	switch err := err.(type) {
		case syscall.Errno:
			if err == syscall.EINTR {
				// interruption by signal - ignore it (e.g. caused by Go)
				continue
			}
		}
	}
	break;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants