本文整理匯總了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!");
}