/// <summary> /// Loads the device metadata /// </summary> /// <param name="busDevice"></param> /// <returns></returns> public static async Task GetDeviceMetadata(this Kaenx.Konnect.Classes.BusDevice busDevice, Dictionary <string, RawKnxDeviceMetadata> pReadlistB) { RawMetaData r = await GetRawDeviceMetadata(busDevice); foreach (KeyValuePair <string, RawKnxDeviceMetadata> k in r.ReadList) { if (k.Value.PropertyValue != null) { if (k.Value.PropertyValue is byte[]) { string bytesReadable = BitConverter.ToString(k.Value.PropertyValue as Byte[]); string stringRepresentation = ASCIIEncoding.ASCII.GetString(k.Value.PropertyValue as byte[]).ToLiteral(); Console.WriteLine(k.Key + ": " + bytesReadable + "[" + stringRepresentation + "]"); } else { Console.WriteLine(k.Key + ": " + k.Value.PropertyValue.ToString()); } } else if (k.Value.RawPropertyValue == null) { Console.WriteLine(k.Key + ": PropertyValue is null, " + (k.Value.ReadSuccessful ? "Read was ok" : "Read failed") + ", Raw Object is null too."); } else { Console.WriteLine(k.Key + ": PropertyValue is null, " + (k.Value.ReadSuccessful ? "Read was ok" : "Read failed") + ", Raw Object contains " + k.Value.RawPropertyValue.Length + " Bytes"); } } }
private static async Task <RawMetaData> GetRawDeviceMetadata(BusDevice busDevice, Dictionary <string, RawKnxDeviceMetadata> pReadlist, int throttling = 300) { // Sanity Checks // Read 0x00 0x01, we are expecting a zero here per KNX Standard Byte[] ba = await busDevice.PropertyRead(0x00, 0x01); UInt16 ui = BitConverter.ToUInt16(ba, 0); Byte[] ba2 = await busDevice.PropertyRead(0x00, 0x02); string s = ASCIIEncoding.ASCII.GetString(ba2); RawMetaData rawData = new RawMetaData(RawMetaData.ReadListDefinition.Empty); rawData.ReadList = pReadlist; foreach (RawKnxDeviceMetadata kvp in rawData.ReadList.Values) { Thread.Sleep(throttling); kvp.TriedReading = true; try { Byte[] baValue = await busDevice.PropertyRead <byte[]>((Byte)kvp.ObjectId, (Byte)kvp.ValueId); kvp.ReadSuccessful = true; kvp.RawPropertyValue = baValue; } catch (Exception Ex) { Console.WriteLine(Ex.ToString()); kvp.ReadSuccessful = false; } } return(rawData); }