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

Timeout problem with io.Reader #116

Open
sanchez84 opened this issue Oct 22, 2020 · 0 comments
Open

Timeout problem with io.Reader #116

sanchez84 opened this issue Oct 22, 2020 · 0 comments

Comments

@sanchez84
Copy link

sanchez84 commented Oct 22, 2020

if I use:

portCfg := &serial.Config{Name: "COM1", Baud: 115200, ReadTimeout: 1 * time.Second}
port, err := serial.OpenPort(portCfg)
portReader = bufio.NewReader(port)
n, err := io.ReadFull(portReader, buf)

timeout doesn't happen. Function serial.Read() returned 0 bytes and error==nil and io.ReadFull() continue to work.
Maybe serial.Read() must return io.EOF if timeout happen?
For this, function getOverlappedResult() maybe like this:

func getOverlappedResult(h syscall.Handle, overlapped *syscall.Overlapped) (int, error) {
	var n int
	_, _, err := syscall.Syscall6(nGetOverlappedResult, 4, // r, _, err := syscall.Syscall6(nGetOverlappedResult, 4,
		uintptr(h),
		uintptr(unsafe.Pointer(overlapped)),
		uintptr(unsafe.Pointer(&n)), 1, 0, 0)
	// if r == 0 {  // old if
	// 	return n, err
	// }
	if err == 1460 { // new if, 1460 - ERROR_TIMEOUT
		return n, io.EOF
	}
	if err != 0 {
		return n, err
	}
	return n, nil
}

Please, fix timeout, thanks

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