本文整理汇总了C#中Windows.Devices.I2c.I2cDevice.Read方法的典型用法代码示例。如果您正苦于以下问题:C# I2cDevice.Read方法的具体用法?C# I2cDevice.Read怎么用?C# I2cDevice.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.Devices.I2c.I2cDevice
的用法示例。
在下文中一共展示了I2cDevice.Read方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public override void Execute(I2cDevice i2CDevice)
{
i2CDevice.Write(GenerateRegisterSensorPackage());
byte[] buffer = new byte[9];
i2CDevice.Read(buffer);
ParseResponse(buffer);
}
示例2: Measure
/// <summary>
/// Measures data from the HTU21D.
/// </summary>
/// <param name="device">The I2C device</param>
/// <param name="command">MEASURE_TEMP or MEASURE_HUMIDITY</param>
/// <param param name="gsl">The global sensor lock</param>
/// <returns>The measured value in quids FS</returns>
private async Task<int> Measure(I2cDevice device, int command, object gsl) {
byte[] data = new byte[3];
// No Hold Master mode
lock (gsl) {
device.Write(new byte[] { (byte)command });
}
await Task.Delay(30);
// Max measurement time is 50 ms for temperature and 16 ms for humidity
for (int i = 0; i < 3; i++) {
await Task.Delay(15);
try {
lock (gsl) {
device.Read(data);
}
// Data is MSB-first in the first 2 bytes
int value = data[1] & 0xFC;
return value | ((data[0] & 0xFF) << 8);
} catch (IOException) {
// Swallow the NACK and try again in 10 ms
}
}
throw new IOException("Still measuring, increase delay!");
}