本文整理汇总了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;
}
示例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.");
}