public static string SerializeValue(BacnetValue value, BacnetApplicationTags type) { switch (type) { case BacnetApplicationTags.BACNET_APPLICATION_TAG_NULL: return(value.ToString()); // Modif FC case BacnetApplicationTags.BACNET_APPLICATION_TAG_REAL: return(((float)value.Value).ToString(CultureInfo.InvariantCulture)); case BacnetApplicationTags.BACNET_APPLICATION_TAG_DOUBLE: return(((double)value.Value).ToString(CultureInfo.InvariantCulture)); case BacnetApplicationTags.BACNET_APPLICATION_TAG_OCTET_STRING: return(Convert.ToBase64String((byte[])value.Value)); case BacnetApplicationTags.BACNET_APPLICATION_TAG_CONTEXT_SPECIFIC_DECODED: { return(value.Value is byte[]? Convert.ToBase64String((byte[])value.Value) : string.Join(";", ((BacnetValue[])value.Value) .Select(v => SerializeValue(v, v.Tag)))); } default: return(value.Value.ToString()); } }
private static string GetNiceName(BacnetApplicationTags DataType) { string name = DataType.ToString(); name = name.Substring(23); name = name.Replace('_', ' '); name = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(name.ToLower()); return(name); }
public BacnetValue(object value) { Value = value; Tag = BacnetApplicationTags.BACNET_APPLICATION_TAG_NULL; //guess at the tag if (value != null) { Tag = TagFromType(value.GetType()); } }
public ScheduleDisplay(ImageList img_List, BacnetClient comm, BacnetAddress adr, BacnetObjectId object_id) { InitializeComponent(); this.comm = comm; this.adr = adr; this.schedule_id = object_id; // Get the Present_Value data Type, used for new value in the schedule // ... replaced if some other values found in the scheduling try { IList <BacnetValue> value; comm.ReadPropertyRequest(adr, object_id, BacnetPropertyIds.PROP_PRESENT_VALUE, out value); if ((value != null) && (value.Count != 0) && (value[0].Tag != BacnetApplicationTags.BACNET_APPLICATION_TAG_NULL)) { ScheduleType = value[0].Tag; } } catch { } for (int i = 1; i < 12; i++) { ScheduleDataType.Items.Add(GetNiceName((BacnetApplicationTags)i)); } ReadEffectivePeriod(); ReadEffectiveWeeklySchedule(); ReadExceptionSchedule(); ReadObjectsPropertiesReferences(); ToolTip t1 = new ToolTip(); t1.AutomaticDelay = 0; t1.SetToolTip(TxtStartDate, "A wrong value set this to Always"); ToolTip t2 = new ToolTip(); t2.AutomaticDelay = 0; t2.SetToolTip(TxtEndDate, "A wrong value set this to Always"); // get the ImageList from MainDialog listReferences.SmallImageList = img_List; ScheduleDataType.Text = GetNiceName(ScheduleType); }
public static string SerializeValue(BacnetValue value, BacnetApplicationTags type) { switch (type) { case BacnetApplicationTags.BACNET_APPLICATION_TAG_NULL: return(value.ToString()); // Modif FC case BacnetApplicationTags.BACNET_APPLICATION_TAG_REAL: return(((float)value.Value).ToString(System.Globalization.CultureInfo.InvariantCulture)); case BacnetApplicationTags.BACNET_APPLICATION_TAG_DOUBLE: return(((double)value.Value).ToString(System.Globalization.CultureInfo.InvariantCulture)); case BacnetApplicationTags.BACNET_APPLICATION_TAG_OCTET_STRING: return(Convert.ToBase64String((byte[])value.Value)); case BacnetApplicationTags.BACNET_APPLICATION_TAG_CONTEXT_SPECIFIC_DECODED: { if (value.Value is byte[]) { return(Convert.ToBase64String((byte[])value.Value)); } else { string ret = ""; BacnetValue[] arr = (BacnetValue[])value.Value; foreach (BacnetValue v in arr) { ret += ";" + SerializeValue(v, v.Tag); } return(ret.Length > 0 ? ret.Substring(1) : ""); } } default: return(value.Value.ToString()); } }
public static BacnetValue DeserializeValue(string value, BacnetApplicationTags type) { switch (type) { case BacnetApplicationTags.BACNET_APPLICATION_TAG_NULL: if (value == "") { return(new BacnetValue(type, null)); // Modif FC } else { return(new BacnetValue(value)); } case BacnetApplicationTags.BACNET_APPLICATION_TAG_BOOLEAN: return(new BacnetValue(type, bool.Parse(value))); case BacnetApplicationTags.BACNET_APPLICATION_TAG_UNSIGNED_INT: return(new BacnetValue(type, uint.Parse(value))); case BacnetApplicationTags.BACNET_APPLICATION_TAG_SIGNED_INT: return(new BacnetValue(type, int.Parse(value))); case BacnetApplicationTags.BACNET_APPLICATION_TAG_REAL: return(new BacnetValue(type, float.Parse(value, System.Globalization.CultureInfo.InvariantCulture))); case BacnetApplicationTags.BACNET_APPLICATION_TAG_DOUBLE: return(new BacnetValue(type, double.Parse(value, System.Globalization.CultureInfo.InvariantCulture))); case BacnetApplicationTags.BACNET_APPLICATION_TAG_OCTET_STRING: try { return(new BacnetValue(type, Convert.FromBase64String(value))); } catch { return(new BacnetValue(type, value)); } case BacnetApplicationTags.BACNET_APPLICATION_TAG_CONTEXT_SPECIFIC_DECODED: try { return(new BacnetValue(type, Convert.FromBase64String(value))); } catch { return(new BacnetValue(type, value)); } case BacnetApplicationTags.BACNET_APPLICATION_TAG_CHARACTER_STRING: return(new BacnetValue(type, value)); case BacnetApplicationTags.BACNET_APPLICATION_TAG_BIT_STRING: return(new BacnetValue(type, BacnetBitString.Parse(value))); case BacnetApplicationTags.BACNET_APPLICATION_TAG_ENUMERATED: return(new BacnetValue(type, uint.Parse(value))); case BacnetApplicationTags.BACNET_APPLICATION_TAG_DATE: return(new BacnetValue(type, DateTime.Parse(value))); case BacnetApplicationTags.BACNET_APPLICATION_TAG_TIME: return(new BacnetValue(type, DateTime.Parse(value))); case BacnetApplicationTags.BACNET_APPLICATION_TAG_OBJECT_ID: return(new BacnetValue(type, BacnetObjectId.Parse(value))); case BacnetApplicationTags.BACNET_APPLICATION_TAG_READ_ACCESS_SPECIFICATION: return(new BacnetValue(type, BacnetReadAccessSpecification.Parse(value))); default: return(new BacnetValue(type, null)); } }
private void ScheduleDataType_SelectedIndexChanged(object sender, EventArgs e) { ScheduleType = (BacnetApplicationTags)(ScheduleDataType.SelectedIndex + 1); }
private void ReadEffectiveWeeklySchedule() { Schedule.BeginUpdate(); Schedule.Nodes.Clear(); byte[] InOutBuffer = null; try { // first gets the PROP_SCHEDULE_DEFAULT IList <BacnetValue> valuedefault; comm.ReadPropertyRequest(adr, schedule_id, BacnetPropertyIds.PROP_SCHEDULE_DEFAULT, out valuedefault); if ((valuedefault != null) && (valuedefault.Count != 0) && (valuedefault[0].Tag != BacnetApplicationTags.BACNET_APPLICATION_TAG_NULL)) { ScheduleType = valuedefault[0].Tag; TxtScheduleDefault.Text = valuedefault[0].Value.ToString(); } if (comm.RawEncodedDecodedPropertyConfirmedRequest(adr, schedule_id, BacnetPropertyIds.PROP_WEEKLY_SCHEDULE, BacnetConfirmedServices.SERVICE_CONFIRMED_READ_PROPERTY, ref InOutBuffer)) { int offset = 0; byte tag_number; uint len_value_type; // Tag 3 offset += ASN1.decode_tag_number(InOutBuffer, offset, out tag_number); if (tag_number != 3) { return; } for (int i = 1; i < 8; i++) { TreeNode tday = null; tday = new TreeNode("[" + (i - 1).ToString() + "] : " + System.Globalization.CultureInfo.InvariantCulture.DateTimeFormat.DayNames[i % 7], 0, 0); Schedule.Nodes.Add(tday); // Tag 0 offset += ASN1.decode_tag_number(InOutBuffer, offset, out tag_number); while (!ASN1.IS_CLOSING_TAG(InOutBuffer[offset])) { BacnetValue value; String s; // Time offset += ASN1.decode_tag_number_and_value(InOutBuffer, offset, out tag_number, out len_value_type); offset += ASN1.bacapp_decode_data(InOutBuffer, offset, InOutBuffer.Length, (BacnetApplicationTags)tag_number, len_value_type, out value); DateTime dt = (DateTime)value.Value; // Value offset += ASN1.decode_tag_number_and_value(InOutBuffer, offset, out tag_number, out len_value_type); offset += ASN1.bacapp_decode_data(InOutBuffer, offset, InOutBuffer.Length, (BacnetApplicationTags)tag_number, len_value_type, out value); if (value.Tag != BacnetApplicationTags.BACNET_APPLICATION_TAG_NULL) { s = dt.ToString("T") + " = " + Property.SerializeValue(value, value.Tag); // Second value is the ... value (Bool, Int, Uint, Float, double or null) ScheduleType = value.Tag; // all type must be the same for a valid schedule (maybe, not sure !), so remember it } else { s = dt.ToString("T") + " = null"; } tday.Nodes.Add(new TreeNode(s, 1, 1)); } offset++; } offset += ASN1.decode_tag_number(InOutBuffer, offset, out tag_number); if (tag_number != 3) { Schedule.Nodes.Clear(); } } } catch { } finally { Schedule.EndUpdate(); Schedule.Sort(); // Time entries are not necesserary sorted, so do it (that's also why days are assign to [0], .. [6]) Schedule.ExpandAll(); Schedule.LabelEdit = true; } }
public BacnetValue(BacnetApplicationTags tag, object value) { Tag = tag; Value = value; }
public BaCSharpTypeAttribute(BacnetApplicationTags BacnetNativeType) { this.BacnetNativeType = BacnetNativeType; }
private void ReadExceptionSchedule() { byte[] InOutBuffer = null; try { if (comm.RawEncodedDecodedPropertyConfirmedRequest(adr, schedule_id, BacnetPropertyIds.PROP_EXCEPTION_SCHEDULE, BacnetConfirmedServices.SERVICE_CONFIRMED_READ_PROPERTY, ref InOutBuffer)) { int offset = 0; byte tag_number; // Tag 3 offset += ASN1.decode_tag_number(InOutBuffer, offset, out tag_number); if (tag_number != 3) { return; } int i = 1; while (!ASN1.IS_CLOSING_TAG(InOutBuffer[offset])) { TreeNode tday = null; var bse = new BACnetSpecialEvent(); offset += bse.ASN1decode(InOutBuffer, offset); tday = new TreeNode(string.Format("[{0}] {1}", i++, bse.period.ToString())); tday.Nodes.Add(new TreeNode(String.Format("priority: {0}", bse.eventPriority), 1, 1)); exceptionSchedules.Nodes.Add(tday); foreach (var tv in bse.Values) { var value = tv.value; var dt = tv.dt; string s; if (value.Tag != BacnetApplicationTags.BACNET_APPLICATION_TAG_NULL) { s = dt.ToString("T") + " = " + Property.SerializeValue(value, value.Tag); // Second value is the ... value (Bool, Int, Uint, Float, double or null) ScheduleType = value.Tag; // all type must be the same for a valid schedule (maybe, not sure !), so remember it } else { s = dt.ToString("T") + " = null"; } tday.Nodes.Add(new TreeNode(s, 1, 1)); } } offset += ASN1.decode_tag_number(InOutBuffer, offset, out tag_number); if (tag_number != 3) { exceptionSchedules.Nodes.Clear(); } exceptionSchedules.ExpandAll(); } } catch { } finally { exceptionSchedules.EndUpdate(); exceptionSchedules.Sort(); // Time entries are not necesserary sorted, so do it (that's also why days are assign to [0], .. [6]) exceptionSchedules.ExpandAll(); exceptionSchedules.LabelEdit = true; } }