Пример #1
0
        static void Main(string[] args)
        {
            // The First Device with 1 Device Object and 1 AnalogInput
            DeviceObject        Dev1 = new DeviceObject(1234, "Device 1", "The First Device", false);
            AnalogInput <float> Temp = new AnalogInput <float>
                                       (
                0,
                "Temperature",
                "Temperature",
                0,
                BacnetUnitsId.UNITS_DEGREES_CELSIUS
                                       );

            Dev1.AddBacnetObject(Temp);

            Temp.internal_PROP_PRESENT_VALUE = 22.6f;

            // The Second Device with 1 Device Object and also 1 AnalogInput
            DeviceObject        Dev2      = new DeviceObject(5678, "Device 2", "The Second Device", false);
            AnalogInput <float> Windspeed = new AnalogInput <float>
                                            (
                1,
                "Windspeed",
                "Wind speed",
                0,
                BacnetUnitsId.UNITS_KILOMETERS_PER_HOUR
                                            );

            Dev2.AddBacnetObject(Windspeed);

            Windspeed.internal_PROP_PRESENT_VALUE = 0.2f;

            // Force the JIT compiler to make some job before network access
            Dev2.Cli2Native();

            // Start the activity for both device
            BacnetActivity BacAc1 = new BacnetActivity();

            BacAc1.StartActivity(Dev1);

            BacnetActivity BacAc2 = new BacnetActivity();

            BacAc2.StartActivity(Dev2);

            // Some animation !
            for (; ;)
            {
                Thread.Sleep(1000);
                //  a Ramp on an object
                if (Temp.internal_PROP_PRESENT_VALUE < 30)
                {
                    Temp.internal_PROP_PRESENT_VALUE = Temp.internal_PROP_PRESENT_VALUE + 1;
                }
                else
                {
                    Temp.internal_PROP_PRESENT_VALUE = 10f;
                }
            }
        }
Пример #2
0
        /*****************************************************************************************************/
        // Create & Delete Object by C. Gunter
        //  OBJECT_ANALOG_INPUT sample
        void handler_OnCreateObjectRequest(BacnetClient sender, BacnetAddress adr, byte invoke_id, BacnetObjectId object_id, ICollection <BacnetPropertyValue> values, BacnetMaxSegments max_segments)
        {
            // simple not all errortypes!!!!!!!! and for now only Analog inputs
            if (device.FindBacnetObject(object_id) != null)
            {
                sender.ErrorResponse(adr, BacnetConfirmedServices.SERVICE_CONFIRMED_CREATE_OBJECT, invoke_id, BacnetErrorClasses.ERROR_CLASS_OBJECT, BacnetErrorCodes.ERROR_CODE_OBJECT_IDENTIFIER_ALREADY_EXISTS);
                return;
            }

            // some default values
            string        obj_name        = object_id.type.ToString() + object_id.instance.ToString();
            string        obj_description = "Sample for you by C. Günter";
            BacnetUnitsId obj_unit        = BacnetUnitsId.UNITS_NO_UNITS;
            double        obj_value       = 0;

            // normally only needs objid, these properties values are sent or not by the client
            foreach (BacnetPropertyValue value in values)
            {
                switch (value.property.propertyIdentifier)
                {
                case (uint)BacnetPropertyIds.PROP_DESCRIPTION:
                    obj_description = (string)value.value[0].Value;
                    break;

                case (uint)BacnetPropertyIds.PROP_OBJECT_NAME:
                    obj_name = (string)value.value[0].Value;
                    break;

                case (uint)BacnetPropertyIds.PROP_UNITS:
                    obj_unit = (BacnetUnitsId)value.value[0].Value;
                    break;

                case (uint)BacnetPropertyIds.PROP_PRESENT_VALUE:
                    try
                    {
                        obj_value = Convert.ToDouble(value.value[0].Value);     // double is the simplest, quite all values convertible to it
                    }
                    catch { }
                    break;
                }
            }
            //add to device
            switch (object_id.type)
            {
            case BacnetObjectTypes.OBJECT_ANALOG_INPUT:
                AnalogInput <double> newAI = new AnalogInput <double>(object_id, obj_name, obj_description, obj_value, obj_unit);
                device.AddBacnetObject(newAI);
                break;

            /* to be added by yourself according to your project requirement
             */
            default:
                sender.ErrorResponse(adr, BacnetConfirmedServices.SERVICE_CONFIRMED_CREATE_OBJECT, invoke_id, BacnetErrorClasses.ERROR_CLASS_OBJECT, BacnetErrorCodes.ERROR_CODE_UNSUPPORTED_OBJECT_TYPE);
                return;
            }
            //send ack that has been created
            sender.CreateObjectResponse(adr, invoke_id, sender.GetSegmentBuffer(max_segments), object_id);
        }
Пример #3
0
        void InitBacnetDictionary()
        {
            uint deviceId;

            if (UInt32.TryParse(BacnetDeviceId, out deviceId) == false)
            {
                deviceId = 12345; // default value
            }
            device = new DeviceObject(deviceId, "Weather2 to Bacnet ", "Weather2 data", false);

            if ((UserAccessKey != null) && (Latitude != null) && (Longitude != null))
            {
                Temp = new AnalogInput <float>
                       (
                    0,
                    "Temperature",
                    "Temperature",
                    0,
                    BacnetUnitsId.UNITS_DEGREES_CELSIUS
                       );

                // 24h trendlog
                TrendTemp = new TrendLog(0, "Temperature Trend", "Temperature Trend", 6 * 24, BacnetTrendLogValueType.TL_TYPE_SIGN);

                Windspeed = new AnalogInput <float>
                            (
                    1,
                    "Windspeed",
                    "Wind speed",
                    0,
                    BacnetUnitsId.UNITS_KILOMETERS_PER_HOUR
                            );
                Humidity = new AnalogInput <float>
                           (
                    2,
                    "Humidity",
                    "Humidity",
                    0,
                    BacnetUnitsId.UNITS_PERCENT
                           );
                Pressure = new AnalogInput <float>
                           (
                    3,
                    "Pressure",
                    "Pressure",
                    0,
                    BacnetUnitsId.UNITS_HECTOPASCALS
                           );

                DewPoint = new AnalogInput <float>
                           (
                    4,
                    "DewPoint",
                    "Dew Point",
                    0,
                    BacnetUnitsId.UNITS_DEGREES_CELSIUS
                           );

                VaporPressure = new AnalogInput <float>
                                (
                    5,
                    "VaporPressure",
                    "Equilibrium Vapor Pressure",
                    0,
                    BacnetUnitsId.UNITS_HECTOPASCALS
                                );

                Windsdir = new CharacterString
                               (0, "Winddir", "Wind Direction", "Not available", false);

                WeatherDescr = new CharacterString
                                   (1, "WeatherDescr", "Weather Description", "Not available", false);

                SunRise        = new BacnetDateTime(0, "Sunrise", "Sun up time");
                SunSet         = new BacnetDateTime(1, "Sunset", "Sun down time");
                Updatetime     = new BacnetDateTime(2, "Updatetime", "Date & Time of the current values");
                NextUpdatetime = new BacnetDateTime(3, "NextUpdatetime", "Date & Time of the next request");

                device.AddBacnetObject(Temp);
                device.AddBacnetObject(TrendTemp);
                device.AddBacnetObject(Windspeed);
                device.AddBacnetObject(Humidity);
                device.AddBacnetObject(Pressure);
                device.AddBacnetObject(DewPoint);
                device.AddBacnetObject(VaporPressure);
                device.AddBacnetObject(Windsdir);
                device.AddBacnetObject(WeatherDescr);
                device.AddBacnetObject(SunRise);
                device.AddBacnetObject(SunSet);
                device.AddBacnetObject(Updatetime);
                device.AddBacnetObject(NextUpdatetime);
                device.AddBacnetObject(new NotificationClass(0, "Notification", "Notification"));
            }
            else
            {
                device.m_PROP_SYSTEM_STATUS = BacnetDeviceStatus.NON_OPERATIONAL;
            }

            // Force the JIT compiler to make some job before network access
            device.Cli2Native();
            BacnetActivity.StartActivity(device);
        }
Пример #4
0
        /*****************************************************************************************************/
        static void InitDeviceObjects()
        {
            // create the device object with StructuredView acceptation
            device = new DeviceObject(deviceId, "Device test", "A test Device", true);

            // ANALOG_INPUT:0 uint
            // initial value 0
            ana0 = new AnalogInput <double>
                   (
                0,
                "Ana0 Sin double",
                "Ana0 Sin double",
                0,
                BacnetUnitsId.UNITS_AMPERES
                   );
            ana0.m_PROP_HIGH_LIMIT = 50;
            ana0.m_PROP_LOW_LIMIT  = -50;
            ana0.m_PROP_DEADBAND   = 5;
            ana0.Enable_Reporting(true, 0);

            device.AddBacnetObject(ana0);   // don't forget to do this

            // Binary Output
            device.AddBacnetObject(new BinaryOutput(0, "Bin Out", "An output", false));

            // Create A StructuredView
            StructuredView s = new StructuredView(0, "Content", "A View");

            // register it
            device.AddBacnetObject(s);  // don't forget to do this

            BaCSharpObject b;

            // ANALOG_VALUE:0 double with Priority Array
            //
            b = new AnalogValue <double>
                (
                0,
                "Ana0 Double",
                "Ana0 Double",
                5465.23,
                BacnetUnitsId.UNITS_BARS,
                true
                );
            s.AddBacnetObject(b); // Put it in the view

            b.OnWriteNotify += new BaCSharpObject.WriteNotificationCallbackHandler(handler_OnWriteNotify);

            // ANALOG_OUTPUT:1 int with Priority Array on Present Value
            b = new AnalogOutput <int>
                (
                1,
                "Ana1 int",
                "Ana1 int",
                (int)56,
                BacnetUnitsId.UNITS_DEGREES_CELSIUS
                );
            s.AddBacnetObject(b); // Put it in the view

            b.OnWriteNotify += new BaCSharpObject.WriteNotificationCallbackHandler(handler_OnWriteNotify);

            // MULTI_STATE_OUTPUT:4 with 6 states
            MultiStateOutput m = new MultiStateOutput
                                 (
                4,
                "MultiStates",
                "MultiStates",
                1,
                6
                                 );

            for (int i = 1; i < 7; i++)
            {
                m.m_PROP_STATE_TEXT[i - 1] = new BacnetValue("Text Level " + i.ToString());
            }

            s.AddBacnetObject(m); // in the view

            StructuredView s2 = new StructuredView(1, "Complex objects", "Complex objects");

            s.AddBacnetObject(s2);

            // TREND_LOG:0 with int values
            // new TrendLog can be changed by new TrendLogCustom
            trend0 = new TrendLog(0, "Trend signed int", "Trend signed int", 200, BacnetTrendLogValueType.TL_TYPE_SIGN);
            s2.AddBacnetObject(trend0); // in the second level view
            // fill Log with more values than the size
            for (int i = 0; i < 300; i++)
            {
                DateTime current = DateTime.Now.AddSeconds(-300 + i);
                if ((i > 200) && (i < 210))   // simulate some errors in the trend
                {
                    trend0.AddValue(new BacnetError(), current, 0, BacnetTrendLogValueType.TL_TYPE_ERROR);
                }
                else
                {
                    trend0.AddValue((int)(i * Math.Sin((float)i / 0.01)), current, 0);
                }
            }

            trend0.AddValue(new BacnetError(), DateTime.Now, 0, BacnetTrendLogValueType.TL_TYPE_ERROR);

            // BACFILE:0
            // File access right me be allowed to the current user
            // for read and for write if any
            b = new BacnetFile
                (
                0,
                "A file",
                "File description",
                "c:\\RemoteObject.xml",
                false
                );
            s2.AddBacnetObject(b); // in the second level view

            NotificationClass nc = new NotificationClass
                                   (
                0,
                "An alarm sender",
                "Alarm description",
                device.PROP_OBJECT_IDENTIFIER
                                   );

            device.AddBacnetObject(nc);

            // Put two elements into the NC recipient List

            // Valid Day
            BacnetBitString week = new BacnetBitString();

            for (int i = 0; i < 7; i++)
            {
                week.SetBit((byte)i, true);                         // Monday to Sunday
            }
            // transition
            BacnetBitString transition = new BacnetBitString();

            transition.SetBit(0, true); // To OffNormal
            transition.SetBit(1, true); // To Fault
            transition.SetBit(2, true); // To Normal

            DeviceReportingRecipient r = new DeviceReportingRecipient
                                         (
                week,                          // week days
                DateTime.MinValue.AddDays(10), // fromTime
                DateTime.MaxValue,             // toTime
                new BacnetObjectId(BacnetObjectTypes.OBJECT_DEVICE, 4000),
                (uint)4,                       // processid
                true,                          // Ack required
                transition                     // transition
                                         );

            nc.AddReportingRecipient(r);

            r = new DeviceReportingRecipient
                (
                week,
                DateTime.MinValue.AddDays(10),
                DateTime.MaxValue,
                new BacnetAddress(BacnetAddressTypes.IP, 0, new Byte[6] {
                255, 255, 255, 255, 0xBA, 0xC0
            }),
                (uint)4,
                true,
                transition
                );

            nc.AddReportingRecipient(r);

            // Create a Schedule
            Schedule sch = new Schedule(0, "Schedule", "Schedule");

            // MUST be added to the device list before modification
            device.AddBacnetObject(sch);

            // a link to the internal analog output
            sch.AddPropertyReference(new BacnetDeviceObjectPropertyReference
                                     (
                                         new BacnetObjectId(BacnetObjectTypes.OBJECT_ANALOG_OUTPUT, 1),
                                         BacnetPropertyIds.PROP_PRESENT_VALUE)
                                     );
            // a link to analog output through the network : could be on another device than itself
            sch.AddPropertyReference(new BacnetDeviceObjectPropertyReference
                                     (
                                         new BacnetObjectId(BacnetObjectTypes.OBJECT_ANALOG_OUTPUT, 1),
                                         BacnetPropertyIds.PROP_PRESENT_VALUE,
                                         new BacnetObjectId(BacnetObjectTypes.OBJECT_DEVICE, 4000))
                                     );

            sch.PROP_SCHEDULE_DEFAULT = (int)452;

            // Schedule a change today in 60 seconds
            sch.AddSchedule
            (
                DateTime.Now.DayOfWeek == 0 ? 6 : (int)DateTime.Now.DayOfWeek - 1, // Monday=0, Sunday=6
                DateTime.Now.AddSeconds(10), (int)900
            );
            sch.PROP_OUT_OF_SERVICE = false;    // needed after all initialization to start the service

            // One empty Calendar, could be fullfill with yabe

            Calendar cal = new Calendar(0, "Test Calendar", "A Yabe calendar");

            device.AddBacnetObject(cal);
        }