SerialPort.read

Read data from port

Receive data time schema:

---|-------|--------------|-------|--> t
 call      |              |       |
 read      |              |       |
   |       |              |       |
   |       |<data receive process>|
   |       |=====   ====  | ======|
   |       |              |
   |       |<-readedData->|
   |                      | 
   |<---readTimeoutSum--->|
   |                    return
   |<---read work time--->|

where readTimeoutSum = readTimeout + readTimeoutMult * dataBuffer.length;

if canReturn is:

CanRead.allOrNothing

if (readedData.length < dataBuffer.length)
    throw TimeoutException(port);
else return readedData;

CanReturn.anyNonZero

if (readedData.length == 0)
    throw TimeoutException(port);
else return readedData;

CanReturn.zero

return readedData;

Params: buf = preallocated buffer for reading cr = flag what define behavior if readedData.length < buf.length then readTimeoutSum is expires

Returns: slice of buf with readed data Throws: PortClosedException if port closed ReadException if read error occurs TimeoutException if timeout expires

Meta