Exemplo n.º 1
0
 /// <summary>
 /// Constructs DS-18B20 object for a given 1-wire bus and a device sequence number. 
 /// </summary>
 /// <param name="bus">1-wire bus to whish the sensor is attached</param>
 /// <param name="index">sequence index of a bus element</param>
 public Ds18b20(OneWire bus, int index)
 {
     if (bus.AcquireEx() < 0)
     {
         throw new InvalidOperationException("Invalid OneWire bus.");
     }
     OneWireBus = bus;
     ArrayList devices = GetDevices();
     if (index >= devices.Count)
     {
         throw new IndexOutOfRangeException("Invalid device number.");
     }
     Address = (byte[])devices[index];
 }
Exemplo n.º 2
0
 /// <summary>
 /// Constructs DS-18B20 object for a given 1-wire bus and a device address
 /// </summary>
 /// <param name="bus">1-wire bus to whish the sensor is attached</param>
 /// <param name="address">device address</param>
 public Ds18b20(OneWire bus, byte[] address)
 {
     if (bus.AcquireEx() < 0)
     {
         throw new InvalidOperationException("Invalid OneWire bus.");
     }
     OneWireBus = bus;
     ArrayList devices = GetDevices();
     foreach (byte[] Address in devices)
     {
         if (Address.Compare(address))
         {
             this.Address = Address;
             return;
         }
     }
     throw new InvalidOperationException("Device with the specified address is not present in the bus.");
 }