/// <summary> /// Reads and scales a SFF8636 register. /// Must be of type Dec or DecWord. /// /// Exception thrown for all other types. /// </summary> /// <param name="reg"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <double> GetValueAsync(Sff8636 reg, CancellationToken cancellationToken = default) { var result = await GetRegAsync(reg, cancellationToken).ConfigureAwait(false); if (reg.Register.Type.Equals(DataType.Dec) | reg.Register.Type.Equals(DataType.DecWord)) { return(result * reg.Register.Scale); } throw new ArgumentException($"Register {reg.Name} with data type : {reg.Type} does not support scaling."); }
//=========================== QSFP /// <summary> /// Reads an SFF8636 register. /// /// Retries and Timeout set by policy. /// </summary> /// <param name="reg"></param> /// <param name="cancellationToken"></param> /// <returns></returns> /// public async Task <dynamic> GetRegAsync(Sff8636 reg, CancellationToken cancellationToken = default) { var policyWrapResults = await _policyWrap.ExecuteAndCaptureAsync(async (context, ct) => { ct.ThrowIfCancellationRequested(); SetPage(reg.Register.Page); var readData = await I2C.I2C_RandomReadAsync(Sff8636.I2CAddress, reg.Register.Address, reg.Register.Size).ConfigureAwait(false); var res = ConvertData(reg, readData); return(res); }, new Dictionary <string, object>() { { $"{GetCaller()}", $"{reg.Name}({reg.Page}.{reg.Address})" } }, cancellationToken : cancellationToken); if (policyWrapResults.Outcome == OutcomeType.Failure) { throw policyWrapResults.FinalException; } return(policyWrapResults.Result); }
/// <summary> /// Writes and verifies setting of a SFF8636 register. /// /// Retries and Timeout set by policy. /// </summary> /// <param name="reg"></param> /// <param name="data"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <bool> SetRegAsync(Sff8636 reg, byte data, CancellationToken cancellationToken = default) { var policyWrapResults = await _policyWrap.ExecuteAndCaptureAsync(async (context, ct) => { ct.ThrowIfCancellationRequested(); SetPage(reg.Register.Page); I2C.I2C_RandomWrite(Sff8636.I2CAddress, reg.Register.Address, data); var readBack = await I2C.I2C_RandomReadAsync(Sff8636.I2CAddress, reg.Register.Address).ConfigureAwait(false); if (data != readBack) { throw new ValidationException($"Validation failed, {data} not equal {readBack}."); } }, new Dictionary <string, object>() { { $"{GetCaller()}", $"{reg.Name}({reg.Page}.{reg.Address}:{data})" } }, cancellationToken : cancellationToken); if (policyWrapResults.Outcome == OutcomeType.Failure) { throw policyWrapResults.FinalException; } return(policyWrapResults.Outcome == OutcomeType.Successful); }