public ReadPropertyMultiple(byte[] apdu) { Created = DateTime.Now; InvokeId = apdu[2]; int len = 4; if (apdu.Length < 7) { throw new Exception("Reject.Missing_required_paramter"); } //Object tag BacNetTag objectIdTag = new BacNetTag(apdu, len, ref len); if (objectIdTag.Class == false) { throw new Exception("Reject.Invalid_tag"); } while (ReadObject(apdu, len, ref len)) { var obj = ObjectList[ObjectList.Count - 1]; if (obj == null) { continue; } ReadProperties(apdu, len, obj.ObjectId, ref len); } }
public byte[] GetBytes() { ArrayList res = new ArrayList(); res.Add((byte)BacNetEnums.BACNET_PDU_TYPE.PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST); res.Add((byte)BacNetEnums.BACNET_UNCONFIRMED_SERVICE.SERVICE_UNCONFIRMED_WHO_IS); if (LowLimit != null && HighLimit != null) { //Low limit BacNetTag lowLimitTag = new BacNetTag { Class = true, Length = (byte)LowLimit.GetLength(), Number = 0 }; res.AddRange(lowLimitTag.GetBytes()); res.AddRange(LowLimit.GetBytes()); //High limit BacNetTag highLimitTag = new BacNetTag { Class = true, Length = (byte)HighLimit.GetLength(), Number = 1 }; res.AddRange(highLimitTag.GetBytes()); res.AddRange(HighLimit.GetBytes()); } return((byte[])res.ToArray(typeof(byte))); }
/// <summary> /// todo: реализовать выбор свойства для отправки /// </summary> /// <returns></returns> public byte[] GetBytes() { ArrayList res = new ArrayList(); res.Add((byte)BacNetEnums.BACNET_PDU_TYPE.PDU_TYPE_COMPLEX_ACK); res.Add(InvokeId); res.Add((byte)BacNetEnums.BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_READ_PROPERTY); //Object ID BacNetTag objectTag = new BacNetTag { Class = true, Length = 4, Number = 0 }; res.AddRange(objectTag.GetBytes()); res.AddRange(Obj.GetObjectBytes()); //Max APDU BacNetTag propertyIdTag = new BacNetTag { Class = true, Length = (byte)Obj.Properties[0].PropertyId.GetLength(), Number = 1 }; res.AddRange(propertyIdTag.GetBytes()); res.AddRange(Obj.Properties[0].PropertyId.GetBytes()); /*if (ArrayIndex != null) * { * BacNetTag arrayIndexTag = new BacNetTag { Class = true, Length = (byte)ArrayIndex.GetLength(), Number = 2 }; * res.AddRange(arrayIndexTag.GetBytes()); * res.AddRange(ArrayIndex.GetBytes()); * }*/ return((byte[])res.ToArray(typeof(byte))); }
private bool ReadObject(byte[] apdu, int startIndex, ref int len) { bool res = false; if (apdu.Length - 1 > startIndex) { try { //Object tag BacNetTag objectIdTag = new BacNetTag(apdu, len, ref len); if (objectIdTag.Class == false) { throw new Exception("Reject.Invalid_tag"); } var objectId = new BacNetObject(apdu, len, ref len); ObjectList.Add(objectId); res = true; } catch { throw new Exception("Reject.Invalid_object_tag"); } } return(res); }
private ArrayList ReadValues(byte[] apdu, int startIndex, ref int len) { var valueList = new ArrayList(); var openingTag = new BacNetTag(apdu, len, ref len); if (openingTag.Length == 6 && openingTag.Number == 4) { BacNetTag metaTag = new BacNetTag(apdu, len, ref len); while (metaTag.Length != 7 || metaTag.LongTag) { object value = ByteConverter.GetAppTagValue(apdu, len, metaTag, ref len); valueList.Add(value); metaTag = new BacNetTag(apdu, len, ref len); } } if (openingTag.Length == 6 && openingTag.Number == 5) { BacNetTag metaTag = new BacNetTag(apdu, len, ref len); while (metaTag.Length != 7 || metaTag.LongTag) { object value = ByteConverter.GetAppTagValue(apdu, len, metaTag, ref len); //valueList.Add(value); metaTag = new BacNetTag(apdu, len, ref len); } } return(valueList); }
private object BuildObjectPropertyReference(byte[] apdu, ref int len) { var objId = new BacNetObject(apdu, len, ref len); var metaTag = new BacNetTag(apdu, len, ref len); var propId = new BacNetUInt(apdu, len, metaTag.Length, ref len); return(new BacNetObjectPropertyRef { ObjectId = objId, PropertyId = propId }); }
public ReadPropertyAck(byte[] apdu) { InvokeId = apdu[1]; int len = 3; //Object tag BacNetTag objectIdTag = new BacNetTag(apdu, len, ref len); if (objectIdTag.Class == false) { throw new Exception("Reject.Invalid_tag"); } Obj = new BacNetObject(apdu, len, ref len); //Property Id BacNetTag propertyIdTag = new BacNetTag(apdu, len, ref len); if (propertyIdTag.Number != 1) { throw new Exception("Reject.Invalid_tag"); } BacNetUInt PropertyId = new BacNetUInt(apdu, len, propertyIdTag.Length, ref len); BacNetTag openingTag = new BacNetTag(apdu, len, ref len); ArrayList ValueList = new ArrayList(); if (openingTag.Length == 6) { BacNetTag metaTag = new BacNetTag(apdu, len, ref len); while (metaTag.Length != 7) { if (metaTag.Class == false) { object value = ByteConverter.GetAppTagValue(apdu, len, metaTag, ref len); ValueList.Add(value); } else { if (metaTag.Length == 6 && PropertyId.Value == (int)BacNetEnums.BACNET_PROPERTY_ID.PROP_WEEKLY_SCHEDULE) { var value = BuildScheduleDay(apdu, ref len); ValueList.Add(value); } if (metaTag.Length == 4 && metaTag.Number == 0 && PropertyId.Value == (int)BacNetEnums.BACNET_PROPERTY_ID.PROP_LIST_OF_OBJECT_PROPERTY_REFERENCES) { var value = BuildObjectPropertyReference(apdu, ref len); ValueList.Add(value); } } metaTag = new BacNetTag(apdu, len, ref len); } } var property = new BacNetProperty { PropertyId = PropertyId, Values = ValueList }; Obj.Properties.Add(property); }
public IAm(byte[] apdu) { int len = 2; /* OBJECT ID - BacNetObject */ BacNetTag deviceTag = new BacNetTag(apdu, len, ref len); if (deviceTag.Number != (int)BacNetEnums.BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_OBJECT_ID) { throw new Exception("Device Id tag is missed."); } deviceObject = new BacNetObject(apdu, len, ref len); if (deviceObject.ObjectType != BacNetEnums.BACNET_OBJECT_TYPE.OBJECT_DEVICE) { throw new Exception("Device object is missed."); } /* MAX APDU - uint */ BacNetTag maxLengthTag = new BacNetTag(apdu, len, ref len); if (maxLengthTag.Number != (int)BacNetEnums.BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_UNSIGNED_INT) { throw new Exception("Max APDU length tag is missed."); } MaxApduLength = new BacNetUInt(apdu, len, maxLengthTag.Length, ref len); /* Segmentation - enum */ BacNetTag segmentationTag = new BacNetTag(apdu, len, ref len); if (segmentationTag.Number != (int)BacNetEnums.BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_ENUMERATED) { throw new Exception("Segmentation APDU tag is missed."); } BacNetEnumeration segmentation = new BacNetEnumeration(apdu, len, segmentationTag.Length, ref len); if (segmentation.Value > (int)BacNetEnums.BACNET_SEGMENTATION.MAX_BACNET_SEGMENTATION) { throw new Exception("Segmentation error."); } BacNetEnums.BACNET_SEGMENTATION tSegmentation; if (BacNetEnums.BACNET_SEGMENTATION.TryParse(segmentation.Value.ToString(), out tSegmentation)) { SegmentationSupported = tSegmentation; } /* Vendor ID - UShort */ BacNetTag vendorTag = new BacNetTag(apdu, len, ref len); if (vendorTag.Number != (int)BacNetEnums.BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_UNSIGNED_INT) { throw new Exception("Vendor Id tag is missed."); } VendorId = new BacNetUInt(apdu, len, vendorTag.Length, ref len); }
public UnconfirmedEventNotification(byte[] apdu) { int len = 2; BacNetTag tag = new BacNetTag(apdu, len, ref len); ProccessId = new BacNetUInt(apdu, len, tag.Length, ref len); tag = new BacNetTag(apdu, len, ref len); Device = new BacNetObject(apdu, len, ref len); tag = new BacNetTag(apdu, len, ref len); Object = new BacNetObject(apdu, len, ref len); tag = new BacNetTag(apdu, len, ref len); if (tag.Length == 6 && tag.Number == 3) { tag = new BacNetTag(apdu, len, ref len); if (tag.Length == 6 && tag.Number == 2) { TimeStamp = new BacNetTimeStamp(apdu, len, ref len); } tag = new BacNetTag(apdu, len, ref len); tag = new BacNetTag(apdu, len, ref len); if (tag.Length != 7 && tag.Number != 3) { throw new Exception("Invalid TimeStamp"); } } tag = new BacNetTag(apdu, len, ref len); NotificationClass = new BacNetUInt(apdu, len, tag.Length, ref len); tag = new BacNetTag(apdu, len, ref len); Priority = new BacNetUInt(apdu, len, tag.Length, ref len); tag = new BacNetTag(apdu, len, ref len); EventType = new BacNetUInt(apdu, len, tag.Length, ref len); tag = new BacNetTag(apdu, len, ref len); Message = new BacNetString(apdu, len, tag.Length, ref len); tag = new BacNetTag(apdu, len, ref len); NotifyType = new BacNetUInt(apdu, len, tag.Length, ref len); tag = new BacNetTag(apdu, len, ref len); AckRequired = new BacNetUInt(apdu, len, tag.Length, ref len); tag = new BacNetTag(apdu, len, ref len); FromState = new BacNetUInt(apdu, len, tag.Length, ref len); tag = new BacNetTag(apdu, len, ref len); ToState = new BacNetUInt(apdu, len, tag.Length, ref len); }
public static object GetAppTagValue(byte[] apdu, int startIndex, BacNetTag metaTag, ref int len) { object res = null; switch (metaTag.Number) { case 1: //UNSIGNED_INT var boolValue = new BacNetBool(metaTag); res = boolValue; break; case 2: //UNSIGNED_INT var uIntValue = new BacNetUInt(apdu, len, metaTag.Length, ref len); res = uIntValue; break; case 3: //SIGNED_INT var intValue = new BacNetInt(apdu, len, metaTag.Length, ref len); res = intValue; break; case 4: //REAL var realValue = new BacNetReal(apdu, len, metaTag.Length, ref len); res = realValue; break; case 5: //DOUBLE var doubleValue = new BacNetDouble(apdu, len, metaTag.Length, ref len); res = doubleValue; break; case 7: //CHARACTER STRING var str = new BacNetString(apdu, len, metaTag.Length, ref len); res = str; break; case 9: //ENUMERATION var enumValue = new BacNetEnumeration(apdu, len, metaTag.Length, ref len); res = enumValue; break; case 11: //TIME var time = new BacNetTime(apdu, len, ref len); res = time; break; case 12: //OBJECT IDENTIFIER var obj = new BacNetObject(apdu, len, ref len); res = obj; break; } return(res); }
public byte[] GetBytes() { ArrayList res = new ArrayList(); res.Add((byte)((byte)BacNetEnums.BACNET_PDU_TYPE.PDU_TYPE_CONFIRMED_SERVICE_REQUEST | (1 << 1))); res.Add((byte)84); res.Add((byte)InvokeId); res.Add((byte)BacNetEnums.BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_SUBSCRIBE_COV); //Process ID var processIdTag = new BacNetTag { Class = true, Length = (byte)ProccessId.GetLength(), Number = 0 }; res.AddRange(processIdTag.GetBytes()); res.AddRange(ProccessId.GetBytes()); //Object ID var objectTag = new BacNetTag { Class = true, Length = 4, Number = 1 }; res.AddRange(objectTag.GetBytes()); res.AddRange(ObjectId.GetObjectBytes()); //Issue Confirmed Notifications var icn = new BacNetBool(); icn.Value = false; var icnTag = new BacNetTag { Class = true, Length = (byte)icn.GetLength(), Number = 2 }; res.AddRange(icnTag.GetBytes()); res.AddRange(icn.GetBytes()); //Lifetime var lifeTime = new BacNetUInt(); lifeTime.Value = 360; var lifeTimeTag = new BacNetTag { Class = true, Length = (byte)lifeTime.GetLength(), Number = 3 }; res.AddRange(lifeTimeTag.GetBytes()); res.AddRange(lifeTime.GetBytes()); return((byte[])res.ToArray(typeof(byte))); }
public byte[] GetBytes() { ArrayList res = new ArrayList(); res.Add((byte)BacNetEnums.BACNET_PDU_TYPE.PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST); res.Add((byte)BacNetEnums.BACNET_UNCONFIRMED_SERVICE.SERVICE_UNCONFIRMED_I_AM); //Object ID BacNetTag deviceTag = new BacNetTag { Class = false, Length = 4, Number = (byte)BacNetEnums.BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_OBJECT_ID }; res.AddRange(deviceTag.GetBytes()); BacNetObject device = new BacNetObject { ObjectType = BacNetEnums.BACNET_OBJECT_TYPE.OBJECT_DEVICE, ObjectId = deviceObject.ObjectId }; res.AddRange(device.GetObjectBytes()); //Max APDU BacNetTag maxApduTag = new BacNetTag { Class = false, Length = (byte)MaxApduLength.GetLength(), Number = (int)BacNetEnums.BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_UNSIGNED_INT }; res.AddRange(maxApduTag.GetBytes()); res.AddRange(MaxApduLength.GetBytes()); //Segmentation BacNetTag segmentationTag = new BacNetTag { Class = false, Length = 1, Number = (int)BacNetEnums.BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_ENUMERATED }; res.AddRange(segmentationTag.GetBytes()); res.Add((byte)SegmentationSupported); //Vendor Id BacNetTag vendorIdTag = new BacNetTag { Class = false, Length = (byte)VendorId.GetLength(), Number = (int)BacNetEnums.BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_UNSIGNED_INT }; res.AddRange(vendorIdTag.GetBytes()); res.AddRange(VendorId.GetBytes()); return((byte[])res.ToArray(typeof(byte))); }
public ErrorAck(byte[] apdu) { if (apdu.Length > 2) { InvokeId = apdu[1]; ServiceChoise = apdu[2]; } int len = 3; //Error class BacNetTag errorClassTag = new BacNetTag(apdu, len, ref len); if (errorClassTag.Class) { throw new Exception("Reject.Invalid_tag"); } BacNetEnumeration errorClass = new BacNetEnumeration(apdu, len, errorClassTag.Length, ref len); if (errorClass.Value > (int)BacNetEnums.BACNET_ERROR_CLASS.MAX_BACNET_ERROR_CLASS) { throw new Exception("Error class error."); } BacNetEnums.BACNET_ERROR_CLASS tErrorClass; if (BacNetEnums.BACNET_ERROR_CLASS.TryParse(errorClass.Value.ToString(), out tErrorClass)) { ErrorClass = tErrorClass; } //Error code BacNetTag errorCodeTag = new BacNetTag(apdu, len, ref len); if (errorCodeTag.Class) { throw new Exception("Reject.Invalid_tag"); } BacNetEnumeration errorCode = new BacNetEnumeration(apdu, len, errorCodeTag.Length, ref len); if (errorCode.Value > (int)BacNetEnums.BACNET_ERROR_CODE.MAX_BACNET_ERROR_CODE) { throw new Exception("Error class error."); } BacNetEnums.BACNET_ERROR_CODE tErrorCode; if (BacNetEnums.BACNET_ERROR_CODE.TryParse(errorCode.Value.ToString(), out tErrorCode)) { ErrorCode = tErrorCode; } }
private static Dictionary <BacNetTime, object> BuildScheduleDay(byte[] apdu, ref int len) { var value = new Dictionary <BacNetTime, object>(); var metaTag = new BacNetTag(apdu, len, ref len); while (metaTag.Length != 7) { var time = ByteConverter.GetAppTagValue(apdu, len, metaTag, ref len) as BacNetTime; metaTag = new BacNetTag(apdu, len, ref len); var timeValue = ByteConverter.GetAppTagValue(apdu, len, metaTag, ref len); if (time != null) { value.Add(time, timeValue); } metaTag = new BacNetTag(apdu, len, ref len); } return(value); }
public byte[] GetBytes() { ArrayList res = new ArrayList(); res.Add((byte)BacNetEnums.BACNET_PDU_TYPE.PDU_TYPE_CONFIRMED_SERVICE_REQUEST); res.Add((byte)84); res.Add(BacNetDevice.Instance.InvokeId); res.Add((byte)BacNetEnums.BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_DELETE_OBJECT); BacNetTag objectTag = new BacNetTag { Class = false, Length = 4, Number = (byte)BacNetEnums.BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_OBJECT_ID }; res.AddRange(objectTag.GetBytes()); res.AddRange(_bacNetObject.GetObjectBytes()); return((byte[])res.ToArray(typeof(byte))); }
public ReadProperty(byte[] apdu) { InvokeId = apdu[2]; int len = 4; if (apdu.Length < 7) { throw new Exception("Reject.Missing_required_paramter"); } //Object tag BacNetTag objectIdTag = new BacNetTag(apdu, len, ref len); if (objectIdTag.Class == false) { throw new Exception("Reject.Invalid_tag"); } ObjectId = new BacNetObject(apdu, len, ref len); //Property Id BacNetTag propertyIdTag = new BacNetTag(apdu, len, ref len); if (propertyIdTag.Number != 1) { throw new Exception("Reject.Invalid_tag"); } PropertyId = new BacNetUInt(apdu, len, propertyIdTag.Length, ref len); if (len < apdu.Length) { BacNetTag arrayIndexTag = new BacNetTag(apdu, len, ref len); if (arrayIndexTag.Number == 2 && len < apdu.Length) { ArrayIndex = new BacNetUInt(apdu, len, arrayIndexTag.Length, ref len); } else { throw new Exception("Reject.InvalidTag"); } } if (len < apdu.Length) { throw new Exception("Reject.TooManyArguments"); } }
public WhoIs(byte[] apdu) { if (apdu.Length < 2) { throw new Exception("Malformed APDU byte array"); } if (apdu.Length == 2) { return; } int len = 2; //Low limit BacNetTag lowLimitTag = new BacNetTag(apdu, len, ref len); LowLimit = new BacNetUInt(apdu, len, lowLimitTag.Length, ref len); //High limit BacNetTag highLimitTag = new BacNetTag(apdu, len, ref len); HighLimit = new BacNetUInt(apdu, len, highLimitTag.Length, ref len); }
private List <BacNetProperty> ReadProperties(byte[] apdu, int startIndex, uint objectId, ref int len) { List <BacNetProperty> res = new List <BacNetProperty>(); var openingTag = new BacNetTag(apdu, len, ref len); if (openingTag.Length == 6 && openingTag.Number == 1) { BacNetTag metaTag = new BacNetTag(apdu, len, ref len); while ((metaTag.Length != 7 || metaTag.LongTag) && metaTag.Number != 1) { var propertyId = new BacNetUInt(apdu, len, metaTag.Length, ref len); BacNetProperty prop = new BacNetProperty { PropertyId = propertyId }; prop.Values = ReadValues(apdu, len, ref len); res.Add(prop); metaTag = new BacNetTag(apdu, len, ref len); } } return(res); }
public byte[] GetBytes() { ArrayList res = new ArrayList(); res.Add((byte)((byte)BacNetEnums.BACNET_PDU_TYPE.PDU_TYPE_CONFIRMED_SERVICE_REQUEST | (1 << 1))); res.Add((byte)84); res.Add((byte)InvokeId); res.Add((byte)BacNetEnums.BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_READ_PROP_MULTIPLE); //Object ID foreach (BacNetObject obj in ObjectList) { BacNetTag objectTag = new BacNetTag { Class = true, Length = 4, Number = 0 }; res.AddRange(objectTag.GetBytes()); res.AddRange(obj.GetObjectBytes()); BacNetTag openingTag = new BacNetTag { Class = true, Length = 6, Number = 1 }; res.AddRange(openingTag.GetBytes()); foreach (BacNetProperty property in obj.Properties) { //Property ID BacNetTag propertyIdTag = new BacNetTag { Class = true, Length = (byte)property.PropertyId.GetLength(), Number = 0 }; res.AddRange(propertyIdTag.GetBytes()); res.AddRange(property.PropertyId.GetBytes()); } BacNetTag closingTag = new BacNetTag { Class = true, Length = 7, Number = 1 }; res.AddRange(closingTag.GetBytes()); } return((byte[])res.ToArray(typeof(byte))); }
public byte[] GetBytes() { ArrayList res = new ArrayList(); res.Add((byte)((byte)BacNetEnums.BACNET_PDU_TYPE.PDU_TYPE_CONFIRMED_SERVICE_REQUEST | (1 << 1))); res.Add((byte)84); res.Add((byte)InvokeId); res.Add((byte)BacNetEnums.BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_READ_PROPERTY); //Object ID BacNetTag objectTag = new BacNetTag { Class = true, Length = 4, Number = 0 }; res.AddRange(objectTag.GetBytes()); res.AddRange(ObjectId.GetObjectBytes()); //Property ID BacNetTag propertyIdTag = new BacNetTag { Class = true, Length = (byte)PropertyId.GetLength(), Number = 1 }; res.AddRange(propertyIdTag.GetBytes()); res.AddRange(PropertyId.GetBytes()); if (ArrayIndex != null) { BacNetTag arrayIndexTag = new BacNetTag { Class = true, Length = (byte)ArrayIndex.GetLength(), Number = 2 }; res.AddRange(arrayIndexTag.GetBytes()); res.AddRange(ArrayIndex.GetBytes()); } return((byte[])res.ToArray(typeof(byte))); }
public UnconfirmedCOVnotification(byte[] apdu) { int len = 2; BacNetTag tag = new BacNetTag(apdu, len, ref len); ProccessId = new BacNetUInt(apdu, len, tag.Length, ref len); tag = new BacNetTag(apdu, len, ref len); Device = new BacNetObject(apdu, len, ref len); tag = new BacNetTag(apdu, len, ref len); Object = new BacNetObject(apdu, len, ref len); tag = new BacNetTag(apdu, len, ref len); TimeRemaining = new BacNetUInt(apdu, len, tag.Length, ref len); tag = new BacNetTag(apdu, len, ref len); tag = new BacNetTag(apdu, len, ref len); BacNetUInt value = new BacNetUInt(apdu, len, tag.Length, ref len); //{ tag = new BacNetTag(apdu, len, ref len); tag = new BacNetTag(apdu, len, ref len); //Это не правильно!!!! /*BacNetReal analogvalue = new BacNetReal(apdu, len, tag.Length, ref len); * * //} * tag = new BacNetTag(apdu, len, ref len); * * tag = new BacNetTag(apdu, len, ref len);*/ }
public byte[] GetBytes() { ArrayList res = new ArrayList(); res.Add((byte)BacNetEnums.BACNET_PDU_TYPE.PDU_TYPE_CONFIRMED_SERVICE_REQUEST); res.Add((byte)3); res.Add((byte)InvokeId); res.Add((byte)BacNetEnums.BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_WRITE_PROPERTY); //Object ID BacNetTag objectTag = new BacNetTag { Class = true, Length = 4, Number = 0 }; res.AddRange(objectTag.GetBytes()); res.AddRange(ObjectId.GetObjectBytes()); //Property ID BacNetTag propertyIdTag = new BacNetTag { Class = true, Length = (byte)PropertyId.GetLength(), Number = 1 }; res.AddRange(propertyIdTag.GetBytes()); res.AddRange(PropertyId.GetBytes()); if (ArrayIndex != null) { BacNetTag arrayIndexTag = new BacNetTag { Class = true, Length = (byte)ArrayIndex.GetLength(), Number = 2 }; res.AddRange(arrayIndexTag.GetBytes()); res.AddRange(ArrayIndex.GetBytes()); } //Opening Tag BacNetTag openingTag = new BacNetTag { Class = true, Length = 6, Number = 3 }; res.AddRange(openingTag.GetBytes()); BacNetTag metaTag = new BacNetTag(); foreach (var value in ValueList) { int type; byte[] valueBytes = ByteConverter.GetPropertyValueBytes(value, out type); if (type != 0) { metaTag = new BacNetTag { Class = false, Length = (byte)valueBytes.Length, Number = (byte)type }; res.AddRange(metaTag.GetBytes()); } res.AddRange(valueBytes); } //Closing Tag BacNetTag closingTag = new BacNetTag { Class = true, Length = 7, Number = 3 }; res.AddRange(closingTag.GetBytes()); BacNetTag priorityTag = new BacNetTag { Class = true, Number = 4, Length = 1 }; res.AddRange(priorityTag.GetBytes()); res.Add((byte)0xA); return((byte[])res.ToArray(typeof(byte))); }
public static byte[] GetPropertyValueBytes(object value, out int type) { var res = new ArrayList(); var boolValue = value as BacNetBool; if (boolValue != null) { type = 1; return(boolValue.GetBytes()); } var uIntValue = value as BacNetUInt; if (uIntValue != null) { type = 2; return(uIntValue.GetBytes()); } var intValue = value as BacNetInt; if (intValue != null) { type = 3; return(intValue.GetBytes()); } var realValue = value as BacNetReal; if (realValue != null) { type = 4; return(realValue.GetBytes()); } var doubleValue = value as BacNetDouble; if (doubleValue != null) { type = 5; return(doubleValue.GetBytes()); } var str = value as BacNetString; if (str != null) { type = 7; return(str.GetBytes()); } var enumValue = value as BacNetEnumeration; if (enumValue != null) { type = 9; return(enumValue.GetBytes()); } var obj = value as BacNetObject; if (obj != null) { type = 12; return(obj.GetObjectBytes()); } var schDayDictionary = value as Dictionary <BacNetTime, object>; if (schDayDictionary != null) { var timeTag = new BacNetTag() { Class = false, Length = 4, Number = 11 }; var schRes = new ArrayList { (byte)0x0E }; foreach (var timeValuePair in schDayDictionary) { schRes.AddRange(timeTag.GetBytes()); schRes.AddRange(timeValuePair.Key.GetBytes()); if (timeValuePair.Value != null) { int localType; byte[] valueBytes = GetPropertyValueBytes(timeValuePair.Value, out localType); var metaTag = new BacNetTag { Class = false, Length = (byte)valueBytes.Length, Number = (byte)localType }; schRes.AddRange(metaTag.GetBytes()); schRes.AddRange(valueBytes); } else { schRes.Add((byte)(0x00)); } } schRes.Add((byte)0x0F); type = 0; return((byte[])schRes.ToArray(typeof(byte))); } var objectPropertyRef = value as BacNetObjectPropertyRef; if (objectPropertyRef != null) { var objectTag = new BacNetTag() { Class = true, Length = 4, Number = 0 }; res.AddRange(objectTag.GetBytes()); res.AddRange(objectPropertyRef.ObjectId.GetObjectBytes()); var propTag = new BacNetTag() { Class = true, Length = (byte)objectPropertyRef.PropertyId.GetLength(), Number = 1 }; res.AddRange(propTag.GetBytes()); res.AddRange(objectPropertyRef.PropertyId.GetBytes()); type = 0; return((byte[])res.ToArray(typeof(byte))); } type = 0;// убрать!!!!!!!! return((byte[])res.ToArray(typeof(byte))); }
public byte[] GetBytes() { ArrayList res = new ArrayList(); res.Add((byte)BacNetEnums.BACNET_PDU_TYPE.PDU_TYPE_CONFIRMED_SERVICE_REQUEST); res.Add((byte)84); res.Add(BacNetDevice.Instance.InvokeId); res.Add((byte)BacNetEnums.BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_CREATE_OBJECT); BacNetTag openingTag = new BacNetTag { Class = true, Length = 6, Number = 0 }; res.AddRange(openingTag.GetBytes()); BacNetTag objectTag = new BacNetTag { Class = true, Length = 4, Number = 1 }; res.AddRange(objectTag.GetBytes()); res.AddRange(NewObject.GetObjectBytes()); BacNetTag closingTag = new BacNetTag { Class = true, Length = 7, Number = 0 }; res.AddRange(closingTag.GetBytes()); objectTag.Class = false; objectTag.Number = 0; openingTag.Number = 1; res.AddRange(openingTag.GetBytes()); openingTag.Number = 2; closingTag.Number = 2; foreach (BacNetProperty property in NewObject.Properties) { BacNetTag propertyIdTag = new BacNetTag { Class = true, Length = (byte)property.PropertyId.GetLength(), Number = 0 }; res.AddRange(propertyIdTag.GetBytes()); res.AddRange(property.PropertyId.GetBytes()); res.AddRange(openingTag.GetBytes()); BacNetTag metaTag = new BacNetTag(); foreach (var value in property.Values) { int type; byte[] valueBytes = ByteConverter.GetPropertyValueBytes(value, out type); metaTag = new BacNetTag { Class = false, Length = (byte)valueBytes.Length, Number = (byte)type, LongTag = true }; res.AddRange(metaTag.GetBytes()); res.AddRange(valueBytes); } res.AddRange(closingTag.GetBytes()); } closingTag.Number = 1; res.AddRange(closingTag.GetBytes()); return((byte[])res.ToArray(typeof(byte))); }