Exemplo n.º 1
0
        /*
         * private static void SensorCalibrationTest()
         * {
         *  {
         *      var sensor = new ModbusInput();
         *      sensor.AddCalibrationPoint(100, 500);
         *      sensor.AddCalibrationPoint(150, 1000);
         *      //sensor.AddCalibrationPoint(200, 1100);
         *
         *      sensor.Update(10);
         *      Console.WriteLine(sensor.PhisycalValue);
         *
         *      sensor.Update(100);
         *      Console.WriteLine(sensor.PhisycalValue);
         *
         *      sensor.Update(110);
         *      Console.WriteLine(sensor.PhisycalValue);
         *
         *      sensor.Update(140);
         *      Console.WriteLine(sensor.PhisycalValue);
         *
         *      sensor.Update(150);
         *      Console.WriteLine(sensor.PhisycalValue);
         *
         *      sensor.Update(175);
         *      Console.WriteLine(sensor.PhisycalValue);
         *
         *      sensor.Update(200);
         *      Console.WriteLine(sensor.PhisycalValue);
         *  }
         * }
         *
         * private static void TestRelay(SignalFactory signals)
         * {
         *  Thread.Sleep(2000);
         *
         *  var period1 = new PeriodicTask(400);
         *  var state1 = true;
         *  period1.OnPeriod = () =>
         *                         {
         *                             //var rv = outputs.FirstOrDefault(s => s.Id == SensorName.Relay(RelayName.Kv10));
         *                             var rv = signals.GetOutput(SensorName.Relay(RelayName.Kv10));
         *                             if (rv != null)
         *                                 rv.Set(state1);
         *
         *                             state1 = !state1;
         *                         };
         *
         *  period1.Start();
         *
         *  var period2 = new PeriodicTask(900);
         *  var state2 = true;
         *  period2.OnPeriod = () =>
         *                         {
         *                             var rv = signals.GetOutput(SensorName.Relay(RelayName.Kv8));
         *                             if (rv != null)
         *                                 rv.Set(state2);
         *
         *                             state2 = !state2;
         *                         };
         *
         *  period2.Start();
         *
         *  var period3 = new PeriodicTask(500);
         *  var state3 = true;
         *  period3.OnPeriod = () =>
         *                         {
         *                             var rv = signals.GetOutput(SensorName.Relay(RelayName.Kv4));
         *                             if (rv != null)
         *                                 rv.Set(state3);
         *
         *                             state3 = !state3;
         *                         };
         *
         *  period3.Start();
         *
         *  var keyboard = signals.GetSignal(SensorName.Keyboard()) as LocalKeyboard;
         *  if (keyboard != null)
         *  {
         *      keyboard.OnPress += value => Console.WriteLine("press: {0}", value);
         *      keyboard.OnRelese += value => Console.WriteLine("release: {0}", value);
         *  }
         * }
         */
        #endregion

        private static void TestKeyboard(SignalsFactory signals)
        {
            /*
             * var kv4 = signals.GetOutput(SensorName.Relay(RelayName.Kv4));
             * var kv8 = signals.GetOutput(SensorName.Relay(RelayName.Kv8));
             * var kv9 = signals.GetOutput(SensorName.Relay(RelayName.Kv9));
             * var kv10 = signals.GetOutput(SensorName.Relay(RelayName.Kv10));
             * var kv11 = signals.GetOutput(SensorName.Relay(RelayName.Kv11));
             *
             * var list = new List<IOutput> {kv4, kv8, kv9, kv10, kv11};
             *
             *
             * var sensors = new List<ISignal>
             *                {
             *                    signals.GetSignal(SensorName.Relay(RelayName.Kv1, SignalName.Feedback)),
             *                    signals.GetSignal(SensorName.Relay(RelayName.Kv2, SignalName.Feedback)),
             *                    signals.GetSignal(SensorName.Relay(RelayName.Kv8, SignalName.Feedback)),
             *                    signals.GetSignal(SensorName.Relay(RelayName.Kv9, SignalName.Feedback)),
             *                    signals.GetSignal(SensorName.Relay(RelayName.Kv10, SignalName.Feedback)),
             *                    signals.GetSignal(SensorName.Relay(RelayName.Kv11, SignalName.Feedback))
             *                };
             *
             * var timer = new PeriodicTask(500);
             * timer.OnPeriod += () =>
             *                    {
             *                        Console.Write("\r");
             *
             *                        foreach (var sensor in sensors)
             *                        {
             *                            Console.ForegroundColor = sensor.Value > 0
             *                                                          ? ConsoleColor.Green
             *                                                          : ConsoleColor.Gray;
             *                            Console.Write("{0}: {1}\t", sensor.Id.Replace("relay.", ""), sensor.Value);
             *                        }
             *                    };
             * timer.Start();
             */


            Keyboard.OnPress += value =>
            {
                Console.WriteLine("press: {0}", value);

                /*
                 * switch (value)
                 * {
                 *      case KeyboardCode.SpeedUp:
                 *      kv4.Set(true);
                 *      break;
                 *
                 *      case KeyboardCode.MotionStart:
                 *      kv8.Set(true);
                 *      break;
                 *
                 *      case KeyboardCode.SpeedDown:
                 *      kv9.Set(true);
                 *      break;
                 *
                 *      case KeyboardCode.MotionStop:
                 *      kv10.Set(true);
                 *      break;
                 *
                 *      case KeyboardCode.PumpStart:
                 *      kv11.Set(true);
                 *      break;
                 * }
                 */
            };


            Keyboard.OnRelese += value =>
            {
                Console.WriteLine("release: {0}", value);

                /*
                 * foreach (var output in list)
                 * {
                 *  output.Set(false);
                 * }
                 */
            };
        }
Exemplo n.º 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
        }