Closed toudi closed 9 months ago
This is old but I also have a need for read with timeout and did kind of the same thing. Could we get this merged?
As for the implementation, technically you could just do
// Refactor existing Read function to take a timeout and rename it
func (dev *Device) ReadTimout(b []byte, timeout int) (int, error) {
... existing read implementation but just use C.hid_read_timeout
}
// Make Read function call ReadTimeout with timeout value of 0
func (dev *Device) Read(b []byte) (int, error) {
return dev.ReadTimout(b, 0)
}
but not a big deal
@gballet do you want me to extract everything to a separate function and always call hid_read_timeout as @bpedman suggested ? I think that's a nice way of not repeating the code, but it's your call
Forgot to mention I went ahead and implemented that variant a while ago, mainly so I could pull from a branch I controlled, but they are basically the same so I don't care which one is used, see #22
is there a chance that we could merge this or #22 ? I'm using a fork of mine in the program that I use but I think it could be beneficial to merge the changes upstream :)
Let's merge https://github.com/karalabe/hid/pull/22, it's a bit simpler. Thanks!
I had a piece of code using your hid library. Everything was working great, but I was struggling with timeouts. Initially, when I realized that your library did not bound to the underlying read_timeout, I did a similar thing to:
however, this led to several problems:
Of course, I could have also implemented this timeout thing wrong.
All this led me to believe that I was trying to kick open the door which was already opened for me - namely - hidapi already implements read_timeout call so if hid would bind to it I could use it.
this PR does just that - it binds to read_timeout call. Thanks to this, my code simply uses this function as a blocking one (no more of goroutines / select calls). I would be very happy if you could point out if this is a right or wrong way to go, basically I am still learning golang so there is a good chance I messed something up.
thanks in advance, and once again, thank you for the wonderful binding!