Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sw-ms-pradipbaria opened this issue Sep 12, 2017 · 0 comments

Comments

@sw-ms-pradipbaria
Copy link

sw-ms-pradipbaria commented Sep 12, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant