当前位置: 首页>>代码示例>>C#>>正文


C# I2cDevice.WritePartial方法代码示例

本文整理汇总了C#中Windows.Devices.I2c.I2cDevice.WritePartial方法的典型用法代码示例。如果您正苦于以下问题:C# I2cDevice.WritePartial方法的具体用法?C# I2cDevice.WritePartial怎么用?C# I2cDevice.WritePartial使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Windows.Devices.I2c.I2cDevice的用法示例。


在下文中一共展示了I2cDevice.WritePartial方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OpenConnection

        public async Task<bool> OpenConnection(string i2cMasterId)
        {

            //Establish I2C connection
            __connection = await I2cDevice.FromIdAsync(i2cMasterId, new I2cConnectionSettings(this.__i2cAddress));
            
            // soft reset
            I2cTransferResult result = __connection.WritePartial(new byte[] { Registers.MPR121_SOFTRESET, 0x63 });

            if (result.Status == I2cTransferStatus.SlaveAddressNotAcknowledged)
            {
                throw new Exception(string.Format("MPR121 at address {0} not responding.", this.__i2cAddress));
            }

            await Task.Delay(1);

            writeRegister(Registers.MPR121_ECR, 0x0);

            byte c = readRegister8(Registers.MPR121_CONFIG2);

            if (c != 0x24) return false;


            SetThresholds(12, 6);

            //Section A Registers - Ref: AN3944, MPR121 Quick Start Guide
            //This group of setting controls the filtering of the system when the data is greater than the baseline. 
            //Settings from Adafruit Libary.. Most probably callibrated for the Adafruit's MPR121 breakout board.
            writeRegister(Registers.MPR121_MHDR, 0x01);
            writeRegister(Registers.MPR121_NHDR, 0x01);
            writeRegister(Registers.MPR121_NCLR, 0x0E);
            writeRegister(Registers.MPR121_FDLR, 0x00);

            //Section B Registers - Ref: AN3944, MPR121 Quick Start Guide
            writeRegister(Registers.MPR121_MHDF, 0x01);
            writeRegister(Registers.MPR121_NHDF, 0x05);
            writeRegister(Registers.MPR121_NCLF, 0x01);
            writeRegister(Registers.MPR121_FDLF, 0x00);

            writeRegister(Registers.MPR121_NHDT, 0x00);
            writeRegister(Registers.MPR121_NCLT, 0x00);
            writeRegister(Registers.MPR121_FDLT, 0x00);

            writeRegister(Registers.MPR121_DEBOUNCE, 0);
            writeRegister(Registers.MPR121_CONFIG1, 0x10); // default, 16uA charge current
            writeRegister(Registers.MPR121_CONFIG2, 0x20); // 0.5uS encoding, 1ms period

            writeRegister(Registers.MPR121_ECR, 0x8F);  // start with first 5 bits of baseline tracking

            InitMPR121TouchInterrupt();

            return true;
        }
开发者ID:mohankrr,项目名称:Windows.IoT.Core.HWInterfaces,代码行数:53,代码来源:MPR121.cs

示例2: I2CInit

        public async Task I2CInit(byte slaveAddress, I2cBusSpeed busSpeed, I2cSharingMode sharingMode)
        {
            // get aqs filter  to find i2c device
            string aqs = I2cDevice.GetDeviceSelector("I2C1");

            // Find the I2C bus controller with our selector string
            var dis = await DeviceInformation.FindAllAsync(aqs);
            if (dis.Count == 0)
                throw new Exception("There is no I2C device"); // bus not found

            I2cConnectionSettings settings = new I2cConnectionSettings(slaveAddress);
            // Create an I2cDevice with our selected bus controller and I2C settings
            _i2CDevice = await I2cDevice.FromIdAsync(dis[0].Id, settings);
            if (_i2CDevice == null) return;
            var status = _i2CDevice.WritePartial(new byte[] { 0x00 });
            if (status.Status == I2cTransferStatus.FullTransfer) _isConnected = true;
            else if (status.Status == I2cTransferStatus.PartialTransfer)
                throw new Exception("There was an error during sending test data.");
            else if (status.Status == I2cTransferStatus.SlaveAddressNotAcknowledged)
              throw new Exception("I2C Device is not connected.");
        
        }
开发者ID:pozzzima123,项目名称:TcpListenerRTM,代码行数:22,代码来源:I2C.cs


注:本文中的Windows.Devices.I2c.I2cDevice.WritePartial方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。