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

windows10 s.Read(buffer) is empty #101

Open
hinet opened this issue May 23, 2019 · 2 comments
Open

windows10 s.Read(buffer) is empty #101

hinet opened this issue May 23, 2019 · 2 comments

Comments

@hinet
Copy link

hinet commented May 23, 2019

config := &serial.Config{Name: "COM3", Baud: 2400, Parity: 'E', StopBits: 1, ReadTimeout: time.Second * 5}
port, err := serial.OpenPort(config)
checkErr(err)
defer port.Close()
n, err := port.Write([]byte("FEFEFEFE68310010111819681104333334333516"))
checkErr(err)


//read
buffer := make([]byte, 1024)
n, err = port.Read(buffer)
checkErr(err)
log.Printf("read:%q", buffer[:n])
@hinet
Copy link
Author

hinet commented May 24, 2019

//I added sleep. It's OK.
time.Sleep(1 * time.Second)
buffer := make([]byte, 1024)
n, err = port.Read(buffer)
checkErr(err)
log.Printf("read:%q", buffer[:n])

I added sleep. It's OK.Is there any other way?

@xiegeo
Copy link

xiegeo commented May 24, 2019

Read in a loop until you got everything. If read repeatedly returns early, add a sleep calculated from expected data length and baud rate.

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