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


C# I2CDevice.CreateReadTransaction方法代码示例

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


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

示例1: Main

        public static void Main()
        {
            //our 10 bit address
            const ushort address10Bit = 0x1001; //binary 1000000001 = 129
            const byte addressMask = 0x78; //reserved address mask 011110XX for 10 bit addressing

            //first MSB part of address
            ushort address1 = addressMask | (address10Bit >> 8); //is 7A and contains the two MSB of the 10 bit address
            I2CDevice.Configuration config = new I2CDevice.Configuration(address1, 100);
            I2CDevice device = new I2CDevice(config);

            //second LSB part of address
            byte address2 = (byte)(address10Bit & 0xFF); //the other 8 bits (LSB)
            byte[] address2OutBuffer = new byte[] { address2 };
            I2CDevice.I2CWriteTransaction addressWriteTransaction = device.CreateWriteTransaction(address2OutBuffer);

            //prepare buffer to write data
            byte[] outBuffer = new byte[] { 0xAA };
            I2CDevice.I2CWriteTransaction writeTransaction = device.CreateWriteTransaction(outBuffer);

            //prepare buffer to read data
            byte[] inBuffer = new byte[4];
            I2CDevice.I2CReadTransaction readTransaction = device.CreateReadTransaction(inBuffer);

            //execute transactions
            I2CDevice.I2CTransaction[] transactions =
                new I2CDevice.I2CTransaction[] { addressWriteTransaction, writeTransaction, readTransaction };
            device.Execute(transactions, 100);
        }
开发者ID:meikeric,项目名称:DotCopter,代码行数:29,代码来源:Program.cs

示例2: readValues

 void readValues(I2CDevice adxl345, short[] result)
 {
     byte[] values = new byte[6];
     I2CDevice.I2CTransaction[] xActions = new I2CDevice.I2CTransaction[2];
     byte[] RegisterNum = new byte[1] { valuesRegister };
     xActions[0] = adxl345.CreateWriteTransaction(RegisterNum);
     xActions[1] = adxl345.CreateReadTransaction(values);
     if (adxl345.Execute(xActions, 1000) == 0)
         throw new Exception("Unable to read accelerometer");
     result[0] = (short)(values[0] + (values[1] << 8));
     result[1] = (short)(values[2] + (values[3] << 8));
     result[2] = (short)(values[4] + (values[5] << 8));
 }
开发者ID:jbuusao,项目名称:NETMF-Projects,代码行数:13,代码来源:Program.cs

示例3: Main

        public static void Main()
        {
            I2CDevice.Configuration config = new I2CDevice.Configuration(58, //address
                                                                         100 //clockrate in KHz
                                                                         );
            I2CDevice device = new I2CDevice(config);

            //prepare buffer to write byte AA
            byte[] outBuffer = new byte[] { 0xAA };
            I2CDevice.I2CWriteTransaction writeTransaction = device.CreateWriteTransaction(outBuffer);

            //prepare buffer to read four bytes
            byte[] inBuffer = new byte[4];
            I2CDevice.I2CReadTransaction readTransaction = device.CreateReadTransaction(inBuffer);

            //execute both transactions
            I2CDevice.I2CTransaction[] transactions =
                new I2CDevice.I2CTransaction[] { writeTransaction, readTransaction };
            int transferred = device.Execute(transactions,
                                             100 //timeout in ms
                                             );
            //transferred bytes should be 1 + 4 = 5
        }
开发者ID:meikeric,项目名称:DotCopter,代码行数:23,代码来源:Program.cs


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