/// <summary> /// Constructor. /// </summary> public GXDLMSDayProfileAction(GXDateTime startTime, string scriptLogicalName, UInt16 scriptSelector) { StartTime = startTime; ScriptLogicalName = scriptLogicalName; ScriptSelector = scriptSelector; }
/// <summary> /// Get difference between given time and run time in ms. /// </summary> /// <param name="start">Start date time.</param> /// <param name="to">Compared time.</param> /// <returns>Difference in milliseconds.</returns> public static long GetDifference(DateTime start, GXDateTime to) { long diff = 0; //Compare ms. if ((to.Skip & DateTimeSkips.Ms) == 0) { if (start.Millisecond < to.Value.Millisecond) { diff = to.Value.Millisecond; } else { diff = -to.Value.Millisecond; } } //Compare seconds. if ((to.Skip & DateTimeSkips.Second) == 0) { if (start.Second < to.Value.Second) { diff += (to.Value.Second - start.Second) * 1000L; } else { diff -= (start.Second - to.Value.Second) * 1000L; } } else if (diff < 0) { diff = 60000 + diff; } //Compare minutes. if ((to.Skip & DateTimeSkips.Minute) == 0) { if (start.Minute < to.Value.Minute) { diff += (to.Value.Minute - start.Minute) * 60000L; } else { diff -= (start.Minute - to.Value.Minute) * 60000L; } } else if (diff < 0) { diff = 60 * 60000 + diff; } //Compare hours. if ((to.Skip & DateTimeSkips.Hour) == 0) { if (start.Hour < to.Value.Hour) { diff += (to.Value.Hour - start.Hour) * 60 * 60000L; } else { diff -= (start.Hour - to.Value.Hour) * 60 * 60000L; } } else if (diff < 0) { diff = 60 * 60000 + diff; } //Compare days. if ((to.Skip & DateTimeSkips.Day) == 0) { if (start.Day < to.Value.Day) { diff += (to.Value.Day - start.Day) * 24 * 60 * 60000; } else if (start.Day != to.Value.Day) { if ((to.Skip & DateTimeSkips.Month) == 0) { diff += (to.Value.Day - start.Day) * 24 * 60 * 60000L; } else { diff = ((DateTime.DaysInMonth(start.Year, start.Month) - start.Day + to.Value.Day) * 24 * 60 * 60000L) + diff; } } } else if (diff < 0) { diff = 24 * 60 * 60000 + diff; } //Compare months. if ((to.Skip & DateTimeSkips.Month) == 0) { if (start.Month < to.Value.Month) { for (int m = start.Month; m != to.Value.Month; ++m) { diff += DateTime.DaysInMonth(start.Year, m) * 24 * 60 * 60000L; } } else { for (int m = to.Value.Month; m != start.Month; ++m) { diff += -DateTime.DaysInMonth(start.Year, m) * 24 * 60 * 60000L; } } } else if (diff < 0) { diff = DateTime.DaysInMonth(start.Year, start.Month) * 24 * 60 * 60000L + diff; } return(diff); }
/// <summary> /// Convert date time to Epoch time. /// </summary> /// <param name="date">Date and time.</param> /// <returns>Unix time.</returns> public static long ToUnixTime(GXDateTime date) { return(ToUnixTime(date.Value.DateTime)); }
void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e) { if (e.Index == 1) { if (e.Value is string) { LogicalName = e.Value.ToString(); } else { LogicalName = GXDLMSClient.ChangeType((byte[])e.Value, DataType.OctetString).ToString(); } } else if (e.Index == 2) { if (Scaler != 1) { try { CurrentAverageValue = Convert.ToDouble(e.Value) * Scaler; } catch (Exception) { //Sometimes scaler is set for wrong Object type. CurrentAverageValue = e.Value; } } else { CurrentAverageValue = e.Value; } } else if (e.Index == 3) { if (Scaler != 1) { try { LastAverageValue = Convert.ToDouble(e.Value) * Scaler; } catch (Exception) { //Sometimes scaler is set for wrong Object type. LastAverageValue = e.Value; } } else { LastAverageValue = e.Value; } } else if (e.Index == 4) { if (e.Value == null) { Scaler = 1; Unit = Unit.None; } else { object[] arr = (object[])e.Value; if (arr.Length != 2) { throw new Exception("setValue failed. Invalid scaler unit value."); } _scaler = Convert.ToInt32(arr[0]); Unit = (Unit)Convert.ToInt32(arr[1]); } } else if (e.Index == 5) { Status = Convert.ToInt32(e.Value); } else if (e.Index == 6) { if (e.Value == null) { CaptureTime = new GXDateTime(DateTime.MinValue); } else { if (e.Value is byte[]) { e.Value = GXDLMSClient.ChangeType((byte[])e.Value, DataType.DateTime); } CaptureTime = (GXDateTime)e.Value; } } else if (e.Index == 7) { if (e.Value == null) { StartTimeCurrent = new GXDateTime(DateTime.MinValue); } else { if (e.Value is byte[]) { e.Value = GXDLMSClient.ChangeType((byte[])e.Value, DataType.DateTime); } StartTimeCurrent = (GXDateTime)e.Value; } } else if (e.Index == 8) { Period = Convert.ToUInt32(e.Value); } else if (e.Index == 9) { NumberOfPeriods = Convert.ToUInt16(e.Value); } else { e.Error = ErrorCode.ReadWriteDenied; } }
static public object ChangeType(object value, DataType type, CultureInfo cultureInfo) { object ret; if (type == DataType.OctetString) { if (value is byte[]) { ret = value; } else { ret = GXDLMSTranslator.HexToBytes((string)value); } } else if (type == DataType.DateTime) { if (value is GXDateTime) { ret = value; } else { ret = new GXDateTime((string)value, CultureInfo.InvariantCulture); } } else if (type == DataType.Date) { if (value is GXDateTime) { ret = value; } else { ret = new GXDate((string)value, CultureInfo.InvariantCulture); } } else if (type == DataType.Time) { if (value is GXDateTime) { ret = value; } else { ret = new GXTime((string)value, CultureInfo.InvariantCulture); } } else if (type == DataType.Enum) { if (value is GXEnum) { ret = value; } else { ret = new GXEnum((byte)Convert.ChangeType(value, typeof(byte))); } } else if (type == DataType.Structure || type == DataType.Array) { ret = GXDLMSTranslator.XmlToValue((string)value); } else if (type == DataType.BitString) { ret = new GXBitString((string)value); } else if (type == DataType.None && value is string && string.IsNullOrEmpty((string)value)) { ret = null; } else { ret = Convert.ChangeType(value, GXDLMSConverter.GetDataType(type), cultureInfo); } return(ret); }
void IGXDLMSBase.SetValue(int index, object value) { if (index == 1) { if (value is string) { LogicalName = value.ToString(); } else { LogicalName = GXDLMSClient.ChangeType((byte[])value, DataType.OctetString).ToString(); } } else if (index == 2) { if (value == null) { Time = new GXDateTime(DateTime.MinValue); } else { if (value is byte[]) { value = GXDLMSClient.ChangeType((byte[]) value, DataType.DateTime); } Time = (GXDateTime)value; } } else if (index == 3) { TimeZone = Convert.ToInt32(value); } else if (index == 4) { Status = (ClockStatus)Convert.ToInt32(value); } else if (index == 5) { if (value == null) { Begin = new GXDateTime(DateTime.MinValue); } else { if (value is byte[]) { value = GXDLMSClient.ChangeType((byte[])value, DataType.DateTime); } Begin = (GXDateTime)value; } } else if (index == 6) { if (value == null) { End = new GXDateTime(DateTime.MinValue); } else { if (value is byte[]) { value = GXDLMSClient.ChangeType((byte[])value, DataType.DateTime); } End = (GXDateTime)value; } } else if (index == 7) { Deviation = Convert.ToInt32(value); } else if (index == 8) { Enabled = Convert.ToBoolean(value); } else if (index == 9) { ClockBase = (ClockBase)Convert.ToInt32(value); } else { throw new ArgumentException("SetValue failed. Invalid attribute index."); } }
/// <summary> /// Constructor. /// </summary> /// <param name="ln">Logican Name of the object.</param> /// <param name="sn">Short Name of the object.</param> public GXDLMSClock(string ln, ushort sn) : base(ObjectType.Clock, ln, sn) { Time = new GXDateTime(DateTime.MinValue); }
static public object ChangeType(object value, DataType type, CultureInfo cultureInfo) { object ret; if (type == DataType.OctetString) { if (value is byte[]) { ret = value; } else { ret = GXDLMSTranslator.HexToBytes((string)value); } } else if (type == DataType.DateTime) { if (value is GXDateTime) { ret = value; } else { ret = new GXDateTime((string)value, CultureInfo.InvariantCulture); } } else if (type == DataType.Date) { if (value is GXDateTime) { ret = value; } else { ret = new GXDate((string)value, CultureInfo.InvariantCulture); } } else if (type == DataType.Time) { if (value is GXDateTime) { ret = value; } else { ret = new GXTime((string)value, CultureInfo.InvariantCulture); } } else if (type == DataType.Enum) { if (value is GXEnum) { ret = value; } else { ret = new GXEnum((byte)Convert.ChangeType(value, typeof(byte))); } } else { ret = Convert.ChangeType(value, GXDLMSConverter.GetDataType(type)); } return(ret); }
/// <summary> /// Constructor. /// </summary> public GXDateTimeOS(GXDateTime value) : base(value, null) { }
/// <summary> /// Constructor. /// </summary> public GXDate(GXDateTime value) : base(value) { Skip = value.Skip | DateTimeSkips.Hour | DateTimeSkips.Minute | DateTimeSkips.Second | DateTimeSkips.Ms; }
/// <summary> /// Constructor. /// </summary> public GXDateOS(GXDateTime value) : base(value) { }
void IGXDLMSBase.SetValue(int index, object value) { if (index == 1) { if (value is string) { LogicalName = value.ToString(); } else { LogicalName = GXDLMSClient.ChangeType((byte[])value, DataType.OctetString).ToString(); } } else if (index == 2) { if (value is byte[]) { CalendarNameActive = GXDLMSClient.ChangeType((byte[])value, DataType.String).ToString(); } else { CalendarNameActive = Convert.ToString(value); } } else if (index == 3) { SeasonProfileActive = null; if (value != null) { List<GXDLMSSeasonProfile> items = new List<GXDLMSSeasonProfile>(); foreach (object[] item in (object[])value) { GXDLMSSeasonProfile it = new GXDLMSSeasonProfile(); it.Name = GXDLMSClient.ChangeType((byte[]) item[0], DataType.String).ToString(); it.Start = (GXDateTime) GXDLMSClient.ChangeType((byte[])item[1], DataType.DateTime); it.WeekName = GXDLMSClient.ChangeType((byte[]) item[2], DataType.String).ToString(); items.Add(it); } SeasonProfileActive = items.ToArray(); } } else if (index == 4) { WeekProfileTableActive = null; if (value != null) { List<GXDLMSWeekProfile> items = new List<GXDLMSWeekProfile>(); foreach (object[] item in (object[])value) { GXDLMSWeekProfile it = new GXDLMSWeekProfile(); it.Name = GXDLMSClient.ChangeType((byte[])item[0], DataType.String).ToString(); it.Monday = Convert.ToInt32(item[1]); it.Tuesday = Convert.ToInt32(item[2]); it.Wednesday= Convert.ToInt32(item[3]); it.Thursday = Convert.ToInt32(item[4]); it.Friday = Convert.ToInt32(item[5]); it.Saturday = Convert.ToInt32(item[6]); it.Sunday = Convert.ToInt32(item[7]); items.Add(it); } WeekProfileTableActive = items.ToArray(); } } else if (index == 5) { DayProfileTableActive = null; if (value != null) { List<GXDLMSDayProfile> items = new List<GXDLMSDayProfile>(); foreach (object[] item in (object[])value) { GXDLMSDayProfile it = new GXDLMSDayProfile(); it.DayId = Convert.ToInt32(item[0]); List<GXDLMSDayProfileAction> actions = new List<GXDLMSDayProfileAction>(); foreach (object[] it2 in (object[])item[1]) { GXDLMSDayProfileAction ac = new GXDLMSDayProfileAction(); ac.StartTime = (GXDateTime)GXDLMSClient.ChangeType((byte[])it2[0], DataType.Time); ac.ScriptLogicalName = GXDLMSClient.ChangeType((byte[])it2[1], DataType.String).ToString(); ac.ScriptSelector = Convert.ToUInt16(it2[2]); actions.Add(ac); } it.DaySchedules = actions.ToArray(); items.Add(it); } DayProfileTableActive = items.ToArray(); } } else if (index == 6) { if (value is byte[]) { CalendarNamePassive = GXDLMSClient.ChangeType((byte[])value, DataType.String).ToString(); } else { CalendarNamePassive = Convert.ToString(value); } } else if (index == 7) { SeasonProfilePassive = null; if (value != null) { List<GXDLMSSeasonProfile> items = new List<GXDLMSSeasonProfile>(); foreach (object[] item in (object[])value) { GXDLMSSeasonProfile it = new GXDLMSSeasonProfile(); it.Name = GXDLMSClient.ChangeType((byte[])item[0], DataType.String).ToString(); it.Start = (GXDateTime)GXDLMSClient.ChangeType((byte[])item[1], DataType.DateTime); it.WeekName = GXDLMSClient.ChangeType((byte[])item[2], DataType.String).ToString(); items.Add(it); } SeasonProfilePassive = items.ToArray(); } } else if (index == 8) { WeekProfileTablePassive = null; if (value != null) { List<GXDLMSWeekProfile> items = new List<GXDLMSWeekProfile>(); foreach (object[] item in (object[])value) { GXDLMSWeekProfile it = new GXDLMSWeekProfile(); it.Name = GXDLMSClient.ChangeType((byte[])item[0], DataType.String).ToString(); it.Monday = Convert.ToInt32(item[1]); it.Tuesday = Convert.ToInt32(item[2]); it.Wednesday = Convert.ToInt32(item[3]); it.Thursday = Convert.ToInt32(item[4]); it.Friday = Convert.ToInt32(item[5]); it.Saturday = Convert.ToInt32(item[6]); it.Sunday = Convert.ToInt32(item[7]); items.Add(it); } WeekProfileTablePassive = items.ToArray(); } } else if (index == 9) { DayProfileTablePassive = null; if (value != null) { List<GXDLMSDayProfile> items = new List<GXDLMSDayProfile>(); foreach (object[] item in (object[])value) { GXDLMSDayProfile it = new GXDLMSDayProfile(); it.DayId = Convert.ToInt32(item[0]); List<GXDLMSDayProfileAction> actions = new List<GXDLMSDayProfileAction>(); foreach (object[] it2 in (object[])item[1]) { GXDLMSDayProfileAction ac = new GXDLMSDayProfileAction(); ac.StartTime = (GXDateTime)GXDLMSClient.ChangeType((byte[])it2[0], DataType.Time); ac.ScriptLogicalName = GXDLMSClient.ChangeType((byte[])it2[1], DataType.String).ToString(); ac.ScriptSelector = Convert.ToUInt16(it2[2]); actions.Add(ac); } it.DaySchedules = actions.ToArray(); items.Add(it); } DayProfileTablePassive = items.ToArray(); } } else if (index == 10) { if (value is byte[]) { Time = (GXDateTime)GXDLMSClient.ChangeType((byte[])value, DataType.DateTime); } else { Time = new GXDateTime(Convert.ToDateTime(value)); } } else { throw new ArgumentException("SetValue failed. Invalid attribute index."); } }
void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e) { if (e.Index == 1) { if (e.Value is string) { LogicalName = e.Value.ToString(); } else if (e.Value != null) { LogicalName = GXDLMSClient.ChangeType((byte[])e.Value, DataType.OctetString).ToString(); } } else if (e.Index == 2) { if (e.Value == null) { Time = new GXDateTime(DateTime.MinValue); } else { if (e.Value is byte[]) { e.Value = GXDLMSClient.ChangeType((byte[])e.Value, DataType.DateTime); } if (e.Value is GXDateTime) { Time = (GXDateTime)e.Value; } else if (e.Value is String) { Time = DateTime.ParseExact((String)e.Value, CultureInfo.CurrentUICulture.DateTimeFormat.ShortDatePattern + " " + CultureInfo.CurrentUICulture.DateTimeFormat.LongTimePattern, CultureInfo.CurrentUICulture); } else { Time = Convert.ToDateTime(e.Value); } } } else if (e.Index == 3) { TimeZone = Convert.ToInt32(e.Value); } else if (e.Index == 4) { Status = (ClockStatus)Convert.ToInt32(e.Value); } else if (e.Index == 5) { if (e.Value == null) { Begin = new GXDateTime(DateTime.MinValue); } else { if (e.Value is byte[]) { e.Value = GXDLMSClient.ChangeType((byte[])e.Value, DataType.DateTime); } Begin = (GXDateTime)e.Value; } } else if (e.Index == 6) { if (e.Value == null) { End = new GXDateTime(DateTime.MinValue); } else { if (e.Value is byte[]) { e.Value = GXDLMSClient.ChangeType((byte[])e.Value, DataType.DateTime); } End = (GXDateTime)e.Value; } } else if (e.Index == 7) { Deviation = Convert.ToInt32(e.Value); } else if (e.Index == 8) { Enabled = Convert.ToBoolean(e.Value); } else if (e.Index == 9) { ClockBase = (ClockBase)Convert.ToInt32(e.Value); } else { e.Error = ErrorCode.ReadWriteDenied; } }
/// <summary> /// Constructor. /// </summary> /// <param name="forSettings">DLMS settings.</param> /// <param name="forCommand">Command.</param> /// <param name="forCommandType">Command type.</param> /// <param name="forAttributeDescriptor">Attribute descriptor,</param> /// <param name="forData">Data,</param> public GXDLMSLNParameters(GXDLMSSettings forSettings, Command forCommand, byte forCommandType, GXByteBuffer forAttributeDescriptor, GXByteBuffer forData, byte forStatus) { settings = forSettings; blockIndex = settings.BlockIndex; command = forCommand; requestType = forCommandType; attributeDescriptor = forAttributeDescriptor; data = forData; time = null; status = forStatus; multipleBlocks = forSettings.Count != 0; lastBlock = forSettings.Count == forSettings.Index; }
void IGXDLMSBase.SetValue(int index, object value) { if (index == 1) { if (value is string) { LogicalName = value.ToString(); } else { LogicalName = GXDLMSClient.ChangeType((byte[])value, DataType.OctetString).ToString(); } } else if (index == 2) { if (CaptureObjects == null || CaptureObjects.Count == 0) { throw new Exception("Read capture objects first."); } if (value != null && (value as object[]).Length != 0) { DateTime lastDate = DateTime.MinValue; foreach (object[] row in (value as object[])) { if ((row as object[]).Length != CaptureObjects.Count) { throw new Exception("Number of columns do not match."); } for (int pos = 0; pos != row.Length; ++pos) { DataType type = CaptureObjects[pos].GetUIDataType(CaptureObjects[pos].SelectedAttributeIndex); if (row[pos] is byte[]) { if (type != DataType.None && row[pos] is byte[]) { row[pos] = GXDLMSClient.ChangeType(row[pos] as byte[], type); if (row[pos] is GXDateTime) { GXDateTime dt = (GXDateTime)row[pos]; lastDate = dt.Value; } } } else if (type == DataType.DateTime && row[pos] == null && CapturePeriod != 0) { if (lastDate == DateTime.MinValue && Buffer.Count != 0) { lastDate = ((GXDateTime)Buffer[Buffer.Count - 1].GetValue(pos)).Value; } if (lastDate != DateTime.MinValue) { lastDate = lastDate.AddSeconds(CapturePeriod); row[pos] = new GXDateTime(lastDate); } } if (CaptureObjects[pos] is GXDLMSRegister && CaptureObjects[pos].SelectedAttributeIndex == 2) { double scaler = (CaptureObjects[pos] as GXDLMSRegister).Scaler; if (scaler != 1) { try { row[pos] = Convert.ToDouble(row[pos]) * scaler; } catch { //Skip error } } } } Buffer.Add(row); } } } else if (index == 3) { Buffer.Clear(); CaptureObjects.Clear(); foreach (object it in value as object[]) { object[] tmp = it as object[]; if (tmp.Length != 4) { throw new GXDLMSException("Invalid structure format."); } ObjectType type = (ObjectType)Convert.ToInt16(tmp[0]); string ln = GXDLMSObject.toLogicalName((byte[]) tmp[1]); int attributeIndex = Convert.ToInt16(tmp[2]); int dataIndex = Convert.ToInt16(tmp[3]); GXDLMSObject obj = null; if (Parent != null) { obj = Parent.FindByLN(type, ln); } if (obj == null) { obj = GXDLMSClient.CreateDLMSObject((int)type, null, 0, ln, 0, attributeIndex, dataIndex); } obj.SelectedAttributeIndex = attributeIndex; obj.SelectedDataIndex = dataIndex; CaptureObjects.Add(obj); } } else if (index == 4) { CapturePeriod = Convert.ToInt32(value); } else if (index == 5) { SortMethod = (SortMethod)Convert.ToInt32(value); } else if (index == 6) { if (value != null) { object[] tmp = value as object[]; if (tmp.Length != 4) { throw new GXDLMSException("Invalid structure format."); } ObjectType type = (ObjectType)Convert.ToInt16(tmp[0]); string ln = GXDLMSObject.toLogicalName((byte[])tmp[1]); int attributeIndex = Convert.ToInt16(tmp[2]); int dataIndex = Convert.ToInt16(tmp[3]); SortObject = CaptureObjects.FindByLN(type, ln); } else { SortObject = null; } } else if (index == 7) { EntriesInUse = Convert.ToInt32(value); } else if (index == 8) { ProfileEntries = Convert.ToInt32(value); } else { throw new ArgumentException("SetValue failed. Invalid attribute index."); } }
/// <summary> /// Constructor. /// </summary> public GXDLMSDayProfileAction(GXDateTime startTime, string scriptLogicalName, UInt16 scriptSelector) { StartTime = startTime; ScriptLogicalName = scriptLogicalName; ScriptSelector = scriptSelector; }
/// <summary> /// Constructor. /// </summary> public GXTime(GXDateTime value) : base(value) { Skip = value.Skip | DateTimeSkips.Year | DateTimeSkips.Month | DateTimeSkips.Day | DateTimeSkips.DayOfWeek; Extra = value.Extra; }
uint IConvertible.ToUInt32(IFormatProvider provider) { return((uint)GXDateTime.ToUnixTime(this.Value.DateTime)); }
/// <summary> /// Constructor. /// </summary> public GXDLMSClock() : base(ObjectType.Clock, "0.0.1.0.0.255", 0) { Time = new GXDateTime(DateTime.MinValue); }
ulong IConvertible.ToUInt64(IFormatProvider provider) { return((ulong)GXDateTime.ToUnixTime(this.Value.DateTime)); }
void IGXDLMSBase.SetValue(int index, object value) { if (index == 1) { if (value is string) { LogicalName = value.ToString(); } else { LogicalName = GXDLMSClient.ChangeType((byte[])value, DataType.OctetString).ToString(); } } else if (index == 2) { if (Scaler != 1) { try { CurrentAverageValue = Convert.ToDouble(value) * Scaler; } catch (Exception) { //Sometimes scaler is set for wrong Object type. CurrentAverageValue = value; } } else { CurrentAverageValue = value; } } else if (index == 3) { if (Scaler != 1) { try { LastAverageValue = Convert.ToDouble(value) * Scaler; } catch (Exception) { //Sometimes scaler is set for wrong Object type. LastAverageValue = value; } } else { LastAverageValue = value; } } else if (index == 4) { if (value == null) { Scaler = 1; Unit = Unit.None; } else { object[] arr = (object[])value; if (arr.Length != 2) { throw new Exception("setValue failed. Invalid scaler unit value."); } m_Scaler = Convert.ToInt32(arr[0]); Unit = (Unit)Convert.ToInt32(arr[1]); } } else if (index == 5) { Status = Convert.ToInt32(value); } else if (index == 6) { if (value == null) { CaptureTime = new GXDateTime(DateTime.MinValue); } else { if (value is byte[]) { value = GXDLMSClient.ChangeType((byte[])value, DataType.DateTime); } CaptureTime = (GXDateTime)value; } } else if (index == 7) { if (value == null) { StartTimeCurrent = new GXDateTime(DateTime.MinValue); } else { if (value is byte[]) { value = GXDLMSClient.ChangeType((byte[])value, DataType.DateTime); } StartTimeCurrent = (GXDateTime)value; } } else if (index == 8) { Period = Convert.ToUInt32(value); } else if (index == 9) { NumberOfPeriods = Convert.ToUInt16(value); } else { throw new ArgumentException("SetValue failed. Invalid attribute index."); } }
/// <summary> /// Get next schedule dates. /// </summary> /// <param name="count"></param> /// <returns></returns> public static DateTime[] GetNextScheduledDates(DateTime start, GXDateTime value, int count) { DateTime tmp; List <DateTime> list = new List <DateTime>(); for (int pos = 0; pos != count; ++pos) { int seconds = GetSeconds(start, value); if ((value.Extra & DateTimeExtraInfo.LastDay) != 0) { int y = 0; int m = start.Month + pos; if (m > 12) { y = m / 12; m %= 12; } tmp = new DateTime(start.Year + y, m, DateTime.DaysInMonth(start.Year, m), value.Value.Hour, value.Value.Minute, value.Value.Second); if ((value.Skip & DateTimeSkips.DayOfWeek) == 0) { int d = value.DayOfWeek; if (value.DayOfWeek == 7) { d = 0; } tmp = tmp.AddDays(-((int)tmp.DayOfWeek - d)); } list.Add(tmp); } else if ((value.Skip & DateTimeSkips.Second) != 0) { start = start.AddSeconds(1); list.Add(start); } else if ((value.Skip & DateTimeSkips.Minute) != 0) { if (pos != 0 && seconds == 0) { start = start.AddMinutes(1); } else { if (seconds < 0) { start = start.AddMinutes(1); } start = start.AddSeconds(seconds); } list.Add(start); } else if ((value.Skip & DateTimeSkips.Hour) != 0) { if (pos != 0 && seconds == 0) { start = start.AddHours(1); } else { if (seconds < 0) { start = start.AddHours(1); } start = start.AddSeconds(seconds); } list.Add(start); } else if ((value.Skip & DateTimeSkips.Day) != 0) { if (pos != 0 && seconds == 0) { start = start.AddDays(1); } else { if (seconds < 0) { start = start.AddDays(1); } start = start.AddSeconds(seconds); } list.Add(start); } else if ((value.Skip & DateTimeSkips.Month) != 0) { if (pos != 0 && seconds == 0) { start = start.AddMonths(1); } else { if (seconds < 0) { start = start.AddMonths(1); } start = start.AddSeconds(seconds); } list.Add(start); } else if ((value.Skip & DateTimeSkips.Year) != 0) { if (pos != 0 && seconds == 0) { start = start.AddYears(1); } else { if (seconds < 0) { start = start.AddYears(1); } start = start.AddSeconds(seconds); } list.Add(start); } else { start = start.Add(value - start); list.Add(start); } } return(list.ToArray()); }
/// <summary> /// Read rows by range. /// </summary> /// <remarks> /// Use this method to read Profile Generic table between dates. /// </remarks> /// <param name="name">object name.</param> /// <param name="ln">The logical name of the first column.</param> /// <param name="objectType">The ObjectType of the first column.</param> /// <param name="version">The version of the first column.</param> /// <param name="start">Start time.</param> /// <param name="end">End time.</param> /// <returns></returns> public byte[] ReadRowsByRange(object name, string ln, ObjectType objectType, int version, DateTime start, DateTime end) { GXDateTime s = new GXDateTime(start.ToUniversalTime()); if (start == DateTime.MinValue || start == DateTime.MaxValue) { s.Value = start; } s.Skip = DateTimeSkips.Ms; GXDateTime e = new GXDateTime(end.ToUniversalTime()); if (end == DateTime.MinValue || end == DateTime.MaxValue) { e.Value = end; } e.Skip = DateTimeSkips.Ms; m_Base.ClearProgress(); List<byte> buff = new List<byte>(); buff.Add(0x01); //Add AccessSelector buff.Add((byte)DataType.Structure); //Add enum tag. buff.Add(0x04); //Add item count buff.Add(0x02); //Add enum tag. buff.Add(0x04); //Add item count GXCommon.SetData(buff, DataType.UInt16, (ushort)8);// Add class_id GXCommon.SetData(buff, DataType.OctetString, ln);// Add parameter Logical name GXCommon.SetData(buff, DataType.Int8, 2);// Add attribute index. GXCommon.SetData(buff, DataType.UInt16, version);// Add version GXCommon.SetData(buff, DataType.DateTime, s);// Add start time. GXCommon.SetData(buff, DataType.DateTime, e);// Add end time. //Add array of read columns. Read All... buff.Add(0x01); //Add item count buff.Add(0x00); //Add item count return m_Base.GenerateMessage(name, buff.ToArray(), ObjectType.ProfileGeneric, 2, this.UseLogicalNameReferencing ? Command.GetRequest : Command.ReadRequest)[0]; }
void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e) { if (e.Index == 1) { if (e.Value is string) { LogicalName = e.Value.ToString(); } else { LogicalName = GXDLMSClient.ChangeType((byte[])e.Value, DataType.OctetString).ToString(); } } else if (e.Index == 2) { if (e.Value is byte[]) { CalendarNameActive = GXDLMSClient.ChangeType((byte[])e.Value, DataType.String).ToString(); } else { CalendarNameActive = Convert.ToString(e.Value); } } else if (e.Index == 3) { SeasonProfileActive = null; if (e.Value != null) { List<GXDLMSSeasonProfile> items = new List<GXDLMSSeasonProfile>(); foreach (object[] item in (object[])e.Value) { GXDLMSSeasonProfile it = new GXDLMSSeasonProfile(); it.Name = GXDLMSClient.ChangeType((byte[])item[0], DataType.String).ToString(); it.Start = (GXDateTime)GXDLMSClient.ChangeType((byte[])item[1], DataType.DateTime); it.WeekName = GXDLMSClient.ChangeType((byte[])item[2], DataType.String).ToString(); items.Add(it); } SeasonProfileActive = items.ToArray(); } } else if (e.Index == 4) { WeekProfileTableActive = null; if (e.Value != null) { List<GXDLMSWeekProfile> items = new List<GXDLMSWeekProfile>(); foreach (object[] item in (object[])e.Value) { GXDLMSWeekProfile it = new GXDLMSWeekProfile(); it.Name = GXDLMSClient.ChangeType((byte[])item[0], DataType.String).ToString(); it.Monday = Convert.ToInt32(item[1]); it.Tuesday = Convert.ToInt32(item[2]); it.Wednesday = Convert.ToInt32(item[3]); it.Thursday = Convert.ToInt32(item[4]); it.Friday = Convert.ToInt32(item[5]); it.Saturday = Convert.ToInt32(item[6]); it.Sunday = Convert.ToInt32(item[7]); items.Add(it); } WeekProfileTableActive = items.ToArray(); } } else if (e.Index == 5) { DayProfileTableActive = null; if (e.Value != null) { List<GXDLMSDayProfile> items = new List<GXDLMSDayProfile>(); foreach (object[] item in (object[])e.Value) { GXDLMSDayProfile it = new GXDLMSDayProfile(); it.DayId = Convert.ToInt32(item[0]); List<GXDLMSDayProfileAction> actions = new List<GXDLMSDayProfileAction>(); foreach (object[] it2 in (object[])item[1]) { GXDLMSDayProfileAction ac = new GXDLMSDayProfileAction(); if (it2[0] is GXDateTime) { ac.StartTime = (GXDateTime)it2[0]; } else { ac.StartTime = (GXDateTime)GXDLMSClient.ChangeType((byte[])it2[0], DataType.Time); } ac.ScriptLogicalName = GXDLMSClient.ChangeType((byte[])it2[1], DataType.OctetString).ToString(); ac.ScriptSelector = Convert.ToUInt16(it2[2]); actions.Add(ac); } it.DaySchedules = actions.ToArray(); items.Add(it); } DayProfileTableActive = items.ToArray(); } } else if (e.Index == 6) { if (e.Value is byte[]) { CalendarNamePassive = GXDLMSClient.ChangeType((byte[])e.Value, DataType.String).ToString(); } else { CalendarNamePassive = Convert.ToString(e.Value); } } else if (e.Index == 7) { SeasonProfilePassive = null; if (e.Value != null) { List<GXDLMSSeasonProfile> items = new List<GXDLMSSeasonProfile>(); foreach (object[] item in (object[])e.Value) { GXDLMSSeasonProfile it = new GXDLMSSeasonProfile(); it.Name = GXDLMSClient.ChangeType((byte[])item[0], DataType.String).ToString(); it.Start = (GXDateTime)GXDLMSClient.ChangeType((byte[])item[1], DataType.DateTime); byte[] weekName = (byte[])item[2]; //If week name is ignored. if (weekName != null && weekName.Length == 1 && weekName[0] == 0xFF) { it.WeekName = ""; } else { it.WeekName = GXDLMSClient.ChangeType((byte[])item[2], DataType.String).ToString(); } items.Add(it); } SeasonProfilePassive = items.ToArray(); } } else if (e.Index == 8) { WeekProfileTablePassive = null; if (e.Value != null) { List<GXDLMSWeekProfile> items = new List<GXDLMSWeekProfile>(); foreach (object[] item in (object[])e.Value) { GXDLMSWeekProfile it = new GXDLMSWeekProfile(); it.Name = GXDLMSClient.ChangeType((byte[])item[0], DataType.String).ToString(); it.Monday = Convert.ToInt32(item[1]); it.Tuesday = Convert.ToInt32(item[2]); it.Wednesday = Convert.ToInt32(item[3]); it.Thursday = Convert.ToInt32(item[4]); it.Friday = Convert.ToInt32(item[5]); it.Saturday = Convert.ToInt32(item[6]); it.Sunday = Convert.ToInt32(item[7]); items.Add(it); } WeekProfileTablePassive = items.ToArray(); } } else if (e.Index == 9) { DayProfileTablePassive = null; if (e.Value != null) { List<GXDLMSDayProfile> items = new List<GXDLMSDayProfile>(); foreach (object[] item in (object[])e.Value) { GXDLMSDayProfile it = new GXDLMSDayProfile(); it.DayId = Convert.ToInt32(item[0]); List<GXDLMSDayProfileAction> actions = new List<GXDLMSDayProfileAction>(); foreach (object[] it2 in (object[])item[1]) { GXDLMSDayProfileAction ac = new GXDLMSDayProfileAction(); if (it2[0] is GXDateTime) { ac.StartTime = (GXDateTime)it2[0]; } else { ac.StartTime = (GXDateTime)GXDLMSClient.ChangeType((byte[])it2[0], DataType.Time); } ac.ScriptLogicalName = GXDLMSClient.ChangeType((byte[])it2[1], DataType.OctetString).ToString(); ac.ScriptSelector = Convert.ToUInt16(it2[2]); actions.Add(ac); } it.DaySchedules = actions.ToArray(); items.Add(it); } DayProfileTablePassive = items.ToArray(); } } else if (e.Index == 10) { if (e.Value is byte[]) { Time = (GXDateTime)GXDLMSClient.ChangeType((byte[])e.Value, DataType.DateTime); } else { Time = new GXDateTime(Convert.ToDateTime(e.Value)); } } else { e.Error = ErrorCode.ReadWriteDenied; } }