/// <summary> Wait for reply from the device. </summary> /// <param name="structSize"> Size of the structure. </param> /// <param name="timeout"> The timeout. </param> /// <returns> returns received byte[] array. </returns> public byte[] WaitForReply(int structSize, int timeout) { // set reference time for timeout DateTime refTime = DateTime.Now + TimeSpan.FromMilliseconds(timeout); // loop, waiting for the response to be available while (_device.NumberOfBytesInRxBuffer() < structSize) { // check for timeout Thread.Sleep(100); if (DateTime.Now > refTime) { return(null); } } // read the bytes into a new byte array int bytesRead; byte[] byteArray = new byte[structSize]; _device.Read(ref byteArray, structSize, out bytesRead); return(byteArray); }