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


C# I2cDevice.ReadPartial方法代码示例

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


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

示例1: 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

示例2: setPWMFreq

        // set the PWM frequency for the servos on the specified servo controll board 
        private static void setPWMFreq(I2cDevice board, int freq)
        {
            double preScale = 25000000.0;
            preScale /= 4096;
            preScale /= (float)freq;
            preScale -= 1.0;

            preScale = Math.Floor(preScale + .5);
            var oldMode = board.ReadPartial(new byte[] { (byte)(PCA9685_REG_MODE1) });
            var newMode = (oldMode.BytesTransferred & 0x7F) | 0x10;
            board.Write(new byte[] { (byte)PCA9685_REG_MODE1, (byte)(newMode) });
            board.Write(new byte[] { (byte)PCA9685_REG_PRESCALE, (byte)(Math.Floor(preScale)) });
            board.Write(new byte[] { (byte)PCA9685_REG_MODE1, (byte)(oldMode.BytesTransferred) });
            board.Write(new byte[] { (byte)PCA9685_REG_MODE1, (byte)(oldMode.BytesTransferred | 0x80) });
        }
开发者ID:peejster,项目名称:hexapet,代码行数:16,代码来源:Movements.cs


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