ConnectI2c() public static méthode

Connects to an I2C device if it exists.
public static ConnectI2c ( int controllerIndex, int address, I2cBusSpeed speed = I2cBusSpeed.FastMode, I2cSharingMode sharingMode = I2cSharingMode.Exclusive ) : Windows.Devices.I2c.I2cDevice
controllerIndex int Controller index.
address int Slave address.
speed I2cBusSpeed Bus speed.
sharingMode I2cSharingMode Sharing mode.
Résultat Windows.Devices.I2c.I2cDevice
        /// <summary>
        /// Creates an initialized instance.
        /// </summary>
        /// <param name="frequency">
        /// <see cref="NxpPca9685Device.Frequency"/> for important information.
        /// Use <see cref="ServoFrequencyDefault"/> to support most analog servos.
        /// </param>
        /// <param name="clear">Clears all LED/PWM values.</param>
        /// <param name="restart">
        /// Set true to restart the device which also enables the osciallator.
        /// When false, you have to call <see cref="NxpPca9685Device.Wake"/> or <see cref="Restart"/> later to enable the oscillator.
        /// </param>
        /// <param name="enable">
        /// Set true to enable output, or false to continue with further initialization before enabling output.
        /// When false, you have to set it later before any output can occur.
        /// Defaults to false to prevent unexpected behaviour from damaging hardware.
        /// </param>
        public static NavioLedPwmDevice Initialize(float frequency,
                                                   bool clear = true, bool restart = true, bool enable = false)
        {
            // Connect to I2C device
            var device = NavioHardwareProvider.ConnectI2c(I2cControllerIndex, I2cAddress, true, true);

            if (device == null)
            {
                // Initialization error
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
                                                                  Resources.Strings.I2cErrorDeviceNotFound, I2cAddress, I2cControllerIndex));
            }

            // Perform device initialization sequence...
            var navioDevice = new NavioLedPwmDevice(device);

            navioDevice.OutputEnabled = false;              // Disable output
            navioDevice.WriteFrequency(frequency);          // Set frequency
            if (clear)
            {
                navioDevice.Clear();                        // Clear LED/PWM values when specified
            }
            if (restart)
            {
                navioDevice.Restart();                      // Restart when specified
            }
            if (enable)
            {
                navioDevice.OutputEnabled = true;           // Enable output when specified
            }
            // Return initialized device
            return(navioDevice);
        }
Exemple #2
0
        /// <summary>
        /// Creates an instance of the correct type depending on the Navio model.
        /// </summary>
        public NavioFramDevice(NavioHardwareModel model)
        {
            // Connect to I2C device
            var device = NavioHardwareProvider.ConnectI2c(I2cControllerIndex, I2cAddress, true, true);

            if (device == null)
            {
                // Initialization error
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
                                                                  Resources.Strings.I2cErrorDeviceNotFound, I2cAddress, I2cControllerIndex));
            }

            // Create model specific device
            switch (model)
            {
            case NavioHardwareModel.Navio:

                // Connect to upper I2C device
                var upperAddress = Mb85rc04vDevice.GetUpperI2cAddress(I2cAddress);
                var upperDevice  = NavioHardwareProvider.ConnectI2c(I2cControllerIndex, upperAddress, true, true);
                if (device == null)
                {
                    // Initialization error
                    throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
                                                                      Resources.Strings.I2cErrorDeviceNotFound, upperAddress, I2cControllerIndex));
                }

                // Create 512 byte device for Navio
                Hardware = new Mb85rc04vDevice(device, upperDevice);
                break;

            case NavioHardwareModel.NavioPlus:

                // Create 32KiB device for Navio+
                Hardware = new Mb85rc256vDevice(device);
                break;

            default:
                throw new NotImplementedException();
            }
        }
Exemple #3
0
 public NavioBarometerDevice()
     : base(NavioHardwareProvider.ConnectI2c(I2cControllerIndex, I2cAddress, true, true), DefaultOsr)
 {
 }