/// <summary> /// Initializes a new 1-wire master /// </summary> /// <typeparam name="T">Type of the master to be initialized.</typeparam> /// <param name="masterAddress">I2C address of the 1-wire master.</param> /// <param name="i2cController">Name of the I2C controller to which the 1-wire master is connected.</param> public void InitMaster <T>(byte masterAddress, string i2cController = "I2C1") where T : IOneWireMaster, new() { //Verbindung zum I²C-Buscontroller string aqs = I2cDevice.GetDeviceSelector(i2cController); var deviceInformation = DeviceInformation.FindAllAsync(aqs).AsTask().Result; //Verbindung zum OneWire Master einrichten und herstellen var masterSettings = new I2cConnectionSettings(masterAddress) { BusSpeed = I2cBusSpeed.FastMode }; var i2cDevice = I2cDevice.FromIdAsync(deviceInformation[0].Id, masterSettings).AsTask().Result; m_Master = new T(); m_Master.Init(i2cDevice); try { m_Master.OneWireReset(); } catch (Exception ex) { throw new Exception("1-wire master not found!", ex); } }
private void GetOneWireDevices(IOneWireMaster master, int oneWireChannel) { var first = true; var deviceDetected = master.OneWireReset(); //prüfen, ob Geräte erkannt if (deviceDetected) { var result = true; do { if (first) { first = false; result = master.OneWireFirst(); } else { result = master.OneWireNext(); } if (result) { foreach (byte code in Enum.GetValues(typeof(FamilyCode))) { if (code == master.RomNo[0]) { Type slaveType = ((FamilyCode)code).GetSlaveType(); var slave = (IOneWireSlave)Activator.CreateInstance(slaveType); byte[] slaveRomNo = new byte[8]; Array.Copy(master.RomNo, slaveRomNo, 8); slave.OneWireAddress = slaveRomNo; slave.Master = master; m_SlaveContainers.Add(new SlaveContainer(slave, oneWireChannel)); } } } } while (result); } }