diff --git a/devices/geiger/gqgmc.go b/devices/geiger/gqgmc.go index 77c04d3112d3c71c61e854b8803faa137036a3f2..43dccdc6fec19c0fe67eb017cb390353c1110faf 100644 --- a/devices/geiger/gqgmc.go +++ b/devices/geiger/gqgmc.go @@ -8,6 +8,7 @@ package geiger import ( + "errors" "fmt" "time" @@ -356,17 +357,13 @@ func (gc *GQGMCCounter) sendCmd(cmd []byte) { } func (gc *GQGMCCounter) readCmdReturn(length uint32) ([]byte, error) { - // Now read the returned raw byte string. Do this by reading one byte - // at a time until the requested number of bytes are attained. However, - // the serial port has been setup to timeout each read attempt. So if - // after N calls to read, we haven't yet read all N bytes, declare - // a failure. The read is done this way to avoid an indefinite blocking - // situation when 0 bytes are returned by the GQ GMC. The only good thing - // about this methodology is that the largest possible read is only 4K - // for the history data. So the read never really takes that much time. - //for(uint32_t i=0; i<retbytes; i++) - // rcvd += read(mUSB_serial, inp, 1); - // inp = &retdata[rcvd]; - // if (rcvd >= retbytes) break; - return nil, nil + buf := make([]byte, length) + n, err := gc.port.Read(buf) + if err != nil { + return nil, err + } + if uint32(n) != length { + return nil, errors.New("Short read") + } + return buf, nil }