private void button2_Click(object sender, EventArgs e) { if (databaseClass != null) { DeviceRecord deviceRecord = new DeviceRecord(); deviceRecord.DeviceID = string.Format("{0}", rnd.Next(1, 5)); deviceRecord.DeviceName = "Prietaiso pavadinimas"; deviceRecord.Location = "Kazkur"; deviceRecord.AddValue(new DeviceValue(DateTime.Now, "DeviceTime", "", "")); deviceRecord.AddValue(new DeviceValue(rnd.NextDouble() * 1000.0, "Energy", "MWh", "")); deviceRecord.AddValue(new DeviceValue(rnd.NextDouble() * 100000.0, "Volume", "m3", "")); deviceRecord.AddValue(new DeviceValue(rnd.NextDouble() * 10.0, "Flow", "m3/h", "")); deviceRecord.AddValue(new DeviceValue(rnd.NextDouble() * 10.0, "Power", "kW", "")); deviceRecord.AddValue(new DeviceValue(rnd.NextDouble() * 100.0, "T1", "°C", "")); deviceRecord.AddValue(new DeviceValue(rnd.NextDouble() * 100.0, "T2", "°C", "")); deviceRecord.AddValue(new DeviceValue(rnd.NextDouble() * 100.0, "dT", "°C", "")); deviceRecord.AddValue(new DeviceValue(rnd.NextDouble() * 100.0, "OnTime", "h", "")); deviceRecord.AddValue(new DeviceValue("0000001001101111", "Error", "", "")); databaseClass.AddNewRecord(deviceRecord); DatabaseClass.GetDeviceList(cbDeviceList); if (cbDeviceList.Items.Count > 0) { cbDeviceList.SelectedIndex = 0; } } }
private static bool DecodingMBUSData(ref byte[] Data, int Size, DeviceRecord deviceRecord) { int ValueIndex = 0; deviceRecord.DeviceID = string.Format("{0}", Common.bcdTobin(ref Data, 7, 4)); ValueIndex = 12 + 7; while (ValueIndex < Size - 2) { var ValueClass = new VIF_DIF_Value(); ValueIndex = DecodingDIF(ref Data, ValueIndex, ValueClass); ValueIndex = DecodingVIF(ref Data, ValueIndex, ValueClass); if (ValueClass.DateTimeFormat > 0) { switch (ValueClass.DateTimeFormat) { case 1: ValueClass.Value = DecodeDateTypeF(ref Data, ValueIndex); break; case 2: ValueClass.Value = DecodeDateTimeTypeF(ref Data, ValueIndex); break; default: break; } } else { switch (ValueClass.ValueSize) { case 0: return(false); case 1: ValueClass.Value = string.Format("{0}", (Data[ValueIndex]) * ValueClass.Daug); break; case 2: ValueClass.Value = string.Format("{0}", (System.BitConverter.ToUInt16(Data, ValueIndex)) * ValueClass.Daug); break; case 3: ValueClass.Value = string.Format("{0}", (System.BitConverter.ToUInt32(Data, ValueIndex) & 0xFFFFFF) * ValueClass.Daug); break; case 4: ValueClass.Value = string.Format("{0}", (System.BitConverter.ToUInt32(Data, ValueIndex)) * ValueClass.Daug); break; case 5: try { ValueClass.Value = string.Format("{0}", (System.BitConverter.ToSingle(Data, ValueIndex)) * ValueClass.Daug); } catch (Exception) { ValueClass.Value = ""; } ValueClass.ValueSize = 4; break; case 6: ValueClass.Value = string.Format("{0}", (System.BitConverter.ToUInt64(Data, ValueIndex) & 0xFFFFFFFFFFFF) * ValueClass.Daug); break; case 7: ValueClass.Value = string.Format("{0}", (System.BitConverter.ToUInt64(Data, ValueIndex)) * ValueClass.Daug); break; case 0x0D: ValueClass.ValueSize = Data[ValueIndex]; break; default: if ((ValueClass.ValueSize & 0x08) > 0) { ValueClass.Value = string.Format("{0}", (Common.bcdTobin(ref Data, ValueIndex, (ValueClass.ValueSize & 7))) * ValueClass.Daug); ValueClass.ValueSize = (ValueClass.ValueSize & 0x07); } else { return(false); } break; } } deviceRecord.AddValue(new DeviceValue(ValueClass.Value, ValueClass.Name, ValueClass.Dimention, "")); ValueIndex += ValueClass.ValueSize; } return(true); }