Example #1
0
        static void Main()
        {
            //var journal = new ConsoleJournal();//journalService.GetJournal();
            //var journal = new SqLiteJournal {IsConsoleEnable = true};//journalService.GetJournal();
            //var journal = new JournalClient("127.0.0.1");

            //Console.OutputEncoding = System.Text.Encoding.GetEncoding(1251);
            //Console.OutputEncoding = System.Text.Encoding.GetEncoding("UTF-8");
            //Console.OutputEncoding = System.Text.Encoding.GetEncoding(866);
            bool debug = false;

            bool oldPanel43 = false;

            var mJServer = new JournalService(true);

            mJServer.Start();
            var journal = mJServer.GetJournal();

            var mMsgLvlSys = MessageLevel.System;

            journal.Warning("Старт работы PCproc", mMsgLvlSys);

            var signals = new SignalsFactory(journal);

            ConfigureSignalFactory(signals);
            journal.Warning("Запуск и конфигурирование Фабрики сигналов", mMsgLvlSys);
            //ModBusWago();

            var wago = new Coupler(journal, "192.168.1.111");


            //if (CouplerConfigurator.W750493_flag == false) wago.SetBaseAddr(524);
            CouplerConfigurator.Init(wago, signals);
            journal.Warning("Инициализация Ваго", mMsgLvlSys);
            List <ITask> tasklets;
            //if (oldPanel43) {
            var local = new RemoteConsole(journal, signals, 5000);

            journal.Warning(" Подключение к порту журнала на 5000 ", mMsgLvlSys);
            tasklets = new List <ITask> {
                local, wago, signals
            };
            //} else tasklets = new List<ITask> { wago, signals };


            /* This code added to support Qt GUI version of 4.3 Panel*/
            var qt = new qt(ref mJServer, ref signals, ref journal, true);

            qt.startLiterner();

            /* This code added to support Qt GUI version of 4.3 Panel*/

            try
            {
                //signals.GetSignal(SensorName.Keyboard()).OnChange += signal => Console.WriteLine("Keyboard: {0}", signal.Value);

                //signals.GetSignal(SensorName.Tank(SignalName.Level)).OnUpdate += signal => journal.Debug(string.Format("Level: {0}", signal.Value), MessageLevel.User);
                //signals.GetSignal("encoder.point").OnUpdate += signal => journal.Info(string.Format("Angle: {0}", signal.Value), MessageLevel.User);
                //signals.GetSignal(SensorName.Tank(SignalName.Temperature)).OnChange += signal => Console.WriteLine("Temp: {0}", signal.Value);

                //signals.GetSignal(SensorName.Cabel(SignalName.Pressure)).OnUpdate += signal => journal.Debug(string.Format("Cabel: {0}", signal.Value), MessageLevel.User);
                //signals.GetSignal(SensorName.Filter(SignalName.Pressure)).OnUpdate += signal => journal.Debug(string.Format("Filter: {0}", signal.Value), MessageLevel.User);
                //signals.GetSignal(SensorName.Steering(SignalName.Pressure)).OnUpdate += signal => journal.Debug(string.Format("Steering: {0}", signal.Value), MessageLevel.User);
                //signals.GetSignal(SensorName.Brake(SignalName.Pressure)).OnUpdate += signal => journal.Debug(string.Format("Brake: {0}", signal.Value), MessageLevel.User);

                //var pStatus = signals.GetSignal(SensorName.Derivative(SystemName.Pump, SignalName.Status));
                //var uz2Status = signals.GetSignal(SensorName.Derivative(SystemName.Uz, 2, SignalName.Status));
                //var uz3Status = signals.GetSignal(SensorName.Derivative(SystemName.Uz, 3, SignalName.Status));
                //var uz4Status = signals.GetSignal(SensorName.Derivative(SystemName.Uz, 4, SignalName.Status));
                //var uz5Status = signals.GetSignal(SensorName.Derivative(SystemName.Uz, 5, SignalName.Status));
                //var cStatus = signals.GetSignal(SensorName.Derivative(SystemName.Conveyor, SignalName.Status));
                //var code = 0;
                //cStatus.Update(code);
                //code++;
                // проверяем не включена ли сейчас станция
                //foilstationstate = checkValueAsBool(signals.GetSignal("relay.kv11.k1").Value);
                // подписываемся на событие ОС по маслостанции, чтобы ставить флаг ее работы (так быстрее, чем постоянно спрашивать сигнал)
                signals.GetSignal("relay.kv11.k1").OnChange += sensor => oilStationState(sensor);

                int MotoSeconds = 0;
                int OilSeconds  = 0;
                //float TotalMotoHours = 0;
                float Moto = signals.GetSignal("system.settings.MotoHours").Value;
                float Oil  = signals.GetSignal("system.settings.OilHours").Value;
                //float TotalMotoHours = signals.GetSignal("system.settings.TotalMotoHours").Value;
                using (new SystemContol(journal, signals))
                {
                    //signals.PrintInfo(); //отладка сигналов в процессоре

                    foreach (var task in tasklets)
                    {
                        task.Start();
                    }

                    while (true)
                    {
                        Thread.Sleep(5000);
                        //проверка состояния насоса маслостанции
                        //var signalPump = signals.GetSignal("derivative.pump.status").Value;

                        //foilstationstate = true;
                        if (foilstationstate)
                        {
                            //насос включен
                            //Считаем секунды
                            MotoSeconds += 5;
                            if (MotoSeconds >= 60 * 15) //одна минута
                            {
                                MotoSeconds = 0;        //сброс секунд
                                Moto        = signals.GetSignal("system.settings.MotoHours").Value;
                                Moto       += 0.25f;
                                signals.Update("system.settings.MotoHours", Moto);
                            }
                            OilSeconds += 5;
                            if (OilSeconds >= 60 * 15) //одна минута
                            {
                                OilSeconds = 0;        //сброс секунд
                                Oil        = signals.GetSignal("system.settings.OilHours").Value;
                                Oil       += 0.25f;
                                signals.Update("system.settings.OilHours", Oil);
                            }

                            //if (MotoHours >= 200) //Замена масла через 200 М.ч.
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                journal.Fatal(ex.ToString(), MessageLevel.System);
            }


            #region stop tasks
            tasklets.Reverse();
            foreach (var task in tasklets)
            {
                task.Stop();
            }
            #endregion
        }
Example #2
0
        // wago - 192.168.1.111
        // gate - 192.168.1.121
        // 4.3" - 192.168.1.122
        // 10" - 192.168.1.131
        // stm32 - 192.168.1.141

        // wago test modules

        static void Main()
        {
            //var journal = new ConsoleJournal();//journalService.GetJournal();
            //var journal = new SqLiteJournal {IsConsoleEnable = true};//journalService.GetJournal();
            //var journal = new JournalClient("127.0.0.1");

            //Console.OutputEncoding = System.Text.Encoding.GetEncoding(1251);
            //Console.OutputEncoding = System.Text.Encoding.GetEncoding("UTF-8");
            //Console.OutputEncoding = System.Text.Encoding.GetEncoding(866);
            bool debug = false;

            bool oldPanel43 = false;

            var mJServer = new JournalService(true);

            mJServer.Start();
            var journal = mJServer.GetJournal();

            var mMsgLvlSys = MessageLevel.System;

            journal.Warning("Старт работы PCproc", mMsgLvlSys);

            var signals = new SignalsFactory(journal);

            ConfigureSignalFactory(signals);
            journal.Warning("Запуск и конфигурирование Фабрики сигналов", mMsgLvlSys);
            //ModBusWago();

            var wago = new Coupler(journal, "192.168.1.111");


            //if (CouplerConfigurator.W750493_flag == false) wago.SetBaseAddr(524);
            CouplerConfigurator.Init(wago, signals);
            journal.Warning("Инициализация Ваго", mMsgLvlSys);
            List <ITask> tasklets;
            //if (oldPanel43) {
            var local = new RemoteConsole(journal, signals, 5000);

            journal.Warning(" Подключение к порту журнала на 5000 ", mMsgLvlSys);
            tasklets = new List <ITask> {
                local, wago, signals
            };
            //} else tasklets = new List<ITask> { wago, signals };


            /* This code added to support Qt GUI version of 4.3 Panel*/
            var qt = new qt(ref mJServer, ref signals, ref journal, true);

            qt.startLiterner();

            /* This code added to support Qt GUI version of 4.3 Panel*/

            try
            {
                //signals.GetSignal(SensorName.Keyboard()).OnChange += signal => Console.WriteLine("Keyboard: {0}", signal.Value);

                //signals.GetSignal(SensorName.Tank(SignalName.Level)).OnUpdate += signal => journal.Debug(string.Format("Level: {0}", signal.Value), MessageLevel.User);
                //signals.GetSignal("encoder.point").OnUpdate += signal => journal.Info(string.Format("Angle: {0}", signal.Value), MessageLevel.User);
                //signals.GetSignal(SensorName.Tank(SignalName.Temperature)).OnChange += signal => Console.WriteLine("Temp: {0}", signal.Value);

                //signals.GetSignal(SensorName.Cabel(SignalName.Pressure)).OnUpdate += signal => journal.Debug(string.Format("Cabel: {0}", signal.Value), MessageLevel.User);
                //signals.GetSignal(SensorName.Filter(SignalName.Pressure)).OnUpdate += signal => journal.Debug(string.Format("Filter: {0}", signal.Value), MessageLevel.User);
                //signals.GetSignal(SensorName.Steering(SignalName.Pressure)).OnUpdate += signal => journal.Debug(string.Format("Steering: {0}", signal.Value), MessageLevel.User);
                //signals.GetSignal(SensorName.Brake(SignalName.Pressure)).OnUpdate += signal => journal.Debug(string.Format("Brake: {0}", signal.Value), MessageLevel.User);

                //var pStatus = signals.GetSignal(SensorName.Derivative(SystemName.Pump, SignalName.Status));
                //var uz2Status = signals.GetSignal(SensorName.Derivative(SystemName.Uz, 2, SignalName.Status));
                //var uz3Status = signals.GetSignal(SensorName.Derivative(SystemName.Uz, 3, SignalName.Status));
                //var uz4Status = signals.GetSignal(SensorName.Derivative(SystemName.Uz, 4, SignalName.Status));
                //var uz5Status = signals.GetSignal(SensorName.Derivative(SystemName.Uz, 5, SignalName.Status));
                //var cStatus = signals.GetSignal(SensorName.Derivative(SystemName.Conveyor, SignalName.Status));
                //var code = 0;
                //cStatus.Update(code);
                //code++;

                //if (code > 2)
                //    code = 0;

                int first_cycle = 0;
                int show_delay  = 0;
                int MotoSeconds = 0;
                int MotoMinutes = 0;
                int MotoDays    = 0;
                //float TotalMotoHours = 0;
                float MotoHours = signals.GetSignal("system.settings.MotoHours").Value;
                //float TotalMotoHours = signals.GetSignal("system.settings.TotalMotoHours").Value;
                using (new SystemContol(journal, signals))
                {
                    //signals.PrintInfo(); //отладка сигналов в процессоре

                    foreach (var task in tasklets)
                    {
                        task.Start();
                    }

                    while (true)
                    {
                        Thread.Sleep(1000);
                        //проверка состояния насоса маслостанции
                        var signalPump = signals.GetSignal("derivative.pump.status").Value;
                        if (debug)
                        {
                            if (signalPump == 0)
                            {
                                Console.WriteLine("Pump stopped: " + signalPump);
                            }
                        }

                        //debug signalPump=1
                        signalPump = 1;
                        //Debug 1sec = 1min
                        MotoMinutes = MotoSeconds;

                        if (signalPump == 1)
                        {
                            //насос включен
                            if (debug)
                            {
                                Console.WriteLine("Pump started: " + signalPump);
                            }

                            //первый проход забрали из базы и прибавили к текущему время
                            if (debug)
                            {
                                Console.WriteLine(">>>>>> Moto hours from DB: " + MotoHours);
                            }
                            //first_cycle = 1;
                            //if (first_cycle == 1) MotoHours = MotoHours + MotoSeconds / 120;

                            //Считаем секунды
                            MotoSeconds++;
                            if (MotoSeconds == 60) //одна минута
                            {
                                MotoSeconds = 0;   //сброс секунд
                                MotoMinutes = MotoMinutes + 1;
                            }


                            if (debug)
                            {
                                Console.WriteLine("Moto seconds: " + MotoSeconds);
                                Console.WriteLine("Moto Minutes: " + MotoMinutes);
                            }

                            //Считаем минуты
                            if (MotoMinutes == 60)
                            {
                                //Сброс минут по накоплении одного часа
                                MotoMinutes = 0;
                                //Cчитаем часы
                                MotoHours = MotoHours + 1;
                                //MotoHours = MotoHours + 100;

                                if (debug)
                                {
                                    Console.WriteLine("Moto seconds: " + MotoSeconds);
                                    Console.WriteLine("Moto Minutes: " + MotoMinutes);
                                    Console.WriteLine(">>>>>> Moto hours now: " + MotoHours);
                                }
                                signals.Update("system.settings.MotoHours", MotoHours);
                            }


                            //Защита от переполнения счетчика
                            if (MotoHours >= 250000) // Т.е. 250 000 часов это 28 лет
                            {
                                MotoHours = 0;
                                if (debug)
                                {
                                    Console.WriteLine(">>>>>> Moto hours now: " + MotoHours);
                                }
                            }

                            //if (MotoHours >= 200) //Замена масла через 200 М.ч.
                        }
                        show_delay++;
                        if (show_delay == 3)
                        {
                            // signals.PrintInfo(); //отладка сигналов в процессоре
                            //signals.WriteInfo(@"/mnt/sdcard/failsignals.raw"); //отладка сигналов в процессоре rwfs директория для перезаписи
                            show_delay = 0; //сброс таймера задержки

                            //Учет входа в меню сервисантов и инжинеров
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                journal.Fatal(ex.ToString(), MessageLevel.System);
            }


            #region stop tasks
            tasklets.Reverse();
            foreach (var task in tasklets)
            {
                task.Stop();
            }
            #endregion
        }