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 serial ERROR_OPERATION_ABORTED (995) #131

Open
hww opened this issue Oct 23, 2023 · 1 comment
Open

Reading serial ERROR_OPERATION_ABORTED (995) #131

hww opened this issue Oct 23, 2023 · 1 comment

Comments

@hww
Copy link

hww commented Oct 23, 2023

Reading bytes from the serial unexpected terminated with the error

error(syscall.Errno) golang.org/x/sys/windows.ERROR_OPERATION_ABORTED (995)

Sample code

The sample code below

serialMode := &serial.Config{Name: "COM4", Baud: baudRate, Size: 8, Parity: serial.ParityNone, StopBits: 1}
port, err := serial.OpenPort(serialMode)
for { 
	reader := bufio.NewReader(port)
	reply, err := reader.ReadBytes('\x0a')
	if err != nil {
		panic(err)
	}
	fmt.Println(reply)
}

Other info

Platform: Windows 10
Golang: go version go1.21.3 windows/amd64
Serial interface: USB to Serial

@hww
Copy link
Author

hww commented Oct 23, 2023

Another interesting behavior happens when the Reader replaced by Scanner (example before)
Lets assume to call the next code in the infinitive loop, and the serial port gets infinitive stream of bytes. Then the line 8 will never be executed because the scanner returns empty lines. But if break the app in the line 1 or 2 and then continue execution, then the line 8 will print a valid data as minimum once.

Looks like "calling the reader with hi rate does not allow to get a valid data", the problem of concurrency or latency of the driver... Very strange, but it refers me to then next post https://stackoverflow.com/questions/21305392/io-operation-aborted-error-thrown-while-reading-serial-port

1	scanner := bufio.NewScanner(port)
2	scanner.Scan()
3	text := scanner.Text()
4
5	fmt.Println(text)
6	n := len(text)
7	if n > 0 {
8		fmt.Println(n)
9	}

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