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


C# I2cDevice.WriteRead方法代码示例

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


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

示例1: GPSFetch

		/// <summary>
		/// Displays the GPS data on the screen.
		/// </summary>
		/// <param name="device">The I2C device</param>
		/// <param name="index">0 for Venus, 1 for Copernicus</param>
		/// <param name="display">An array containing 4 text boxes - lat, lon, alt, vel</param>
		private void GPSFetch(I2cDevice device, int index, params TextBlock[] display) {
			byte[] data = new byte[17];
			// Receive 17 bytes starting from lat register (0x10), where 0x30 is the second GPS
			byte address = (byte)(((index == 0) ? 0x00 : 0x20) + 0x10);
			device.WriteRead(new byte[] { address }, data);
			// Convert all to correct types
			double lat = BitConverter.ToInt32(data, 0) * 1E-6;
			double lon = BitConverter.ToInt32(data, 4) * 1E-6;
			double vel = BitConverter.ToInt16(data, 8) * 1E-1;
			double head = BitConverter.ToInt16(data, 10) * 1E-1;
			double alt = BitConverter.ToInt32(data, 12) * 1E-2;
			int satellites = (int)data[16];
			// Write to the screen
			if (satellites > 0) {
				display[0].Text = lat.ToString("F6");
				display[1].Text = lon.ToString("F6");
				display[2].Text = alt.ToString("F1");
				display[3].Text = vel.ToString("F1");
			} else {
				display[0].Text = "NO FIX";
				display[1].Text = satellites.ToString();
				display[2].Text = "";
				display[3].Text = "";
			}
		}
开发者ID:Scorillo47,项目名称:hab,代码行数:31,代码来源:MainPage.xaml.cs

示例2: Read16Bits

		public static UInt16 Read16Bits(I2cDevice device, byte reg, ByteOrder byteOrder, string exceptionMessage)
		{
			try
			{
				byte[] addr = { reg };

				byte[] data = new byte[2];

				device.WriteRead(addr, data);

				switch (byteOrder)
				{
					case ByteOrder.BigEndian:
						return (UInt16)((data[0] << 8) | data[1]);

					case ByteOrder.LittleEndian:
						return (UInt16)((data[1] << 8) | data[0]);

					default:
						throw new SensorException($"Unsupported byte order {byteOrder}");
				}
			}
			catch (Exception exception)
			{
				throw new SensorException(exceptionMessage, exception);
			}
		}
开发者ID:harshatech2012,项目名称:RPi.SenseHat,代码行数:27,代码来源:I2CSupport.cs

示例3: Read

 public static bool Read(I2cDevice device, byte reg, byte[] data)
 {
     byte[] addr = new byte[1];
     addr[0] = reg;
     try {
         device.WriteRead(addr, data);
         return true;
     } catch {
         return false;
     }
 }
开发者ID:emmellsoft,项目名称:RTIMULibCS,代码行数:11,代码来源:RTI2C.cs

示例4: Init

		public override string Init(I2cDevice device) {
			byte[] data = new byte[3];
			// Stream read 0x00 (WHO_AM_I), 0x01 (SW_VERSION_MAJOR),
			// 0x02 (SW_VERSION_MINOR)
			device.WriteRead(new byte[] { 0x00 }, data);
			// Check for sync
			if ((data[0] & 0xFF) != SLAVE_ADDRESS)
				throw new IOException("Telemetry MCU is not in sync or disconnected");
			// Check firmware version
			if ((data[1] & 0xFF) != SW_VERSION)
				throw new IOException("Telemetry MCU is using incompatible firmware");
			// Column guide
			return "FIX_1,LAT_1,LON_1,ALT_1,VEL_1,HDG_1,FIX_2,LAT_2,LON_2,ALT_2,VEL_2,HDG_2";
		}
开发者ID:Scorillo47,项目名称:hab,代码行数:14,代码来源:TelemetryI2CSensor.cs

示例5: GPSFetch

		/// <summary>
		/// Displays the GPS data on the screen.
		/// </summary>
		/// <param name="device">The I2C device</param>
		/// <param name="index">0 for Venus, 1 for Copernicus</param>
		/// <returns>The GPS data in a structure</returns>
		private GPSData GPSFetch(I2cDevice device, int index) {
			byte[] data = new byte[17];
			// Receive 17 bytes starting from 0x10, where 0x30 is the second GPS
			byte address = (byte)(((index == 0) ? 0x00 : 0x20) + 0x10);
			device.WriteRead(new byte[] { address }, data);
			GPSData result = new GPSData();
			// Convert all to correct types
			result.latitude = BitConverter.ToInt32(data, 0) * 1E-6;
			result.longitude = BitConverter.ToInt32(data, 4) * 1E-6;
			result.velocity = BitConverter.ToInt16(data, 8) * 1E-1;
			result.heading = BitConverter.ToInt16(data, 10) * 1E-1;
			result.altitude = BitConverter.ToInt32(data, 12) * 1E-2;
			result.satellites = data[16];
			return result;
		}
开发者ID:Scorillo47,项目名称:hab,代码行数:21,代码来源:TelemetryI2CSensor.cs

示例6: Read8Bits

		public static byte Read8Bits(I2cDevice device, byte reg, string exceptionMessage)
		{
			try
			{
				byte[] addr = { reg };

				byte[] data = new byte[1];

				device.WriteRead(addr, data);
				return data[0];
			}
			catch (Exception exception)
			{
				throw new SensorException(exceptionMessage, exception);
			}
		}
开发者ID:harshatech2012,项目名称:RPi.SenseHat,代码行数:16,代码来源:I2CSupport.cs

示例7: InitializeSystem

        private async void InitializeSystem(byte[] pinDirection, int inputCheckInterval)
        {
            byte[] readBuffer;
            byte bitMask0;
            byte bitMask1;

            // initialize I2C communications
            string deviceSelector = I2cDevice.GetDeviceSelector();
            var i2cDeviceControllers = await DeviceInformation.FindAllAsync(deviceSelector);
            if (i2cDeviceControllers.Count == 0)
            {
                throw new NullReferenceException("No I2C controllers were found on this system. Maybe it isn't a Raspberry Pi?");
            }

            var i2cSettings = new I2cConnectionSettings(_portExpanderAddress);
            i2cSettings.BusSpeed = I2cBusSpeed.FastMode;
            i2cPortExpander = await I2cDevice.FromIdAsync(i2cDeviceControllers[0].Id, i2cSettings);
            if (i2cPortExpander == null)
            {
                throw new Exception(string.Format(
                    "Slave address {0} is currently in use on {1}. " +
                    "Please ensure that no other applications are using I2C.",
                    i2cSettings.SlaveAddress,
                    i2cDeviceControllers[0].Id));
            }

            // initialize I2C Port Expander registers
            try
            {
                // initialize local copies of the IODIR, GPIO, and OLAT registers
                readBuffer = new byte[1];

                // read in each register value on register at a time. I'm doing this one at a time
                // to keep it straight in my head.
                i2cPortExpander.WriteRead(new byte[] { PORT_EXPANDER_IODIR0_REGISTER_ADDRESS }, readBuffer);
                iodir0Register = readBuffer[0];
                i2cPortExpander.WriteRead(new byte[] { PORT_EXPANDER_IODIR1_REGISTER_ADDRESS }, readBuffer);
                iodir1Register = readBuffer[0];

                i2cPortExpander.WriteRead(new byte[] { PORT_EXPANDER_GPIO0_REGISTER_ADDRESS }, readBuffer);
                gpio0Register = readBuffer[0];
                i2cPortExpander.WriteRead(new byte[] { PORT_EXPANDER_GPIO1_REGISTER_ADDRESS }, readBuffer);
                gpio1Register = readBuffer[0];

                i2cPortExpander.WriteRead(new byte[] { PORT_EXPANDER_OLAT0_REGISTER_ADDRESS }, readBuffer);
                olat0Register = readBuffer[0];
                i2cPortExpander.WriteRead(new byte[] { PORT_EXPANDER_OLAT1_REGISTER_ADDRESS }, readBuffer);
                olat1Register = readBuffer[0];

                // configure the output pins to be logic high, leave the other pins as they are.
                olat0Register |= pinDirection[0];
                _i2CWriteBuffer = new byte[] { PORT_EXPANDER_OLAT0_REGISTER_ADDRESS, olat0Register };
                i2cPortExpander.Write(_i2CWriteBuffer);
                olat1Register |= pinDirection[1];
                _i2CWriteBuffer = new byte[] { PORT_EXPANDER_OLAT1_REGISTER_ADDRESS, olat1Register };
                i2cPortExpander.Write(_i2CWriteBuffer);

                // configure the specified pins to be an output and leave the other pins as they are.
                // input is logic low, output is logic high
                bitMask0 = (byte)(0xFF ^ pinDirection[0]); // set the GPIO pin mask bit to '0' for bits that are set, all other bits to '1'
                iodir0Register &= bitMask0;
                _i2CWriteBuffer = new byte[] { PORT_EXPANDER_IODIR0_REGISTER_ADDRESS, iodir0Register };
                i2cPortExpander.Write(_i2CWriteBuffer);
                bitMask1 = (byte)(0xFF ^ pinDirection[1]); // set the GPIO pin mask bit to '0' for bits that are set, all other bits to '1'
                iodir1Register &= bitMask1;
                _i2CWriteBuffer = new byte[] { PORT_EXPANDER_IODIR1_REGISTER_ADDRESS, iodir1Register };
                i2cPortExpander.Write(_i2CWriteBuffer);

            }
            catch (Exception e)
            {
                throw new Exception("Failed to initialize I2C port expander: " + e.Message);
            }

            // setup our input checking timer

            inputStatusCheckTimer = new DispatcherTimer();
            inputStatusCheckTimer.Interval = TimeSpan.FromMilliseconds(inputCheckInterval);
            inputStatusCheckTimer.Tick += InputStatusCheckTimer_Tick;
            inputStatusCheckTimer.Start();
        }
开发者ID:AerialBreakSoftware,项目名称:Win10RaspberrySprinkle,代码行数:81,代码来源:I2CExpander.cs

示例8: BeginAsync


//.........这里部分代码省略.........
                 */
                string advanced_query_syntax = I2cDevice.GetDeviceSelector("I2C1");
                DeviceInformationCollection device_information_collection = await DeviceInformation.FindAllAsync(advanced_query_syntax);
                string deviceId = device_information_collection[0].Id;

                /*
                 * Establish an I2C connection to the HTDU21D
                 *
                 * Instantiate the I2cConnectionSettings using the device address of the HTDU21D
                 * - Set the I2C bus speed of connection to fast mode
                 * - Set the I2C sharing mode of the connection to shared
                 *
                 * Instantiate the the HTDU21D I2C device using the device id and the I2cConnectionSettings
                 */
                I2cConnectionSettings htdu21d_connection = new I2cConnectionSettings(HTDU21D_I2C_ADDRESS);
                htdu21d_connection.BusSpeed = I2cBusSpeed.FastMode;
                htdu21d_connection.SharingMode = I2cSharingMode.Shared;

                htdu21d = await I2cDevice.FromIdAsync(deviceId, htdu21d_connection);

                /*
                 * Establish an I2C connection to the MPL3115A2
                 *
                 * Instantiate the I2cConnectionSettings using the device address of the MPL3115A2
                 * - Set the I2C bus speed of connection to fast mode
                 * - Set the I2C sharing mode of the connection to shared
                 *
                 * Instantiate the the MPL3115A2 I2C device using the device id and the I2cConnectionSettings
                 */
                I2cConnectionSettings mpl3115a2_connection = new I2cConnectionSettings(MPL3115A2_I2C_ADDRESS);
                mpl3115a2_connection.BusSpeed = I2cBusSpeed.FastMode;
                mpl3115a2_connection.SharingMode = I2cSharingMode.Shared;

                mpl3115a2 = await I2cDevice.FromIdAsync(deviceId, mpl3115a2_connection);

                /*
                 * Test to see if the I2C devices are available.
                 *
                 * If the I2C devices are not available, this is
                 * a good indicator the weather shield is either
                 * missing or configured incorrectly. Therefore we
                 * will disable the weather shield functionality to
                 * handle the failure case gracefully. This allows
                 * the invoking application to remain deployable
                 * across the Universal Windows Platform.
                 *
                 * NOTE: For a more detailed description of the I2C
                 * transactions used for testing below, please
                 * refer to the "Raw___" functions provided below.
                 */
                if (null == mpl3115a2)
                {
                    available = false;
                    enable = false;
                    return;
                }
                else
                {
                    byte[] reg_data = new byte[1];

                    try
                    {
                        mpl3115a2.WriteRead(new byte[] { CTRL_REG1 }, reg_data);
                        reg_data[0] &= 0xFE;  // ensure SBYB (bit 0) is set to STANDBY
                        reg_data[0] |= 0x02;  // ensure OST (bit 1) is set to initiate measurement
                        mpl3115a2.Write(new byte[] { CTRL_REG1, reg_data[0] });
                    }
                    catch
                    {
                        available = false;
                        enable = false;
                        return;
                    }
                }

                if (null == htdu21d)
                {
                    available = false;
                    enable = false;
                    return;
                }
                else
                {
                    byte[] i2c_temperature_data = new byte[3];

                    try
                    {
                        htdu21d.WriteRead(new byte[] { SAMPLE_TEMPERATURE_HOLD }, i2c_temperature_data);
                    }
                    catch
                    {
                        available = false;
                        enable = false;
                        return;
                    }
                }

                available = true;
                enable = true;
            }
开发者ID:JimGaleForce,项目名称:iot-build-lab,代码行数:101,代码来源:WeatherShield.cs

示例9: Initialize

        /// <summary>
        /// Initializer for the controller.
        /// </summary>
        public void Initialize()
        {
            //Initialize servo-parameters:
            //--------------------------------------
            Servos = new IServo[NUM_SERVOS];
            for (var i = 0; i < NUM_SERVOS; i++)
                Servos[i] = new SG5010
                {
                    Id = Convert.ToByte(i),
                    VelocityValue = 0
                };
            //--------------------------------------

            //Initialize servo-controller:
            //--------------------------------------
            var settings = new I2cConnectionSettings(SLAVE_ADDRESS) { BusSpeed = I2cBusSpeed.FastMode };
            var aqs = I2cDevice.GetDeviceSelector();
            var dis = DeviceInformation.FindAllAsync(aqs);

            //Get DeviceInformation:
            while(dis.Status != AsyncStatus.Completed) { }
            var d = dis.GetResults()[0];

            //Get I2cDevice:
            var s = I2cDevice.FromIdAsync(d.Id, settings);
            while(s.Status != AsyncStatus.Completed) { }
            m_pServoI2c = s.GetResults();
            //--------------------------------------

            //Read controller-values:
            //--------------------------------------
            var readBuf = new byte[1];
            var regAddrBuf = new[] { MODE1_ADRESS };
            m_pServoI2c.WriteRead(regAddrBuf, readBuf);
            m_bAutoIncrement = (readBuf[0] & Convert.ToByte(0x20)) == Convert.ToByte(0x20);
            m_bSleepMode = (readBuf[0] & Convert.ToByte(0x10)) == Convert.ToByte(0x10);
            m_bSub1 = (readBuf[0] & Convert.ToByte(0x08)) == Convert.ToByte(0x08);
            m_bSub2 = (readBuf[0] & Convert.ToByte(0x04)) == Convert.ToByte(0x04);
            m_bSub3 = (readBuf[0] & Convert.ToByte(0x02)) == Convert.ToByte(0x02);
            //--------------------------------------

            SetAllPwm(0, 0);
            Reset();
        }
开发者ID:Hannsen94,项目名称:RaspberryCopter,代码行数:47,代码来源:PCA9685.cs

示例10: Timer_Tick

        private async void Timer_Tick(ThreadPoolTimer timer)
        {
            try
            {

                Debug.WriteLine("1");
                String aqs = I2cDevice.GetDeviceSelector("I2C1");

                Debug.WriteLine("2");
                byte[] Digit1Data = new byte[8];
                byte[] Digit1Command = new byte[0];

                Debug.WriteLine("3");
                var deviceInfo = await DeviceInformation.FindAllAsync(aqs);

                Debug.WriteLine("4");
                Digit1 = await I2cDevice.FromIdAsync(deviceInfo[0].Id, new I2cConnectionSettings(0x70));

                Debug.WriteLine("5");
                Digit1.WriteRead(Digit1Command,Digit1Data);


                Debug.WriteLine("Trying to do the data thing");

          
                Debug.WriteLine(Digit1Data.ToString());
            }
            catch
            {
                Debug.WriteLine("Fuck you");
            }
    

        }
开发者ID:leeberg,项目名称:IotPinBall,代码行数:34,代码来源:MainPage.xaml.cs

示例11: InitI2C

        private async void InitI2C() {
            byte[] i2CWriteBuffer;
            byte[] i2CReadBuffer;
            byte bitMask;

            // Inicjalizacja I2C - urządzenie z RPI2
            string deviceSelector = I2cDevice.GetDeviceSelector();
            var i2cDeviceControllers = await DeviceInformation.FindAllAsync(deviceSelector);
            if (i2cDeviceControllers.Count == 0) {
                return;
            }

            //Ustawienia dla MCP230008
            var i2cSettings = new I2cConnectionSettings(I2C_ADDR_MCP23008);
            i2cSettings.BusSpeed = I2cBusSpeed.FastMode;
            i2cMCP23008 = await I2cDevice.FromIdAsync(i2cDeviceControllers[0].Id, i2cSettings);
            if (i2cMCP23008 == null) {
                return;
            }

            //Ustawienia dla PCF8591
            i2cSettings.SlaveAddress = I2C_ADDR_PCF8591;
            i2cPCF8591 = await I2cDevice.FromIdAsync(i2cDeviceControllers[0].Id, i2cSettings);
            if (i2cPCF8591 == null) {
                return;
            }

            //Ustawienia dla Arduino
            i2cSettings.SlaveAddress = I2C_ADDR_ARDUINO;
            i2cArduino = await I2cDevice.FromIdAsync(i2cDeviceControllers[0].Id, i2cSettings);
            if (i2cArduino == null) {
                return;
            }


            // Inicjalizacja port Expander 
			// Za: https://ms-iot.github.io/content/en-US/win10/samples/I2CPortExpander.htm 
            try {
                i2CReadBuffer = new byte[1];
                i2cMCP23008.WriteRead(new byte[] { MCP23008_IODIR }, i2CReadBuffer);
                iodirRegister = i2CReadBuffer[0];
                i2cMCP23008.WriteRead(new byte[] { MCP23008_GPIO }, i2CReadBuffer);
                gpioRegister = i2CReadBuffer[0];
                i2cMCP23008.WriteRead(new byte[] { MCP23008_OLAT }, i2CReadBuffer);
                olatRegister = i2CReadBuffer[0];

                // Konfiguracja PIN-a z laserem na 1; reszta bez zmian
                olatRegister |= LED_GPIO_PIN;
                i2CWriteBuffer = new byte[] { MCP23008_OLAT, olatRegister };
                i2cMCP23008.Write(i2CWriteBuffer);

                bitMask = (byte)(0xFF ^ LED_GPIO_PIN); // Tylko nasz PIN będzie miał maskę 0 - reszta będzie równa 1, co spowoduje że nie zmienią wartości
                iodirRegister &= bitMask;
                i2CWriteBuffer = new byte[] { MCP23008_IODIR, iodirRegister };
                i2cMCP23008.Write(i2CWriteBuffer);

            } catch (Exception e) {
                return;
            }


            //Komunikacja z Arduino
            byte[] wbuffer = new byte[] { 1, 2, 3, 4, 5, 6 };
            byte[] rbuffer = new byte[2];
			//Wysłanie liczb do dodania
            i2cArduino.Write(wbuffer);
            await Task.Delay(1000);
			//Odczytanie wyniku
            var result = i2cArduino.ReadPartial(rbuffer);
            //Wyświetlenie
			int sum = (((int)rbuffer[1]) << 8) + (int)rbuffer[0];
            Debug.WriteLine($"Suma:{sum}");

            //Błyskanie laserem co sekundę
            m_timer = new DispatcherTimer();
            m_timer.Interval = TimeSpan.FromMilliseconds(1000);
            m_timer.Tick += timer_Tick;
            m_timer.Start();

			//Zapis "trójkąta" do PCF8591 (w pętli, nieskończonej)
            await WritePCF8591();
        }
开发者ID:shaoyiwork,项目名称:WindowsIoT_I2CArduino,代码行数:82,代码来源:MainPage.xaml.cs

示例12: InitializeSystem

        private async void InitializeSystem()
        {
            byte[] i2CWriteBuffer;
            byte[] i2CReadBuffer;
            byte bitMask;
            
            // initialize I2C communications
            string deviceSelector = I2cDevice.GetDeviceSelector();
            var i2cDeviceControllers = await DeviceInformation.FindAllAsync(deviceSelector);
            if (i2cDeviceControllers.Count == 0)
            {
                ButtonStatusText.Text = "No I2C controllers were found on this system.";
                return;
            }
            
            var i2cSettings = new I2cConnectionSettings(PORT_EXPANDER_I2C_ADDRESS);
            i2cSettings.BusSpeed = I2cBusSpeed.FastMode;
            i2cPortExpander = await I2cDevice.FromIdAsync(i2cDeviceControllers[0].Id, i2cSettings);
            if (i2cPortExpander == null)
            {
                ButtonStatusText.Text = string.Format(
                    "Slave address {0} is currently in use on {1}. " +
                    "Please ensure that no other applications are using I2C.",
                    i2cSettings.SlaveAddress,
                    i2cDeviceControllers[0].Id);
                return;
            }

            // initialize I2C Port Expander registers
            try
            {
                // initialize local copies of the IODIR, GPIO, and OLAT registers
                i2CReadBuffer = new byte[1];

                // read in each register value on register at a time (could do this all at once but
                // for example clarity purposes we do it this way)
                i2cPortExpander.WriteRead(new byte[] { PORT_EXPANDER_IODIR_REGISTER_ADDRESS }, i2CReadBuffer);
                iodirRegister = i2CReadBuffer[0];

                i2cPortExpander.WriteRead(new byte[] { PORT_EXPANDER_GPIO_REGISTER_ADDRESS }, i2CReadBuffer);
                gpioRegister = i2CReadBuffer[0];

                i2cPortExpander.WriteRead(new byte[] { PORT_EXPANDER_OLAT_REGISTER_ADDRESS }, i2CReadBuffer);
                olatRegister = i2CReadBuffer[0];

                // configure the LED pin output to be logic high, leave the other pins as they are.
                olatRegister |= LED_GPIO_PIN;
                i2CWriteBuffer = new byte[] { PORT_EXPANDER_OLAT_REGISTER_ADDRESS, olatRegister };
                i2cPortExpander.Write(i2CWriteBuffer);

                // configure only the LED pin to be an output and leave the other pins as they are.
                // input is logic low, output is logic high
                bitMask = (byte)(0xFF ^ LED_GPIO_PIN); // set the LED GPIO pin mask bit to '0', all other bits to '1'
                iodirRegister &= bitMask;
                i2CWriteBuffer = new byte[] { PORT_EXPANDER_IODIR_REGISTER_ADDRESS, iodirRegister };
                i2cPortExpander.Write(i2CWriteBuffer);

            }
            catch (Exception e)
            {
                ButtonStatusText.Text = "Failed to initialize I2C port expander: " + e.Message;
                return;
            }

            // setup our timers, one for the LED blink interval, the other for checking button status
            
            ledTimer = new DispatcherTimer();
            ledTimer.Interval = TimeSpan.FromMilliseconds(TIMER_INTERVAL);
            ledTimer.Tick += LedTimer_Tick;
            ledTimer.Start();

            buttonStatusCheckTimer = new DispatcherTimer();
            buttonStatusCheckTimer.Interval = TimeSpan.FromMilliseconds(BUTTON_STATUS_CHECK_TIMER_INTERVAL);
            buttonStatusCheckTimer.Tick += ButtonStatusCheckTimer_Tick;
            buttonStatusCheckTimer.Start();
        }
开发者ID:Rbecca,项目名称:samples,代码行数:76,代码来源:MainPage.xaml.cs

示例13: readInt

 private int readInt(I2cDevice dev, byte addr)
 {
     byte[] w = new byte[2] { addr, 0 }, r = new byte[2];
     dev.WriteRead(w, r);
     return ((int)r[0]) << 8 + (int)r[0];
 }
开发者ID:tkopacz,项目名称:iot-kabelki-azure-iot-hub,代码行数:6,代码来源:IotTelemetrySource.cs

示例14: readByte

 private byte readByte(I2cDevice dev, byte addr)
 {
     byte[] w = new byte[1] { addr }, r = new byte[1];
     dev.WriteRead(w, r);
     return r[0];
 }
开发者ID:tkopacz,项目名称:iot-kabelki-azure-iot-hub,代码行数:6,代码来源:IotTelemetrySource.cs

示例15: ReadBytes

		public static byte[] ReadBytes(I2cDevice device, byte reg, int count, string exceptionMessage)
		{
			try
			{
				byte[] addr = { reg };

				byte[] data = new byte[count];

				device.WriteRead(addr, data);
				return data;
			}
			catch (Exception exception)
			{
				throw new SensorException(exceptionMessage, exception);
			}
		}
开发者ID:harshatech2012,项目名称:RPi.SenseHat,代码行数:16,代码来源:I2CSupport.cs


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