예제 #1
0
 /// <summary>
 /// Creates default I2cBus
 /// </summary>
 /// <param name="busId">The bus ID.</param>
 /// <returns>I2cBus instance.</returns>
 public static I2cBus Create(int busId)
 {
     if (Environment.OSVersion.Platform == PlatformID.Win32NT)
     {
         return CreateWindows10I2cBus(busId);
     }
     else
     {
         return UnixI2cBus.Create(busId);
     }
 }
예제 #2
0
 /// <summary>
 /// Creates a communications channel to a device on an I2C bus running on the current platform
 /// </summary>
 /// <param name="settings">The connection settings of a device on an I2C bus.</param>
 /// <returns>A communications channel to a device on an I2C bus running on Windows 10 IoT.</returns>
 public static I2cDevice Create(I2cConnectionSettings settings)
 {
     if (Environment.OSVersion.Platform == PlatformID.Win32NT)
     {
         return(CreateWindows10I2cDevice(settings));
     }
     else
     {
         return(new UnixI2cDevice(UnixI2cBus.Create(settings.BusId), settings.DeviceAddress, shouldDisposeBus: true));
     }
 }
예제 #3
0
    protected override void Dispose(bool disposing)
    {
        if (_bus != null)
        {
            if (_shouldDisposeBus)
            {
                _bus.Dispose();
            }
            else
            {
                _bus.RemoveDeviceNoCheck(_deviceAddress);
            }

            _bus = null !;
        }

        base.Dispose(disposing);
    }
예제 #4
0
 public UnixI2cDevice(UnixI2cBus bus, int deviceAddress, bool shouldDisposeBus = false)
 {
     _bus              = bus;
     _deviceAddress    = deviceAddress;
     _shouldDisposeBus = shouldDisposeBus;
 }