BACnet.Examples icon indicating copy to clipboard operation
BACnet.Examples copied to clipboard

Exception schedule object not working as of Weekshedule flow, help needed!

Open sw-ms-pradipbaria opened this issue 6 years ago • 0 comments

Hello @gralin , I am trying to setup exception schedule as per week schedule setup in this example, schedule object get added successfully in virtual device, but defined exception schedule not getting added. Below is the code i have implemented to achieve this.

[Serializable]
    class ExceptionScheduleTimeValue
    {
        public DateTime dt;
        public object Value;
        public ExceptionScheduleTimeValue(DateTime dt, object Value)
        {
            this.dt = dt;
            this.Value = Value;
        }
    }
[Serializable]
    class ExceptionScheduleArray
    {
        public List<ExceptionScheduleTimeValue>[] listOfTimeValues = new List<ExceptionScheduleTimeValue>[1];
        public DateTime period;
        public ExceptionScheduleArray(DateTime fdPeriod, List<ExceptionScheduleTimeValue>[] foExceptionScheduleTimeValue)
        {
            this.listOfTimeValues = foExceptionScheduleTimeValue;
            this.period = fdPeriod;
        }
    }
[Serializable]
    class BacnetWeeklyExceptionSchedule : ASN1.IEncode
    {
        public List<ExceptionScheduleArray>[] loExceptionScheduleArray = new List<ExceptionScheduleArray>[1];
        public void Encode(EncodeBuffer buffer)
        {
            for (int i = 0; i < loExceptionScheduleArray.Length; i++)
            {
                ASN1.encode_opening_tag(buffer, 0);
                List<ExceptionScheduleArray> loArray = loExceptionScheduleArray[i];
                var loExceptionScheduleTimeValue = loArray[i];
                ASN1.bacapp_encode_application_data(buffer, new BacnetValue(BacnetApplicationTags.BACNET_APPLICATION_TAG_DATE, loArray[j].period));

                foreach (var ds in loExceptionScheduleTimeValue.listOfTimeValues)
                {
                    var loTime = ds[0].dt;
                    var loValue = ds[0].Value;

                    ASN1.bacapp_encode_application_data(buffer, new BacnetValue(BacnetApplicationTags.BACNET_APPLICATION_TAG_TIME, loTime));
                    ASN1.bacapp_encode_application_data(buffer, new BacnetValue(loValue));
                }

                ASN1.encode_closing_tag(buffer, 0);
            }
        }
    }

Below is the object creation for exception schedule using structure defined above.


var loBacnetValue = new List<BacnetValue>();
var loNewPropertyValue = new BacnetPropertyValue();

BacnetWeeklyExceptionSchedule loBacnetWeeklyExceptionSchedule = new BacnetWeeklyExceptionSchedule();

DateTime ldDate = DateTime.Now.AddDays(1).AddMinutes(2);

List<ExceptionScheduleTimeValue>[] loExceptionSchedulTimeValue = new List<ExceptionScheduleTimeValue>[1];
loExceptionSchedulTimeValue[0] = new List<ExceptionScheduleTimeValue>();
loExceptionSchedulTimeValue[0].Add(new ExceptionScheduleTimeValue(ldDate, Convert.ToSingle(111)));

BACnetCalendarEntry loBACnetCalendarEntry = new BACnetCalendarEntry();
loBACnetCalendarEntry.Entries = new List<object>();
loBACnetCalendarEntry.Entries.Add(new BacnetValue(BacnetApplicationTags.BACNET_APPLICATION_TAG_DATE, DateTime.Today.AddDays(1)));

loBacnetWeeklyExceptionSchedule.loExceptionScheduleArray = new List<ExceptionScheduleArray>[1];
loBacnetWeeklyExceptionSchedule.loExceptionScheduleArray[0] = new List<ExceptionScheduleArray>();

loBacnetWeeklyExceptionSchedule.loExceptionScheduleArray[0].Add(new ExceptionScheduleArray(ldDate, loExceptionSchedulTimeValue));

loBacnetValue.Add(new BacnetValue(BacnetApplicationTags.BACNET_APPLICATION_TAG_SPECIAL_EVENT, loBacnetWeeklyExceptionSchedule));

loNewPropertyValue.value = loBacnetValue;
loNewPropertyValue.property = new BacnetPropertyReference((uint)BacnetPropertyIds.PROP_EXCEPTION_SCHEDULE, ASN1.BACNET_ARRAY_ALL);
loBacnetPropertyValueList.Add(loNewPropertyValue);

moBacnetClient.CreateObjectRequest(loBacnetAddress, new BacnetObjectId(BacnetObjectTypes.OBJECT_SCHEDULE, (uint)liTopInstanceID), loBacnetPropertyValueList);

I am newbie and looking around your SDK and BACnet implementation, Please help me on this Thanks

sw-ms-pradipbaria avatar Sep 12 '17 11:09 sw-ms-pradipbaria