/// <summary> /// Frees resources owned by this instance. /// </summary> /// <param name="disposing"> /// True when called via <see cref="IDisposable.Dispose()"/>, false when called from the finalizer. /// </param> protected override void Dispose(bool disposing) { // Do nothing when already disposed if (IsDisposed) { return; } // Dispose try { // Dispose managed resource during dispose if (disposing) { if (HardwareUpper != null) { HardwareUpper.Dispose(); } } } finally { // Dispose base class base.Dispose(disposing); } }
/// <summary> /// Frees resources owned by this instance. /// </summary> /// <param name="disposing"> /// True when called via <see cref="IDisposable.Dispose()"/>, false when called from the finalizer. /// </param> protected override void Dispose(bool disposing) { try { // Only managed resources to dispose if (!disposing) { return; } // Close device HardwareUpper?.Dispose(); } finally { // Dispose base class base.Dispose(disposing); } }
public Mb85rc04vDevice(int busNumber, byte chipNumber, I2cBusSpeed speed = I2cBusSpeed.FastMode, I2cSharingMode sharingMode = I2cSharingMode.Exclusive) : base(chipNumber, MemorySize) { // Check device addresses var lowerAddress = GetDataI2cAddress(chipNumber, false); var upperAddress = GetDataI2cAddress(chipNumber, true); // Connect to devices try { Hardware = I2cExtensions.Connect(busNumber, lowerAddress, speed, sharingMode); HardwareUpper = I2cExtensions.Connect(busNumber, upperAddress, speed, sharingMode); } catch { // Free resources on initialization error Hardware?.Dispose(); HardwareUpper?.Dispose(); // Continue error throw; } }