Esempio n. 1
0
        public static void Scan(II2CBus bus)
        {
            if (bus == null)
            {
                throw new ArgumentNullException("bus");
            }
            int        count        = 0;
            const int  clockRateKhz = 100;
            const int  timeout      = 100;
            const byte startAddress = 0x08;
            const byte endAddress   = 127;

            Debug.Print("Scanning I2C Bus for devices starting at: " + HexString.GetString(startAddress) + " ... ");
            for (byte address = startAddress; address < endAddress; address++)
            {
                var configuration = new I2CDevice.Configuration(address, clockRateKhz);
                var buffer        = new byte[] {
                    0
                };
                bool canRead  = bus.Read(configuration, buffer, timeout);
                bool canWrite = bus.Write(configuration, buffer, timeout);
                if (canRead || canWrite)
                {
                    count++;
                    Debug.Print("Address: 0x" + HexString.GetString(address) + ", Read => " + canRead + ", Write => " + canWrite);
                }
            }
            Debug.Print("Scanning ended at: " + HexString.GetString(endAddress));
            Debug.Print("Scanning found " + count + " devices.");
        }
Esempio n. 2
0
 private void SetPwm(byte num, ushort on, ushort off)
 {
     i2c.Write(i2caddr, new byte[] { (byte)(LED0_ON_L + 4 * num),
                                     (byte)on,
                                     (byte)(on >> 8),
                                     (byte)(off),
                                     (byte)(off >> 8) });
 }
Esempio n. 3
0
 protected bool Write(byte[] writeBuffer)
 {
     lock (_bus) {
         return(_bus.Write(_config, writeBuffer, _timeoutMilliseconds));
     }
 }