• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Hardware.I2CDevice类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



I2CDevice类属于Microsoft.SPOT.Hardware命名空间,在下文中一共展示了I2CDevice类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Accelerometer

        public Accelerometer(I2CDevice bus, ushort deviceAddress = 0x53, int clockRate = 400)
        {
            this.bus = bus;
            configuration = new I2CDevice.Configuration(deviceAddress, clockRate);

            ConfigureDevice();
        }
开发者ID:ducas,项目名称:Robbo,代码行数:7,代码来源:Accelerometer.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: Sketch01

        public static void Sketch01()
        {
            //create I2C object
            //note that the netmf i2cdevice configuration requires a 7-bit address! It set the 8th R/W bit automatically.
            I2CDevice.Configuration con =
                new I2CDevice.Configuration(0x68, 100);
            I2CDevice MyI2C = new I2CDevice(con);

            // Create transactions
            // We need 2 in this example, we are reading from the device
            // First transaction is writing the "read command"
            // Second transaction is reading the data
            I2CDevice.I2CTransaction[] xActions =
                new I2CDevice.I2CTransaction[2];

            // create write buffer (we need one byte)
            byte[] RegisterNum = new byte[1] { 0x14 };
            xActions[0] = I2CDevice.CreateWriteTransaction(RegisterNum);
            // create read buffer to read the register
            byte[] RegisterValue = new byte[1];
            xActions[1] = I2CDevice.CreateReadTransaction(RegisterValue);

            // Now we access the I2C bus using a timeout of one second
            // if the execute command returns zero, the transaction failed (this
            // is a good check to make sure that you are communicating with the device correctly
            // and don’t have a wiring issue or other problem with the I2C device)
            if (MyI2C.Execute(xActions, 1000) == 0)
            {
                Debug.Print("Failed to perform I2C transaction");
            }
            else
            {
                Debug.Print("Register value: " + RegisterValue[0].ToString());
            }
        }
开发者ID:binary10,项目名称:Netduino,代码行数:35,代码来源:Test.cs


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


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

        public static void Main()
        {
            var i2c = new I2CDevice(new I2CDevice.Configuration(0x42, 400));
            var sensor = new MjTextileSensor.MjTextileSensor(i2c);

            byte majorVersion;
            byte minorVersion;
            sensor.GetVersion(out majorVersion, out minorVersion);
            Debug.Print("Firmware version is " + majorVersion + "." + minorVersion + ".");

            var values = new byte[10];
            for (; ; )
            {
                int valuesCount = sensor.GetSensorValues(values);
                if (valuesCount != 10)
                {
                    Thread.Sleep(1000);
                    continue;
                }

                var message = "";
                for (int i = 0; i < valuesCount; i++)
                {
                    message += values[i].ToString() + " ";
                }
                Debug.Print(message);

                Thread.Sleep(1000);
            }
        }
开发者ID:matsujirushi,项目名称:TextileSensorKit,代码行数:30,代码来源:Program.cs


示例7: Init

        /// <summary>
        /// Turns on the Oscillator. Turns on the Display. Turns off Blinking. Sets Brightness to full.
        /// </summary>
        public void Init()
        {
            Config = new I2CDevice.Configuration(HT16K33_ADRESS, HT16K33_CLKRATE);
            Matrix = new I2CDevice(Config);

            byte[] write = new byte[1];
            write[0] = HT16K33_OSC_ON; // IC Oscillator ON

            byte[] write2 = new byte[1];
            write2[0] = HT16K33_DISPLAY_ON; // Display ON

            I2CDevice.I2CTransaction[] i2cTx = new I2CDevice.I2CTransaction[1];
            i2cTx[0] = I2CDevice.CreateWriteTransaction(write);

            I2CDevice.I2CTransaction[] i2cTx2 = new I2CDevice.I2CTransaction[1];
            i2cTx2[0] = I2CDevice.CreateWriteTransaction(write2);

            Matrix.Execute(i2cTx, Timeout);
            Matrix.Execute(i2cTx2, Timeout);

            // initialize DisplayBuffer
            for (int i = 0; i < 8; i++)
            {
                DisplayBuffer[i] = 0x00;
            }
        }
开发者ID:MichaelCastano,项目名称:netmf.MC.LEDBackpack,代码行数:29,代码来源:Matrix_8x8.cs


示例8: Read

 public void Read(I2CDevice.Configuration config, byte[] buffer, int transactionTimeout)
 {
     _slaveDevice.Config = config;
     I2CDevice.I2CTransaction[] i2CTransactions = new I2CDevice.I2CTransaction[] { I2CDevice.CreateReadTransaction(buffer) };
     lock (_slaveDevice)
         _slaveDevice.Execute(i2CTransactions, transactionTimeout);
 }
开发者ID:lukecummings,项目名称:DotCopter,代码行数:7,代码来源:I2CBus.cs


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


示例10: Execute

 public int Execute(I2CDevice.I2CTransaction[] xActions, int timeout)
 {
     if (this.isDisposed)
         throw new ObjectDisposedException();
     singletonDevice.Config = this.Config;
     return singletonDevice.Execute(xActions, timeout);
 }
开发者ID:meikeric,项目名称:DotCopter,代码行数:7,代码来源:I2CDevice2.cs


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


示例12: NativeI2CBus

        public NativeI2CBus(Socket socket, ushort address, int clockRateKhz, Module module)
        {
            if (_device == null)
                _device = new Hardware.I2CDevice(new Hardware.I2CDevice.Configuration(0, 50));

            _configuration = new Hardware.I2CDevice.Configuration(address, clockRateKhz);
        }
开发者ID:EmiiFont,项目名称:MyShuttle_RC,代码行数:7,代码来源:NativeI2CBus.cs


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


示例14: run

        void run()
        {
            values[0] = values[1] = values[2] = -1;
            oldValues[0] = oldValues[1] = oldValues[2] = -1;

            I2CDevice.Configuration configuration = new I2CDevice.Configuration(deviceAddress, 400);
            I2CDevice adxl345 = new I2CDevice(configuration);
            writeCommand(adxl345, 0x2d, 0);
            writeCommand(adxl345, 0x2d, 16);
            writeCommand(adxl345, 0x2d, 8);
            // Set the g range to 2g - typical output: 17, -32, 257 (scale = 3.9 => 66 mg, -124 mg, 1002 mg)
            writeCommand(adxl345, 0x31, 0);
            // Set the g range to 16g - typical output: 2, -4, 31 (scale = 31.2 => 62.4 mg, -124.8 mg, 967 mg)
            // writeCommand(adxl345, 0x31, 3);
            while (true)
            {
                readValues(adxl345, values);
                if ((changed(values[0], oldValues[0])) || (changed(values[1], oldValues[1])) || (changed(values[2], oldValues[2])))
                {
                    //Debug.Print("Values: " + values[0] + ", " + values[1] + ", " + values[2]+"\n");
                    reporter.report(values[0] + "," + values[1] + "," + values[2]+"\n\r");
                }
                oldValues[0] = values[0];
                oldValues[1] = values[1];
                oldValues[2] = values[2];
            }
        }
开发者ID:jbuusao,项目名称:NETMF-Projects,代码行数:27,代码来源:Program.cs


示例15: I2CPlug

 /// <summary>
 /// Create a new abstract I2C device.
 /// </summary>
 /// <param name="Address">I2C address.</param>
 /// <param name="ClockRateKhz">I2C clockrate.</param>
 public I2CPlug(Byte    Address,
                UInt32  ClockRateKhz = DefaultClockRate)
 {
     this._Address    = Address;
     this.I2C_Config  = new I2CDevice.Configuration(this.Address, (Int32) ClockRateKhz);
     this.I2C_Device  = new I2CDevice(this.I2C_Config);
 }
开发者ID:Vanaheimr,项目名称:Nyi,代码行数:12,代码来源:I2CPlug.cs


示例16: TWIDisplay

        // Create new instance using a pre-created I2CDevice
        public TWIDisplay(I2CDevice display)
        {
            m_data = new byte[4];
            m_dots = 0;
            m_display = display;

            setRotateMode();
        }
开发者ID:akafugu,项目名称:twidisplay,代码行数:9,代码来源:TWIDisplay.cs


示例17: Execute

 public override int Execute(I2CDevice.I2CTransaction[] transactions, int millisecondsTimeout)
 {
     lock (_device)
     {
         _device.Config = _configuration;
         return _device.Execute(transactions, millisecondsTimeout);
     }
 }
开发者ID:EmiiFont,项目名称:MyShuttle_RC,代码行数:8,代码来源:I2CBus.cs


示例18: InitBlinkM

 private void InitBlinkM(I2CDevice i2cDevice, I2CDevice.Configuration blinkM)
 {
     BlinkMCommand.StopScript.Execute(i2cDevice, blinkM);
     // BlinkMCommand.GetAddress.Execute(i2cDevice, blinkM);
     // BlinkMCommand.GetVersion.Execute(i2cDevice, blinkM);
     BlinkMCommand.SetFadeSpeed.Execute(i2cDevice, blinkM, 255);
     BlinkMCommand.FadeToHSB.Execute(i2cDevice, blinkM, 0, 0, 0);
 }
开发者ID:cjdaly,项目名称:napkin,代码行数:8,代码来源:Program.cs


示例19: Read

        public int Read(XI2CDevice.Configuration configuration, byte[] data)
        {
            _device.Config = configuration;

            XI2CDevice.I2CReadTransaction read = XI2CDevice.CreateReadTransaction(data);

            return _device.Execute(new XI2CDevice.I2CTransaction[] { read }, _readTimeout);
        }
开发者ID:iainmckay,项目名称:jollyi2c,代码行数:8,代码来源:I2CBus.cs


示例20: GetRegister

 public static byte GetRegister(this I2CDevice device, I2CDevice.Configuration config, int timeout, byte register)
 {
     byte result;
     if (TryGetRegister(device, config, timeout, register, out result))
         return result;
     else
         throw new Exception();
 }
开发者ID:KonstantinKolesnik,项目名称:MFE,代码行数:8,代码来源:I2CExtension.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# I2CDevice.I2CTransaction类代码示例发布时间:2022-05-26
下一篇:
C# Hardware.Cpu类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap