Example #1
0
        /// <summary>
        /// Initialize the AnalogAmplifier.
        /// </summary>
        /// <param name="code">The code.</param>
        /// <param name="gain">The gain.</param>
        /// <param name="offset">The offset.</param>
        public virtual void Initialize(string code, IValue gain, IValue offset)
        {
            this.Logger.Debug(string.Format("Start to initialize a AnalogCoponent. Component code : {0}", code));

            // If gain or offset not define => add default value.
            if(gain == null) gain = new AnalogValue(1);
            if(offset == null) offset = new AnalogValue(0);

            // Add standart parameter for analog control.
            this.InitialParameters.Add(new Parameter{ Key = PARAM_GAIN, Comment="Imupt gain for all analog imput of this componant. This value is static.\nTthis parameter is set to 1 by default.", Value = gain});
            this.InitialParameters.Add(new Parameter { Key = PARAM_OFFSET, Comment = "Imupt offset for all analog imput of this componant. This value is static.\nThis parameter is set to 1 by default.", Value = offset });
            base.Initialize(code);
        }
        /// <summary>
        /// Writes the specified data.
        /// </summary>
        /// <param name="channel">The channel.</param>
        /// <param name="data">The data.</param>
        public void Write(Mcp4822Channel channel, AnalogValue data)
        {
            using (spiConnection.SelectSlave())
            {
                var value = (uint)(data.Relative * 0xFFF);
                if (value > 0xFFF)
                    value = 0xFFF;

                // Set active channel
                spiConnection.Write(channel == Mcp4822Channel.ChannelB);

                // Ignored bit
                spiConnection.Synchronize();

                // Select 1x Gain
                spiConnection.Write(true);

                // Active mode operation
                spiConnection.Write(true);

                // Write 12 bits data (some lower bits are ignored by MCP4802/4812
                spiConnection.Write(value, 12);
            }
        }
Example #3
0
 public void SetMainPres(AnalogValue obj)
 {
     Main_Pressure = obj;
 }
Example #4
0
 public void SetHeatAssist_Timer_SP(AnalogValue obj)
 {
     HeatAssist_Timer_SP = obj;
 }
Example #5
0
 public void SetFT_TT_3(AnalogValue obj)
 {
     FT_TT_3 = obj;
 }
Example #6
0
 public void SetFT_TT_2(AnalogValue obj)
 {
     FT_TT_2 = obj;
 }
Example #7
0
 public void SetFT_TT_1(AnalogValue obj)
 {
     FT_TT_1 = obj;
 }
Example #8
0
 public void SetPreHeat_Temp_SP(AnalogValue obj)
 {
     PreHeat_Temp_SP = obj;
 }
        public ForecastObject CalculateHourlyForecastForDer(List <Data> hourlyDerData, SynchronousMachine der, long sunriseTime, long sunsetTime, AnalogValue modelDataActive, AnalogValue modelDataReactive)
        {
            ForecastObject forecastObj = new ForecastObject();

            forecastObj.DerGID = der.GlobalId;

            //LogHelper.Log(LogTarget.File, LogService.CalculateHourlyForecast, " INFO - CalculateHourlyForecast.cs - Calculate hourly forecast for one der.");

            if (modelDataActive == null)
            {
                //LogHelper.Log(LogTarget.File, LogService.CalculateHourlyForecast, " ERROR - CalculateHourlyForecast.cs - Model data active object is null.");
                return(null);
            }

            foreach (Data derHour in hourlyDerData)
            {
                switch (der.FuelType)
                {
                case FuelType.Sun:
                {
                    //get ders substation so you can get latitude and longitude
                    //need this to calculate sunrise and sunset time for calculation of active power for solar
                    float activePowSolar  = powCalc.GetActivePowerForSolarGenerator((float)derHour.Temperature, (float)derHour.CloudCover, der.NominalP, sunriseTime, sunsetTime);
                    float powIncrease     = 0;
                    float powDecrease     = 0;
                    float powIncreaseTemp = activePowSolar + der.DERFlexibilityP;
                    float powDecreaseTemp = activePowSolar - der.DERFlexibilityP;

                    if (powIncreaseTemp >= der.MaxP)
                    {
                        //LogHelper.Log(LogTarget.File, LogService.CalculateHourlyForecast, " WARNING - CalculateHourlyForecast.cs - Solar panel: "+der.GlobalId+" active power increase value change is higher or equal to max active power. New active power increase value is set to max active power value.");
                        powIncrease = der.MaxP;
                    }
                    else
                    {
                        //LogHelper.Log(LogTarget.File, LogService.CalculateHourlyForecast, " INFO - CalculateHourlyForecast.cs - Solar panel: " + der.GlobalId + " active power increase value change is lower then max active power. New active power increase value is set regularly.");
                        powIncrease = powIncreaseTemp;
                    }

                    if (powDecreaseTemp <= der.MinP)
                    {
                        //LogHelper.Log(LogTarget.File, LogService.CalculateHourlyForecast, " WARNING - CalculateHourlyForecast.cs - Solar panel: " + der.GlobalId + " active power decrease value change is lower or equal to min active power. New active power decrease value is set to min active power value.");
                        powDecrease = der.MinP;
                    }
                    else
                    {
                        //LogHelper.Log(LogTarget.File, LogService.CalculateHourlyForecast, " INFO - CalculateHourlyForecast.cs - Solar panel: " + der.GlobalId + " active power decrease value change is higher then min active power. New active power decrease value is set regularly.");
                        powDecrease = powDecreaseTemp;
                    }

                    forecastObj.HourlyP.Add(new AnalogValue(activePowSolar, derHour.Time, modelDataActive.GlobalId, modelDataActive.SynchronousMachine,
                                                            PowerType.Active, powIncrease, powDecrease));
                }

                break;

                case FuelType.Wind:
                {
                    float activePowWind           = powCalc.GetActivePowerForWindGenerator(der.NominalP, (float)derHour.WindSpeed);
                    float reactivePowWind         = activePowWind * 0.05f;
                    float powIncreaseActive       = 0;
                    float powDecreaseActive       = 0;
                    float powIncreaseActiveTemp   = activePowWind + der.DERFlexibilityP;
                    float powDecreaseActiveTemp   = activePowWind - der.DERFlexibilityP;
                    float powIncreaseReactive     = 0;
                    float powDecreaseReactive     = 0;
                    float powIncreaseReactiveTemp = reactivePowWind + der.DERFlexibilityQ;
                    float powDecreaseReactiveTemp = reactivePowWind - der.DERFlexibilityQ;

                    //Check for active power limit
                    if (powIncreaseActiveTemp >= der.MaxP)
                    {
                        //LogHelper.Log(LogTarget.File, LogService.CalculateHourlyForecast, " WARNING - CalculateHourlyForecast.cs - Wind turbine: " + der.GlobalId + " active power increase value change is higher or equal to max active power. New active power increase value is set to max active power value.");
                        powIncreaseActive = der.MaxP;
                    }
                    else
                    {
                        //LogHelper.Log(LogTarget.File, LogService.CalculateHourlyForecast, " INFO - CalculateHourlyForecast.cs - Wind turbine: " + der.GlobalId + " active power increase value change is lower then max active power. New active power increase value is set regularly.");
                        powIncreaseActive = powIncreaseActiveTemp;
                    }

                    if (powDecreaseActiveTemp <= der.MinP)
                    {
                        //LogHelper.Log(LogTarget.File, LogService.CalculateHourlyForecast, " WARNING - CalculateHourlyForecast.cs - Wind turbine: " + der.GlobalId + " active power decrease value change is lower or equal to min active power. New active power decrease value is set to min active power value.");
                        powDecreaseActive = der.MinP;
                    }
                    else
                    {
                        //LogHelper.Log(LogTarget.File, LogService.CalculateHourlyForecast, " INFO - CalculateHourlyForecast.cs - Wind turbine: " + der.GlobalId + " active power decrease value change is higher then min active power. New active power decrease value is set regularly.");
                        powDecreaseActive = powDecreaseActiveTemp;
                    }

                    //Check for reactive power limit
                    if (powIncreaseReactiveTemp >= der.MaxQ)
                    {
                        //LogHelper.Log(LogTarget.File, LogService.CalculateHourlyForecast, " WARNING - CalculateHourlyForecast.cs - Wind turbine: " + der.GlobalId + " reactive power increase value change is higher or equal to max reactive power. New reactive power increase value is set to max reactive power value.");
                        powIncreaseReactive = der.MaxQ;
                    }
                    else
                    {
                        //LogHelper.Log(LogTarget.File, LogService.CalculateHourlyForecast, " INFO - CalculateHourlyForecast.cs - Wind turbine: " + der.GlobalId + " reactive power increase value change is lower then max reactive power. New reactive power increase value is set regularly.");
                        powIncreaseReactive = powIncreaseReactiveTemp;
                    }

                    if (powDecreaseReactiveTemp <= der.MinQ)
                    {
                        //LogHelper.Log(LogTarget.File, LogService.CalculateHourlyForecast, " WARNING - CalculateHourlyForecast.cs - Wind turbine: " + der.GlobalId + " reactive power decrease value change is lower or equal to min reactive power. New reactive power decrease value is set to min reactive power value.");
                        powDecreaseReactive = der.MinQ;
                    }
                    else
                    {
                        //LogHelper.Log(LogTarget.File, LogService.CalculateHourlyForecast, " INFO - CalculateHourlyForecast.cs - Wind turbine: " + der.GlobalId + " reactive power decrease value change is higher then min reactive power. New reactive power decrease value is set regularly.");
                        powDecreaseReactive = powDecreaseReactiveTemp;
                    }
                    forecastObj.HourlyP.Add(new AnalogValue(activePowWind, derHour.Time, modelDataActive.GlobalId, modelDataActive.SynchronousMachine,
                                                            PowerType.Active, powIncreaseActive, powDecreaseActive));

                    forecastObj.HourlyQ.Add(new AnalogValue(reactivePowWind, derHour.Time, modelDataReactive.GlobalId, modelDataReactive.SynchronousMachine,
                                                            PowerType.Reactive, powIncreaseReactive, powDecreaseReactive));
                }

                break;

                default:
                    break;
                }
            }

            return(forecastObj);
        }
        /// <summary>
        /// Helper function to distribute power when DER is not flexible enough
        /// </summary>
        /// <param name="aValue"></param>
        /// <param name="setpoint"></param>
        /// <param name="smDelta"></param>
        /// <param name="smFlexibility"></param>
        /// <param name="dValue"></param>
        private void CheckDistributedPartsOnPoorFlex(Dictionary <long, float> pDistributionBySM, AnalogValue aValue,
                                                     Setpoint setpoint, float smDelta, float smFlexibility, bool isPositiveD, ref float dValue)
        {
            long smGid = aValue.SynchronousMachine;

            LogHelper.Log(LogTarget.File, LogService.CalculationEngineDistributer, " INFO - CalculationEngineDistributer.cs - Distribute power for NOT flexible enough der: " + smGid);

            if (pDistributionBySM.ContainsKey(smGid))                                   // Da li je vec nesto rasporedjeno na DER?
            {
                float smDeltaPart = smFlexibility - Math.Abs(pDistributionBySM[smGid]); // zahtjeva se vrijednost koja je preko flex, stoga napunimo DER do kraja njegovog flexibility

                if (isPositiveD)                                                        //ubaceno zbog negativnih delti
                {
                    if (dValue >= smDeltaPart)
                    {
                        pDistributionBySM[smGid] += smDeltaPart;
                        dValue       -= smDeltaPart;
                        aValue.Value += smDeltaPart;
                        UpdateAnalogValuesList(aValue, setpoint);
                    }

                    else
                    {
                        pDistributionBySM[smGid] += dValue;
                        aValue.Value             += dValue;
                        UpdateAnalogValuesList(aValue, setpoint);
                        dValue = 0;
                    }
                }
                else
                {
                    if (dValue <= smDeltaPart)
                    {
                        pDistributionBySM[smGid] += smDeltaPart;
                        dValue       -= smDeltaPart;
                        aValue.Value += smDeltaPart;
                        UpdateAnalogValuesList(aValue, setpoint);
                    }
                    else
                    {
                        pDistributionBySM[smGid] += dValue;
                        aValue.Value             += dValue;
                        UpdateAnalogValuesList(aValue, setpoint);
                        dValue = 0;
                    }
                }
            }
            else
            {
                if (isPositiveD) // ubaceno zbog negativnih delti
                {
                    if (dValue >= smFlexibility)
                    {
                        pDistributionBySM.Add(smGid, smFlexibility); // napunjen je do kraja, a ostaka smDelte nas ne zanima
                        dValue       -= smFlexibility;
                        aValue.Value += smFlexibility;
                        UpdateAnalogValuesList(aValue, setpoint);
                    }
                    else
                    {
                        pDistributionBySM.Add(smGid, dValue); // napunjen je do kraja, a ostaka smDelte nas ne zanima
                        aValue.Value += dValue;
                        UpdateAnalogValuesList(aValue, setpoint);
                        dValue = 0;
                    }
                }
                else
                {
                    smFlexibility = smFlexibility * -1;
                    if (dValue <= smFlexibility)
                    {
                        pDistributionBySM.Add(smGid, smFlexibility);
                        dValue       -= smFlexibility;
                        aValue.Value += smFlexibility;
                        UpdateAnalogValuesList(aValue, setpoint);
                    }
                    else
                    {
                        pDistributionBySM.Add(smGid, dValue);
                        aValue.Value += dValue;
                        UpdateAnalogValuesList(aValue, setpoint);
                        dValue = 0;
                    }
                }
            }
        }
 /// <summary>
 /// Helper function to reduce delta step to be not higher than Max, not lower than Min
 /// </summary>
 /// <param name="k"></param>
 /// <param name="availableReserve"></param>
 /// <param name="isDeltaPositive"></param>
 /// <param name="aValue"></param>
 private void ReduceKToProperValue(ref float k, float availableReserve, bool isDeltaPositive, AnalogValue aValue)
 {
     if (isDeltaPositive)
     {
         if (k > availableReserve)
         {
             k = availableReserve;
         }
     }
     else
     {
         if (Math.Abs(k) > availableReserve)
         {
             k = availableReserve * (-1);
         }
     }
 }
        /// <summary>
        /// Helper function to distribute power when DER is flexible enough
        /// </summary>
        /// <param name="aValue"></param>
        /// <param name="setpoint"></param>
        /// <param name="smDelta"></param>
        /// <param name="smFlexibility"></param>
        /// <param name="dValue"></param>
        private void CheckDistributedPartsOnGoodFlex(Dictionary <long, float> pDistributionBySM, AnalogValue aValue,
                                                     Setpoint setpoint, float smDelta, float smFlexibility, bool isPositiveD, ref float dValue)
        {
            long smGid = aValue.SynchronousMachine;

            LogHelper.Log(LogTarget.File, LogService.CalculationEngineDistributer, " INFO - CalculationEngineDistributer.cs - Distribute power for flexible enough der: " + smGid);

            if (pDistributionBySM.ContainsKey(smGid)) // ako se vec nalazi u listi za distr, provjeriti trenutno opterecenje
            {
                if (Math.Abs(pDistributionBySM[smGid] + smDelta) <= smFlexibility)
                {
                    if (isPositiveD) //ubaceno zbog negativnih delti
                    {
                        if (dValue >= smDelta)
                        {
                            pDistributionBySM[smGid] += smDelta;
                            dValue       -= smDelta;
                            aValue.Value += smDelta;
                            UpdateAnalogValuesList(aValue, setpoint);
                        }

                        else
                        {
                            pDistributionBySM[smGid] += dValue;
                            aValue.Value             += dValue;
                            UpdateAnalogValuesList(aValue, setpoint);
                            dValue = 0;
                        }
                    }
                    else
                    {
                        if (dValue <= smDelta)
                        {
                            pDistributionBySM[smGid] += smDelta;
                            dValue       -= smDelta;
                            aValue.Value += smDelta;
                            UpdateAnalogValuesList(aValue, setpoint);
                        }
                        else
                        {
                            pDistributionBySM[smGid] += dValue;
                            aValue.Value             += dValue;
                            UpdateAnalogValuesList(aValue, setpoint);
                            dValue = 0;
                        }
                    }
                }
                else // ne moze se dodati cjelokupna delta
                {
                    float availableOnDER = smFlexibility - Math.Abs(pDistributionBySM[smGid]);

                    if (isPositiveD) //ubaceno zbog negativnih delti
                    {
                        if (dValue >= availableOnDER)
                        {
                            pDistributionBySM[smGid] += availableOnDER;
                            dValue       -= availableOnDER;
                            aValue.Value += availableOnDER;
                            UpdateAnalogValuesList(aValue, setpoint);
                        }
                        else
                        {
                            pDistributionBySM[smGid] += dValue;
                            aValue.Value             += dValue;
                            UpdateAnalogValuesList(aValue, setpoint);
                            dValue = 0;
                        }
                    }
                    else
                    {
                        availableOnDER = availableOnDER * (-1);
                        if (dValue <= availableOnDER)
                        {
                            pDistributionBySM[smGid] += availableOnDER;
                            dValue       -= availableOnDER;
                            aValue.Value += availableOnDER;
                            UpdateAnalogValuesList(aValue, setpoint);
                        }
                        else
                        {
                            pDistributionBySM[smGid] += dValue;
                            aValue.Value             += dValue;
                            UpdateAnalogValuesList(aValue, setpoint);
                            dValue = 0;
                        }
                    }
                }
            }
            else // ako se prvi put pojavljuje ta SM u raspodjeli
            {
                if (isPositiveD) // ubaceno zbog negativnih delti
                {
                    if (dValue >= smDelta)
                    {
                        pDistributionBySM.Add(smGid, smDelta); // napunjen je do kraja, a ostaka smDelte nas ne zanima
                        dValue       -= smDelta;
                        aValue.Value += smDelta;
                        UpdateAnalogValuesList(aValue, setpoint);
                    }
                    else
                    {
                        pDistributionBySM.Add(smGid, dValue); // napunjen je do kraja, a ostaka smDelte nas ne zanima
                        aValue.Value += dValue;
                        UpdateAnalogValuesList(aValue, setpoint);
                        dValue = 0;
                    }
                }
                else
                {
                    if (dValue <= smDelta)
                    {
                        pDistributionBySM.Add(smGid, smDelta);
                        dValue       -= smDelta;
                        aValue.Value += smDelta;
                        UpdateAnalogValuesList(aValue, setpoint);
                    }
                    else
                    {
                        pDistributionBySM.Add(smGid, dValue);
                        aValue.Value += dValue;
                        UpdateAnalogValuesList(aValue, setpoint);
                        dValue = 0;
                    }
                }
            }
        }
 /// <summary>
 /// Writes the specified value to the pin.
 /// </summary>
 /// <param name="value">The value.</param>
 public void Write(AnalogValue value)
 {
     connection.Write(channel, value);
 }
Example #14
0
        public static void Main(string[] args)
        {
            var bmp280 = new Bmp280();

            bmp280.Initialize();

            const ConnectorPin adcClock = ConnectorPin.P1Pin23;
            const ConnectorPin adcMiso  = ConnectorPin.P1Pin21;
            const ConnectorPin adcMosi  = ConnectorPin.P1Pin19;
            const ConnectorPin adcCs    = ConnectorPin.P1Pin24;

            const ConnectorPin pir = ConnectorPin.P1Pin31;
            const ConnectorPin led = ConnectorPin.P1Pin29;

            var driver = new GpioConnectionDriver();

            var adcConnection = new Mcp3008SpiConnection(
                driver.Out(adcClock),
                driver.Out(adcCs),
                driver.In(adcMiso),
                driver.Out(adcMosi));

            var pirPin = driver.In(pir);
            var ledPin = driver.Out(led);

            bool ledState = false;

            ledPin.Write(ledState);

            while (true)
            {
                Thread.Sleep(500);

                // Read the temperature and pressure
                float p = bmp280.ReadPreasure().Result;
                float t = bmp280.ReadTemperature().Result;

                float tempF        = (t * 9 / 5) + 32;
                float pressureInHg = p * .295357F / 1000;

                Console.WriteLine("Pressure: " + pressureInHg + " inHg");
                Console.WriteLine("Temperature: " + tempF + " F");

                // Read the analog inputs
                AnalogValue a0 = adcConnection.Read(Mcp3008Channel.Channel0);
                AnalogValue a1 = adcConnection.Read(Mcp3008Channel.Channel1);
                AnalogValue a2 = adcConnection.Read(Mcp3008Channel.Channel2);

                Console.WriteLine("Value 1: " + a0.Value);
                Console.WriteLine("Value 2: " + a1.Value);
                Console.WriteLine("Value 3: " + a2.Value);

                // Read the pir sensor
                var pirState = pirPin.Read();
                Console.WriteLine("Pir Pin Value: " + pirState.ToString());
                if (pirState && !ledState)
                {
                    ledState = true;
                    ledPin.Write(ledState);
                }
                else if (!pirState && ledState)
                {
                    ledState = false;
                    ledPin.Write(ledState);
                }
            }
        }
Example #15
0
 public void SetManualSetTemp(AnalogValue obj)
 {
     ManualSetTemp = obj;
 }
Example #16
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 = transition.SetBit(0, true); // To OffNormal
            transition = transition.SetBit(1, true); // To Fault
            transition = 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);
        }
Example #17
0
 public void SetPneumaticPres(AnalogValue obj)
 {
     Pneumatic_Pressure = obj;
 }
Example #18
0
 /// <summary>
 /// Writes the specified value to the pin.
 /// </summary>
 /// <param name="value">The value.</param>
 public void Write(AnalogValue value)
 {
     this.connection.Write(this.channel, value);
 }
Example #19
0
        /// <summary>
        /// Initialize the specified name.
        /// </summary>
        /// <param name="code">The code.</param>
        /// <param name="gain">The gain.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="deltaValueToSetOn">The delta value to set on.</param>
        /// <param name="deltaValueToSetOff">The delta value to set off.</param>
        public void Initialize(string code, AnalogValue gain, AnalogValue offset, AnalogValue deltaValueToSetOn, AnalogValue deltaValueToSetOff)
        {
            this.InitialParameters.Add(new Parameter().Initialize(PARAM_D_OFF, new AnalogValue(), EnumParameterDirection.Input, "Delta value to set OFF."));
            this.InitialParameters.Add(new Parameter().Initialize(PARAM_D_ON, new AnalogValue(), EnumParameterDirection.Input, "Delta value to set ON."));
            this.InitialParameters.Add(new Parameter().Initialize(INPUT1, new AnalogValue(), EnumParameterDirection.Input, "Input value 1."));
            this.InitialParameters.Add(new Parameter().Initialize(INPUT2, new AnalogValue(), EnumParameterDirection.Input, "Input value 2."));
            this.InitialParameters.Add(new Parameter().Initialize(OUTPUT1, new AnalogValue(), EnumParameterDirection.Output, "Output value."));

            this.Initialize(code, gain, offset);
        }
Example #20
0
 /// <summary>
 /// Writes the specified value to the pin.
 /// </summary>
 /// <param name="value">The value.</param>
 public void Write(AnalogValue value)
 {
     connection.Write(channel, value);
 }