コード例 #1
0
ファイル: TheDefaultSensor.cs プロジェクト: TRUMPF-IoT/cdeSDK
        protected override void SensorCyclicCalc(long timer)
        {
            base.SensorCyclicCalc(timer);
            if ((timer % PingFreq) != 0)
            {
                return;
            }
            if (IsInCyclic)
            {
                return;
            }
            IsInCyclic = true;
            PingFreq   = (int)TheThing.GetSafePropertyNumber(MyBaseEngine.GetBaseThing(), "CalcAggregation");
            if (PingFreq == 0)
            {
                PingFreq = 30;
            }

            var tVals = MyHistorian?.GetValues();   //TODO: This returns null if the SensorHistorian is in the SQL Server. We need to think about what we do here!

            if (tVals?.Any() == true)
            {
                string tValues = TheThing.GetSafePropertyString(MyBaseThing, "HistoryFields");
                if (tValues.Contains("QValue_Ave"))
                {
                    TheThing.SetSafePropertyNumber(MyBaseThing, "QValue_Ave", tVals.Average(w => w.PB.ContainsKey("QValue") ? TheCommonUtils.CDbl(w.PB["QValue"]) : 0));
                }
                if (tValues.Contains("QValue_Min"))
                {
                    TheThing.SetSafePropertyNumber(MyBaseThing, "QValue_Min", tVals.Min(w => w.PB.ContainsKey("QValue") ? TheCommonUtils.CDbl(w.PB["QValue"]) : 0));
                }
                if (tValues.Contains("QValue_Max"))
                {
                    TheThing.SetSafePropertyNumber(MyBaseThing, "QValue_Max", tVals.Max(w => w.PB.ContainsKey("QValue") ? TheCommonUtils.CDbl(w.PB["QValue"]) : 0));
                }
            }
            IsInCyclic = false;
        }
コード例 #2
0
        public virtual void DoCreateUX(TheFormInfo tMyForm, ThePropertyBag pChartControlBag = null)
        {
            var tQVN = TheThing.GetSafePropertyString(MyBaseThing, "StateSensorValueName");
            //var tQV = TheThing.GetSafePropertyString(MyBaseThing, "StateSensorValue");
            var tQU = TheThing.GetSafePropertyString(MyBaseThing, "StateSensorUnit");

            TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.TileGroup, 12460, 0, 0, null, null, new nmiCtrlTileGroup {
                ParentFld = 12011, TileWidth = 6, TileHeight = 3
            });
            ValueField = TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.SmartLabel, 12461, 0, 0, $"{tQVN}", "QValue", new nmiCtrlSmartLabel {
                ParentFld = 12460, TileWidth = 6, TileFactorY = 2, TileHeight = 3, FontSize = 96
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.SmartLabel, 12462, 0, 0, $"{tQU}", "StateSensorUnit", new nmiCtrlSmartLabel {
                ParentFld = 12460, NoTE = true, TileWidth = 6, TileFactorY = 2, TileHeight = 1, FontSize = 18, HorizontalAlignment = "right", VerticalAlignment = "top"
            });

            var tG = TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.TileGroup, 12000, 0, 0, null, null, new nmiCtrlTileGroup()
            {
                TileWidth = 18
            });

            tG.AddOrUpdatePlatformBag(eWebPlatform.Mobile, new nmiPlatBag {
                MaxTileWidth = 6
            });
            tG.AddOrUpdatePlatformBag(eWebPlatform.HoloLens, new nmiPlatBag {
                MaxTileWidth = 12
            });
            tG.AddOrUpdatePlatformBag(eWebPlatform.TeslaXS, new nmiPlatBag {
                MaxTileWidth = 12
            });

            string pSensorPicSource = TheThing.GetSafePropertyString(MyBaseThing, "StateSensorLogo");

            if (string.IsNullOrEmpty(pSensorPicSource))
            {
                pSensorPicSource = "SENSORS/Images/SensorLogo_156x78.png";
            }
            TheSensorNMI.CreatePerformanceHeader(MyBaseThing, tMyForm, 12010, 12000, pSensorPicSource);

            TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.CollapsibleGroup, 12030, 2, 0, $"Live Chart", null, new nmiCtrlCollapsibleGroup()
            {
                ParentFld = 12000, TileWidth = 6, NoTE = true, Background = "transparent", Foreground = "black", FontSize = 10, IsSmall = true, HorizontalAlignment = "left"
            });                                                                                                                                                                                                                                                                                                               //LabelClassName = "cdeTileGroupHeaderSmall SensorGroupLabel", LabelForeground = "white",
            LiveChartFld = TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.UserControl, 12031, 2, 0, $"{tQVN} Chart", "QValue", new ThePropertyBag()
            {
                "ControlType=Live Chart",
                "ParentFld=12030", "NoTE=true", $"Title={tQVN}",
                "SeriesNames=[{ \"name\":\"Current Temp\", \"lineColor\":\"rgba(0,255,0,0.39)\"}, { \"name\":\"Max Temp\", \"lineColor\":\"rgba(0,0,255,0.64)\"}]", "TileWidth=6", "TileHeight=4", "Speed=500", $"MaxValue={TheThing.GetSafePropertyNumber(MyBaseThing, "StateSensorMaxValue")}", "Delay=0", "Background=rgba(0,0,0,0.01)"
            });


            TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.CollapsibleGroup, 12040, 2, 0, "Distribution Curve", null, new nmiCtrlCollapsibleGroup()
            {
                ParentFld = 12000, TileWidth = 6, NoTE = true, Background = "transparent", Foreground = "black", FontSize = 10, IsSmall = true, HorizontalAlignment = "left"
            });                                                                                                                                                                                                                                                                                                                      //LabelClassName = "cdeTileGroupHeaderSmall SensorGroupLabel", LabelForeground = "white",
            BucketChartFld = TheNMIEngine.AddSmartControl(MyBaseThing, tMyForm, eFieldType.UserControl, 12041, 0, 0, $"{tQVN} Chart", "BucketChart", new ThePropertyBag()
            {
                "NoTE=true", "ParentFld=12040", $"SubTitle={tQVN}", $"SetSeries={{\"name\": \"{tQVN}\"}}",
                "TileWidth=6", "TileHeight=4", "ControlType=Stack Chart",
                $"XAxis={{ \"categories\": {mBucket?.GetBuckets()} }}", $"iValue={mBucket?.GetBucketArray()}"
            });

            TheSensorNMI.CreateDeviceDetails(MyBaseThing, tMyForm, 12060, 12000, null); // new List<string> { $"{tQVN},{tQV}" });

            if (pChartControlBag == null)
            {
                pChartControlBag = new ThePropertyBag {
                    "DoClose=true"
                }
            }
            ;
            else
            {
                ThePropertyBag.PropBagUpdateValue(pChartControlBag, "DoClose", "=", "true");
            }
            var tt = MyHistorian?.CreateHistoryTrendUX(tMyForm, 12300, 12000, $"{tQVN} Trend", $"{tQVN} Trend", TheThing.GetSafePropertyString(MyBaseThing, "HistoryFields"), false, false, pChartControlBag);
        }
コード例 #3
0
 void sinkHistReady2(ICDEThing sender, object para)
 {
     MyHistorian.SetCacheStoreInterval(60);
 }