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


C# I2CDevice.Execute方法代码示例

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


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

示例1: Sketch

        // Explorations into I2C usage
        public static void Sketch()
        {
            // Create the config object with device address and clock speed
            I2CDevice.Configuration c = new I2CDevice.Configuration(0x68, 100);
            I2CDevice d = new I2CDevice(c);

            byte[] read_byte = new byte[1];

            byte test_value = 0x00;

            while (test_value < 0xff)
            {
                // Read the register
                I2CDevice.I2CWriteTransaction w = I2CDevice.CreateWriteTransaction(new byte[] { 0x14 });
                I2CDevice.I2CReadTransaction r = I2CDevice.CreateReadTransaction(read_byte);
                int bytes_exchanged = d.Execute(new I2CDevice.I2CTransaction[] { w, r }, 100);

                // Write to the register
                w = I2CDevice.CreateWriteTransaction(new byte[] { 0x14, test_value });
                bytes_exchanged = d.Execute(new I2CDevice.I2CTransaction[] { w }, 100);

                foreach (byte b in read_byte)
                {
                    Debug.Print(b.ToString());
                }
                test_value++;

                Thread.Sleep(3000);
            }
        }
开发者ID:binary10,项目名称:Netduino,代码行数:31,代码来源:Test.cs

示例2: ShieldStudioView

        public ShieldStudioView()
        {
            _device = new I2CDevice(new I2CDevice.Configuration(0x50, 400));

            // select configuration register
            // MAX6953 Table 6
            // disable shutdown
            _device.Execute(new I2CDevice.I2CTransaction[] { I2CDevice.CreateWriteTransaction(new byte[] { 0x04, 0x01 }) }, TIMEOUT);

            // MAX9653 Table 23
            // set Intensity for Digit 0 and 2
            // all segments 10 ma
            _device.Execute(new I2CDevice.I2CTransaction[] { I2CDevice.CreateWriteTransaction(new byte[] { 0x01, 0x33 }) }, TIMEOUT);

            // MAX9653 Table 24
            // set Intensity for Digit 1 and 3
            // all segments 10 ma
            _device.Execute(new I2CDevice.I2CTransaction[] { I2CDevice.CreateWriteTransaction(new byte[] { 0x02, 0x33 }) }, TIMEOUT);

            // turn on all LEDs in test mode.
            // MAX6953 Table 22
            _device.Execute(new I2CDevice.I2CTransaction[] { I2CDevice.CreateWriteTransaction(new byte[] { 0x07, 0x01 }) }, TIMEOUT);

            // disable test mode.
            // MAX6953 Table 22
            _device.Execute(new I2CDevice.I2CTransaction[] { I2CDevice.CreateWriteTransaction(new byte[] { 0x07, 0x00 }) }, TIMEOUT);
        }
开发者ID:thomasnguyencom,项目名称:learning-netduino,代码行数:27,代码来源:ShieldStudioView.cs

示例3: ScanAddresses

        /// <summary>
        /// Scan range of addresses and print devices to debug output.
        /// </summary>
        /// <param name="startAddress">Start of scanning (included)</param>
        /// <param name="endAddress">End of scanning (included)</param>
        /// <param name="clockRateKhz">frequency in Khz</param>
        public static void ScanAddresses(ushort startAddress, ushort endAddress, ushort clockRateKhz = 100)
        {
            Debug.Print("Scanning...");
            for (ushort adr = startAddress; adr <= endAddress; adr++)
            {

                I2CDevice device = new I2CDevice(new I2CDevice.Configuration(adr, clockRateKhz));
                byte[] buff = new byte[1];
                try
                {
                    I2CDevice.I2CReadTransaction read = I2CDevice.CreateReadTransaction(buff);
                    var ret = device.Execute(new I2CDevice.I2CTransaction[] { read }, 1000);
                    if(ret > 0) Debug.Print("Device on address: "+adr+ " (0x"+adr.ToString("X")+")");

                }
                catch (Exception){
                    continue;
                }
                finally
                {
                    //otestovat yda se dela pokazde
                    device.Dispose();
                    device = null;
                }
            }
            Debug.Print("Scanning finished.");
        }
开发者ID:marinehero,项目名称:NETMF-Utils,代码行数:33,代码来源:I2CScanner.cs

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

示例5: TSL2561

        public TSL2561(byte I2CAddress, int ClockinKHz)
        {
            I2CConfig = new I2CDevice.Configuration(I2CAddress, ClockinKHz);
              I2C = new I2CDevice(I2CConfig);

              // read the ID register.
              var Actions = new I2CDevice.I2CTransaction[2];
              byte[] rx = new byte[1];
              Actions[0] = I2CDevice.CreateWriteTransaction(new byte[] { 0x0a });
              Actions[1] = I2CDevice.CreateReadTransaction(rx);
              if (I2C.Execute(Actions, 1000) == 0)
              {
            Debug.Print("Read ID Register failed");
            // exit or something
              }
              else
              {
            Debug.Print("ID value: " + rx[0].ToString());
              }
              // 4 msb must be 0001 for a TSL2561
              if ((rx[0] & 0xf0) != 0xa0)
              {
            // exit or something
              }

              setGain(0x10);
              Thread.Sleep(5);   // Mandatory after each Write transaction !!!
        }
开发者ID:rhekkers,项目名称:LuxPlugOnPanda,代码行数:28,代码来源:TSL2561.cs

示例6: SiliconLabsSI7005

        public SiliconLabsSI7005(byte deviceId = DeviceIdDefault, int clockRateKHz = ClockRateKHzDefault, int transactionTimeoutmSec = TransactionTimeoutmSecDefault)
        {
            this.deviceId = deviceId;
             this.clockRateKHz = clockRateKHz;
             this.transactionTimeoutmSec = transactionTimeoutmSec;

             using (OutputPort i2cPort = new OutputPort(Pins.GPIO_PIN_SDA, true))
             {
            i2cPort.Write(false);
            Thread.Sleep(250);
             }

             using (I2CDevice device = new I2CDevice(new I2CDevice.Configuration(deviceId, clockRateKHz)))
             {
            byte[] writeBuffer = { RegisterIdDeviceId };
            byte[] readBuffer = new byte[1];

            // The first request always fails
            I2CDevice.I2CTransaction[] action = new I2CDevice.I2CTransaction[]
            {
               I2CDevice.CreateWriteTransaction(writeBuffer),
               I2CDevice.CreateReadTransaction(readBuffer)
            };

            if( device.Execute(action, transactionTimeoutmSec) == 0 )
            {
            //   throw new ApplicationException("Unable to send get device id command");
            }
             }
        }
开发者ID:CanterburyRegionalCouncil,项目名称:AirQualityMonitoringDevice,代码行数:30,代码来源:SiliconLabsSI7005.cs

示例7: Main

        public static void Main()
        {
            OutputPort Led = new OutputPort(Pins.ONBOARD_LED, false);

            byte[] Addr=new byte[2];
            Addr[0]=0x00;
            Addr[1]=0x01;

            byte[] TxBuff = new byte[4];
            TxBuff[0] = (byte)'1';
            TxBuff[1] = (byte)'2';
            TxBuff[2] = (byte)'3';
            TxBuff[3] = (byte)'4';

            byte[] RxBuff= new byte[4];

            I2CDevice.Configuration I2C_Configuration = new I2CDevice.Configuration(0x50, 400);
            I2CDevice I2C1 = new I2CDevice(I2C_Configuration);

            I2CDevice.I2CTransaction[] WriteTran = new I2CDevice.I2CTransaction[]
            {
                I2CDevice.CreateWriteTransaction(Addr),
                I2CDevice.CreateWriteTransaction(TxBuff)
            };

            I2CDevice.I2CTransaction[] ReadTran = new I2CDevice.I2CTransaction[]
            {
                I2CDevice.CreateWriteTransaction(Addr),
                I2CDevice.CreateReadTransaction(RxBuff)
            };

            while(true)
            {
                Led.Write(true);
                I2C1.Execute(WriteTran, 1000);
                Debug.Print("Write Success!");
                Thread.Sleep(200);
                I2C1.Execute(ReadTran, 1000);
                Debug.Print("Read Success!");
                string ReadOut = new string(System.Text.Encoding.UTF8.GetChars(RxBuff));
                Debug.Print("EEPROM CONTENT:"+ReadOut);
                Led.Write(false);
                Thread.Sleep(200);

            }
        }
开发者ID:rmerouze,项目名称:Netduino,代码行数:46,代码来源:Program.cs

示例8: SetRedLED

 public static void SetRedLED(I2CDevice FPGA, bool state)
 {
     int I2CTimeout = 1000;
     byte[] buffer = new byte[2];
     buffer[0] = 0x10;
     buffer[1] = state ? (byte)0x01 : (byte)0x00;
     var transaction = new I2CDevice.I2CTransaction[]
     {
         I2CDevice.CreateWriteTransaction(buffer)
     };
     FPGA.Execute(transaction, I2CTimeout);
 }
开发者ID:wramsdell,项目名称:Netduino_Example,代码行数:12,代码来源:Program.cs

示例9: GetData

 public static byte GetData(I2CDevice FPGA, byte Port)
 {
     int I2CTimeout = 1000;
     byte[] buffer = new byte[1];
     var transaction = new I2CDevice.I2CTransaction[]
     {
         I2CDevice.CreateWriteTransaction(new byte[] {Port}),
         I2CDevice.CreateReadTransaction(buffer)
     };
     FPGA.Execute(transaction, I2CTimeout);
     return buffer[0];
 }
开发者ID:wramsdell,项目名称:Netduino_Example,代码行数:12,代码来源:Program.cs

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

示例11: Magnetometer

        public Magnetometer()
        {
            monitor = new object();
            magnetometer = new I2CDevice(new I2CDevice.Configuration(address, freq));
            //I2CDevice.I2CWriteTransaction activeAutoReset_RAWMode = I2CDevice.CreateWriteTransaction(new byte[] { 0x12, 0xC0 });
            I2CDevice.I2CWriteTransaction activeMode = I2CDevice.CreateWriteTransaction(new byte[] { 0x10, 0x01 });
            I2CDevice.I2CWriteTransaction correct = I2CDevice.CreateWriteTransaction(new byte[] { 0x11, 0x00 });
            //I2CDevice.I2CWriteTransaction activeMode_FastMode = I2CDevice.CreateWriteTransaction(new byte[] { 0x10, 0x05 });
            int i = magnetometer.Execute(new I2CDevice.I2CTransaction[] { activeMode, correct }, 1000);

            //2285
            //-3062
            byte[] XOFF = FromShortC2(2630);
            I2CDevice.I2CWriteTransaction XOFFM = I2CDevice.CreateWriteTransaction(new byte[] { 0x09, XOFF[1] });
            I2CDevice.I2CWriteTransaction XOFFL = I2CDevice.CreateWriteTransaction(new byte[] { 0x0A, XOFF[0] });

            byte[] YOFF = FromShortC2(-3192);
            I2CDevice.I2CWriteTransaction YOFFM = I2CDevice.CreateWriteTransaction(new byte[] { 0x0B, YOFF[1] });
            I2CDevice.I2CWriteTransaction YOFFL = I2CDevice.CreateWriteTransaction(new byte[] { 0x0C, YOFF[0] });

            int i2 = magnetometer.Execute(new I2CDevice.I2CTransaction[] { XOFFM, XOFFL, YOFFM, YOFFL }, 1000);

            update = new Timer(new TimerCallback(read), new object(), 1000, 500);
        }
开发者ID:AlexAlbala,项目名称:MaCRo,代码行数:24,代码来源:Magnetometer.cs

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

示例13: GetRegister

        /// <summary>
        /// Returns the value contained in a register
        /// et +
        /// </summary>
        /// <param name="RegisterNumber">The register number</param>
        /// <returns></returns>
        private byte GetRegister(Registers RegisterNumber)
        {
            // Buffer d'écriture
                byte[] outBuffer = new byte[] { (byte)RegisterNumber };
                I2CDevice.I2CWriteTransaction writeTransaction = I2CDevice.CreateWriteTransaction(outBuffer);

                // Buffer de lecture
                byte[] inBuffer = new byte[1];
                I2CDevice.I2CReadTransaction readTransaction = I2CDevice.CreateReadTransaction(inBuffer);

                // Tableau des transactions
                I2CDevice.I2CTransaction[] transactions = new I2CDevice.I2CTransaction[] { writeTransaction, readTransaction };
                // Exécution des transactions
                busI2C = new I2CDevice(ConfigSRF08); // Connexion virtuelle du SRF08 au bus I2C

                if (busI2C.Execute(transactions, TRANSACTIONEXECUTETIMEOUT) != 0)
                {
                    // Success
                    //Debug.Print("Received the first data from at device " + busI2C.Config.Address + ": " + ((int)inBuffer[0]).ToString());
                }
                else
                {
                    // Failed
                    //Debug.Print("Failed to execute transaction at device: " + busI2C.Config.Address + ".");
                }
                busI2C.Dispose(); // Déconnexion virtuelle de l'objet Lcd du bus I2C
                return inBuffer[0];
        }
开发者ID:WebGE,项目名称:SRF08,代码行数:34,代码来源:SRF08.cs

示例14: ReadRange

        /// <summary>
        /// Triggers a shot ulrasons, wait for 75ms and return result in the unit of measure
        /// </summary>
        /// <param name="units">unit of measure expected</param>
        /// <returns>range in cm or inches or millisec</returns>
        public UInt16 ReadRange(MeasuringUnits units)
        {
            this.unit = units;
                // Calcul du mot de commande à partir de l'unité de mesure
                byte command = (byte)(80 + (byte)units);

                // Création d'un buffer et d'une transaction pour l'accès au module en écriture
                byte[] outbuffer = new byte[] { (byte)Registers.Command, command };
                I2CDevice.I2CTransaction WriteUnit = I2CDevice.CreateWriteTransaction(outbuffer);

                // Création d'un buffer et d'une transaction pour l'accès au module en lecture
                byte[] inbuffer = new byte[4];
                I2CDevice.I2CTransaction ReadDist = I2CDevice.CreateReadTransaction(inbuffer);

                // Tableaux des transactions
                I2CDevice.I2CTransaction[] T_WriteUnit = new I2CDevice.I2CTransaction[] { WriteUnit };
                I2CDevice.I2CTransaction[] T_ReadDist = new I2CDevice.I2CTransaction[] { ReadDist };

                // Exécution des transactions
                busI2C = new I2CDevice(ConfigSRF08); // Connexion virtuelle de l'objet SRF08 au bus I2C
                busI2C.Execute(T_WriteUnit, TRANSACTIONEXECUTETIMEOUT); // Transaction : Activation US
                Thread.Sleep(75); // attente echo US
                busI2C.Execute(T_ReadDist, TRANSACTIONEXECUTETIMEOUT); // Transaction : Lecture distance
                UInt16 range = (UInt16)((UInt16)(inbuffer[3] << 8) + inbuffer[2]); // Calcul de la distance
                busI2C.Dispose(); // Déconnexion virtuelle de l'objet SRF08 du bus I2C
                return range;
        }
开发者ID:WebGE,项目名称:SRF08,代码行数:32,代码来源:SRF08.cs

示例15: TrigShotUS

        /// <summary>
        /// Only triggers a shot ulrasons
        /// </summary>
        /// <param name="units">unit of measure expected</param>
        public void TrigShotUS(MeasuringUnits units)
        {
            this.unit = units;
                // Calcul du mot de commande à partir de l'unité de mesure
                byte commandByte = (byte)(80 + (byte)units);

                // Création d'un buffer et d'une transaction pour l'accès au module en écriture
                byte[] outbuffer = new byte[] { (byte)Registers.Command, commandByte };
                I2CDevice.I2CTransaction WriteUnit = I2CDevice.CreateWriteTransaction(outbuffer);

                // Tableaux des transactions
                I2CDevice.I2CTransaction[] T_WriteUnit = new I2CDevice.I2CTransaction[] { WriteUnit };

                // Exécution de la transactions
                busI2C = new I2CDevice(ConfigSRF08); // Connexion virtuelle de l'objet SRF08 au bus I2C
                busI2C.Execute(T_WriteUnit, TRANSACTIONEXECUTETIMEOUT); // Transaction : Activation US
                busI2C.Dispose(); // Déconnexion virtuelle de l'objet SRF08 du bus I2C
        }
开发者ID:WebGE,项目名称:SRF08,代码行数:22,代码来源:SRF08.cs


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