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

Reading error on windows #77

Open
matteonistri opened this issue May 4, 2020 · 0 comments
Open

Reading error on windows #77

matteonistri opened this issue May 4, 2020 · 0 comments

Comments

@matteonistri
Copy link

Hello,
using this library on windows, I encountered an error on reading. I know for sure that there is something to read, but the Read method is blocking (even after the read timeout is elapsed) and it never returns. After a debug session, I found out that it's waiting for overlapped I/O to complete (here) that apparently never happens.
Here's my code:

mode := &serial.Mode{
		BaudRate: 115200,
		Parity:   serial.OddParity,
		DataBits: 8,
		StopBits: serial.TwoStopBits,
	}

port, err := serial.Open("COM1", mode)
n, err := port.Write([]byte("data\r"))
if err != nil {
	log.Fatal(err)
}
fmt.Printf("Sent %v bytes\n", n)

buff := make([]byte, 1024)
for {
	n, err = port.Read(buff)
	if err != nil {
		log.Fatal(err)
		break
	}
	if n == 0 {
		fmt.Println("\nEOF")
		break
	}
	fmt.Printf("%v", string(buff[:n]))
	fmt.Println(n)
}

Am I doing something wrong?

Also I found out that on handle creation (here), passing 0 instead of syscall.FILE_FLAG_OVERLAPPED, will make Read work.

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

1 participant