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


C# I2cDevice.Read方法代码示例

本文整理汇总了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);
        }
开发者ID:rishabhbanga,项目名称:CK.HomeAutomation,代码行数:9,代码来源:ReadDHT22SensorCommand.cs

示例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!");
		}
开发者ID:Scorillo47,项目名称:hab,代码行数:30,代码来源:HTU21I2CSensor.cs


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