예제 #1
0
 protected bool Read(out byte value)
 {
     lock (_bus) {
         bool success = _bus.Read(_config, _buffer1, _timeoutMilliseconds);
         if (!success)
         {
             value = 0;
             return(false);
         }
         value = _buffer1[0];
         return(true);
     }
 }
예제 #2
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.");
        }