コード例 #1
0
        public void DaServerMgt_DataChanged(int clientSubscription, bool allQualitiesGood, bool noErrors, ItemValueCallback[] itemValues)
        {
            try
            {
                foreach (ItemValueCallback itemValue in itemValues)
                {
                    if (itemValue.ResultID.Succeeded)
                    {
                        Console.WriteLine(itemValue.TimeStamp + ": " + itemValue.ClientHandle + " - " + itemValue.Value + "\n");
                        Enum.TryParse <PlantState>(itemValue.Value.ToString(), out PlantState plant);
                        if (_plantState == null)
                        {
                            _plantState = new PlantStateHandler(itemValue.TimeStamp, plant);
                        }
                        //plantStateDataAccess.Insert(new PlantStateRowData() { PlantState = (PlantState)plant, TimeStamp = itemValue.TimeStamp });

                        OnPlantStateChange(itemValue.TimeStamp, plant);
                    }
                    else
                    {
                        Console.WriteLine("Errore");
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("DataChanged exception. Reason: {0}", ex);
            }
        }
コード例 #2
0
        private void OnMidnight()
        {
            //timerMidnight.Interval = 860000399; //resets the timer
            timerMidnight.Interval = 5000; //resets the timer
            //the following updated the object
            var now = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 23, 59, 59);

            // ab edit: a scopo di debug _plantState.SetCurrentState  imposta a 0 lo span se è negativo, come accade
            // quando OnMidnight viene chiamata dal timer ogni X secondi anzichè a mezzanotte
            _plantState.SetCurrentState(now, _plantState.CurrentState);
            SavePlantStateToDb(_plantState.PlantStateRowData);
            SavePlantDurationToDb(_plantState.PlantStateDuration);
            PollingCountPieces();
            now = now.AddSeconds(1);
            //missing polling operations (read and persistence);
            //get data from durations counters
            //_plantState.PlantStateDuration.OffDuration.
            //plantStateDataAccess
            //save them to the db

            _plantState = new PlantStateHandler(now, _plantState.CurrentState);
            SavePlantStateToDb(_plantState.PlantStateRowData);
        }
コード例 #3
0
        private void InitPlantState()
        {
            // Aggiorno a mano i valori di tre tag

            int maxAge = 0;

            ItemIdentifier[] OPCItems      = new ItemIdentifier[1];
            ItemValue[]      OPCItemValues = null;

            OPCItems[0] = new ItemIdentifier
            {
                ItemName     = "its-iot-device.Device1.PlantStatus",
                ClientHandle = 1
            };

            //OPCItems[1] = new ItemIdentifier();
            //OPCItems[1].ItemName = "its-iot-device.Device1.PieceCounter";
            //OPCItems[1].ClientHandle = 2;

            //OPCItems[2] = new ItemIdentifier();
            //OPCItems[2].ItemName = "its-iot-device.Device1.DefectedPiecesCounter";
            //OPCItems[2].ClientHandle = 3;

            Console.WriteLine(OPCItems[0].ItemName + "--STATUS \n");
            //Console.WriteLine(OPCItems[1].ItemName + "--PIECE COUNTER \n");
            //Console.WriteLine(OPCItems[2].ItemName + "--DEFECTED PIECES\n");

            try
            {
                daServerMgt.Read(maxAge, ref OPCItems, out OPCItemValues);

                /*if (OPCItems[0].ResultID.Succeeded & OPCItemValues[0].Quality.IsGood)
                 * {
                 *  Console.WriteLine(OPCItemValues[0].Value.ToString() + "\n");
                 * }
                 * else
                 * {
                 *  Console.WriteLine(OPCItems[0].ResultID.Description + "\n");
                 * }*/

                if (OPCItems[0].ResultID.Succeeded & OPCItemValues[0].Quality.IsGood)
                {
                    Console.WriteLine(OPCItemValues[0].Value.ToString() + "\n");

                    Enum.TryParse <PlantState>(OPCItemValues[0].Value.ToString(), out PlantState plant);
                    if (_plantState == null)
                    {
                        _plantState = new PlantStateHandler(OPCItemValues[0].TimeStamp, plant);
                    }
                    OnPlantStateChange(OPCItemValues[0].TimeStamp, plant);
                }
                else
                {
                    Console.WriteLine(OPCItems[0].ResultID.Description + "\n");
                }

                /*if (OPCItems[2].ResultID.Succeeded & OPCItemValues[1].Quality.IsGood)
                 * {
                 *  Console.WriteLine(OPCItemValues[2].Value.ToString() + "\n");
                 * }
                 * else
                 * {
                 *  Console.WriteLine(OPCItems[2].ResultID.Description + "\n");
                 * }*/
            }
            catch (Exception ex)
            {
                // ab edit: aggiungiamo ilcontesto per capire l'errore
                Console.WriteLine($"InitPlantState exeception: {ex.ToString()}");
            }
        }