public bool IsGyroValid() { bool valid = false; short regValue = 0; try { int attempt = 0; for (attempt = 0; attempt < 200; attempt++) { //The ADIS values seem to fluctuate at times, so try a few times to get the right value. //If it still cannot be validated, something may be wrong regValue = (short)_gyroscopeDevice.RegisterRead((byte)Register.PROD_ID); valid = regValue.Equals(gyroProductID); if (valid) { break; } } if (valid) { _logger.LogInformation($"ADIS16460 Prod ID Register reads {regValue} after {attempt} attempts."); } else { _logger.LogInformation($"ADIS16460 Prod ID Register could not be validated."); } } catch (Exception ex) { _logger.LogError("Error validating Gyro"); _logger.LogError(ex.Message); _logger.LogError(ex.StackTrace); } return(valid); }