예제 #1
0
        public static void Init(IJournal journal, ISignalsFactory signals)
        {
            mRelay = new Relay(journal, RelayName.Kv4, signals);

            mOnTimeout           = signals.GetSignal("soundalarm.on.timeout");
            mOnTimeout.OnUpdate += signal =>
            {
                var rv = signal.ValueAsInt < 1500 ? 1500 : signal.ValueAsInt > 6000 ? 6000 : signal.ValueAsInt;
                journal.Debug(string.Format("Таймер вкл. сирены установлен в {0} мс", rv), MessageLevel.System);
                mTask.SetTimeout(rv);
            };

            mOffTimeout           = signals.GetSignal("soundalarm.off.timeout");
            mOffTimeout.OnUpdate += signal =>
            {
                var rv = signal.ValueAsInt < 2500 ? 2500 : signal.ValueAsInt > 10000 ? 10000 : signal.ValueAsInt;
                journal.Debug(string.Format("Таймер выкл. сирены установлен в {0} мс", rv), MessageLevel.System);
                mUnlockInterval = rv;
            };

            // values by default
            mTask           = new DelayedTask(mOnTimeout.ValueAsInt); // 1500
            mUnlockInterval = mOffTimeout.ValueAsInt;                 // 5000

            mTask.OnTimeout += ProcessTimerEvent;
        }
예제 #2
0
파일: Relay.cs 프로젝트: Mokarski/Vagonka
        public void On()
        {
            if (!mOutput.IsSet)
            {
                mJournal.Debug(string.Format("Реле (ОС) {0} вкл.", mOutput.Specification.Id), MessageLevel.System);
            }

            mTask.Start();
            mOutput.Update(true);
        }
예제 #3
0
파일: Relay.cs 프로젝트: Mokarski/Vagonka
        public Relay(IJournal journal, RelayName name, ISignalsFactory signals)
        {
            mJournal = journal;
            mOutput  = signals.GetSignal(SensorName.Relay(name));

            // TODO: uncomment
            mFeedback = signals.GetSignal(SensorName.Relay(name, SignalName.Feedback));

            if (mFeedback != null)
            {
                mFeedback.OnChange += FeedbackOnChange;
            }

            if (mOnTimeout == null)
            {
                mOnTimeout = signals.GetSignal("relay.feedback.on.timeout");
            }

            if (mFeedback != null)
            {
                mOnTimeout.OnUpdate += signal =>
                {
                    var rv = signal.ValueAsInt < 1500 ? 1500 : signal.ValueAsInt > 6000 ? 6000 : signal.ValueAsInt;
                    mJournal.Debug(string.Format("Таймер реле (ОС) установлен в {0} мс для {1}", rv, mOutput.Specification.Id), MessageLevel.System);
                    mTask.SetTimeout(rv);
                };
            }

            // задержка на контроль обратной связи по контактору по умолчанию
            mTask            = new DelayedTask(mOnTimeout == null ? 3000 : mOnTimeout.ValueAsInt < 1500 ? 1500 : mOnTimeout.ValueAsInt > 6000 ? 6000 : mOnTimeout.ValueAsInt);
            mTask.OnTimeout += Checkout;
        }
예제 #4
0
파일: Engine.cs 프로젝트: Mokarski/Vagonka
        /// <summary>
        /// Устанавливем состояние через метод для логгирования
        /// </summary>
        /// <param name="state"></param>
        private static void SetState(SystemState state)
        {
            if (State == state)
            {
                return;
            }

            mJournal.Debug(string.Format("Статус обработчика инверторов: {0}", state), MessageLevel.System);

            State = state;
        }
예제 #5
0
파일: FNTGZ60.cs 프로젝트: Mokarski/Vagonka
        public FNTGZ60(IJournal journal, ISignalsFactory signals, RS485Master modbus, byte modbusId)
        {
            var id = SensorName.Invertor(modbusId);

            if (journal == null)
            {
                throw new ArgumentNullException("journal");
            }

            if (modbus == null)
            {
                throw new ArgumentNullException("modbus");
            }

            Id          = id;
            mJournal    = journal;
            mConnection = modbus;
            mModbusId   = modbusId;

            Status = EngineStatus.Init;


            mState = signals.GetSignal(SensorName.Invertor(mModbusId, SignalName.Mode));
            mError = signals.GetSignal(SensorName.Invertor(mModbusId, SignalName.Error));
            var lastError = float.NaN;

            mError.OnUpdate += signal =>
            {
                if (float.IsNaN(mError.Value) && !float.IsNaN(lastError))
                {
                    mJournal.Debug(string.Format("mError уст. в неизв. сост.: {0}", Id), MessageLevel.System);
                }

                lastError = signal.Value;
            };

            mFrequency   = signals.GetSignal(SensorName.Invertor(mModbusId, SignalName.Frequency));
            mCurrent     = signals.GetSignal(SensorName.Invertor(mModbusId, SignalName.Current));
            mVoltage     = signals.GetSignal(SensorName.Invertor(mModbusId, SignalName.Voltage));
            mTemperature = signals.GetSignal(SensorName.Invertor(mModbusId, SignalName.Temperature));
            mAngle       = signals.GetSignal(SensorName.Invertor(mModbusId, SignalName.Angle));

            mLastStop     = signals.GetSignal(SensorName.Invertor(mModbusId, SignalName.LastStop));
            mHourStop     = signals.GetSignal(SensorName.Invertor(mModbusId, SignalName.HourStop));
            mMinuteStop   = signals.GetSignal(SensorName.Invertor(mModbusId, SignalName.MinuteStop));
            mDayStop      = signals.GetSignal(SensorName.Invertor(mModbusId, SignalName.DayStop));
            mMonthStop    = signals.GetSignal(SensorName.Invertor(mModbusId, SignalName.MonthStop));
            mYearStop     = signals.GetSignal(SensorName.Invertor(mModbusId, SignalName.YearStop));
            mFzadStop     = signals.GetSignal(SensorName.Invertor(mModbusId, SignalName.FzadStop));
            mFpracyStop   = signals.GetSignal(SensorName.Invertor(mModbusId, SignalName.FpracyStop));
            mUdStop       = signals.GetSignal(SensorName.Invertor(mModbusId, SignalName.UdStop));
            mIskutStop    = signals.GetSignal(SensorName.Invertor(mModbusId, SignalName.IskutStop));
            mTermSensStop = signals.GetSignal(SensorName.Invertor(mModbusId, SignalName.TermSensStop));
        }
예제 #6
0
 public void Debug(string message, MessageLevel level = MessageLevel.User)
 {
     mJournal.Debug(message, level);
 }
예제 #7
0
        private void KeyboardInit()
        {
            var pressLockTime = DateTime.MaxValue;

            Keyboard.OnPress += code =>
            {
                switch (code)
                {
                    #region lock & fault reset
                case KeyboardCode.Reserved:
                {
                    switch (mState)
                    {
                    case SystemState.Init:
                    case SystemState.Ready:
                    case SystemState.Failure:
                    {
                        mJournal.Debug(string.Format("Сброс системы: {0}", mState), MessageLevel.System);
                        Pump.ResetFault();
                        Engine.ResetFault();
                        SetState(SystemState.Init, SystemStateCodes.State.Initialization);
                    }
                    break;
                    }
                }
                break;

                //now this button is reset
                case KeyboardCode.UserLock:
                {
                    //pressLockTime = DateTime.Now;
                    switch (mState)
                    {
                    case SystemState.Init:
                    case SystemState.Ready:
                    case SystemState.Failure:
                    {
                        mJournal.Debug(string.Format("Сброс системы: {0}", mState), MessageLevel.System);
                        Pump.ResetFault();
                        Engine.ResetFault();
                        SetState(SystemState.Init, SystemStateCodes.State.Initialization);
                    }
                    break;
                    }
                }
                break;
                    #endregion

                    #region engine
                // now is speed 4 button
                case KeyboardCode.SpeedUp:
                {
                    /*switch (mState)
                     * {
                     *  //case SystemState.Init:
                     *  case SystemState.Ready:
                     *  case SystemState.Active:
                     *      Engine.SpeedUp(EngineMode.Motion);
                     *      break;
                     * }
                     */
                    switch (mState)
                    {
                    // можем запускать только из состояния, когда включен только насос
                    case SystemState.Ready:
                    {
                        Engine.SetMode(EngineMode.Motion);

                        // если нет блокировок на запуск, то mIsActionBlock == false
                        if (!mIsActionBlock)
                        {
                            SetState(SystemState.Active, SystemStateCodes.State.MotionMode);
                        }

                        Engine.Speed4(EngineMode.Motion);
                    }

                    break;
                    }
                }
                break;

                // now this is speed 2 button
                case KeyboardCode.SpeedDown:
                {
                    /*
                     * switch (mState)
                     * {
                     *
                     *  //case SystemState.Init:
                     *  case SystemState.Ready:
                     *  case SystemState.Active:
                     *      Engine.SpeedDown(EngineMode.Motion);
                     *      break;
                     *
                     * }
                     */
                    switch (mState)
                    {
                    // можем запускать только из состояния, когда включен только насос
                    case SystemState.Ready:
                    {
                        Engine.SetMode(EngineMode.Motion);

                        // если нет блокировок на запуск, то mIsActionBlock == false
                        if (!mIsActionBlock)
                        {
                            SetState(SystemState.Active, SystemStateCodes.State.MotionMode);
                        }

                        Engine.Speed2(EngineMode.Motion);
                    }

                    break;
                    }
                }
                break;

                //now is speed 3 button
                case KeyboardCode.MotionStart:
                {
                    switch (mState)
                    {
                    // можем запускать только из состояния, когда включен только насос
                    case SystemState.Ready:
                    {
                        Engine.SetMode(EngineMode.Motion);

                        // если нет блокировок на запуск, то mIsActionBlock == false
                        if (!mIsActionBlock)
                        {
                            SetState(SystemState.Active, SystemStateCodes.State.MotionMode);
                        }

                        Engine.Speed3(EngineMode.Motion);
                    }

                    break;
                    }
                }
                break;

                // now is speed1 button
                case KeyboardCode.MotionStop:
                {
                    switch (mState)
                    {
                    // можем запускать только из состояния, когда включен только насос
                    case SystemState.Ready:
                    {
                        Engine.SetMode(EngineMode.Motion);

                        // если нет блокировок на запуск, то mIsActionBlock == false
                        if (!mIsActionBlock)
                        {
                            SetState(SystemState.Active, SystemStateCodes.State.MotionMode);
                        }

                        Engine.Speed1(EngineMode.Motion);
                    }

                    break;
                    }
                }
                break;
                    #endregion

                    #region conveyor

                case KeyboardCode.ConveyorUp:
                {
                    switch (mState)
                    {
                    case SystemState.Init:
                    case SystemState.Ready:
                    case SystemState.Active:
                        Engine.ConveyorSpeed2();
                        Engine.ConveyorOn(1);
                        //Engine.SpeedUp(EngineMode.Conveyor);
                        break;
                    }
                }
                break;

                case KeyboardCode.ConveyorDown:
                {
                    switch (mState)
                    {
                    case SystemState.Init:
                    case SystemState.Ready:
                    case SystemState.Active:
                        Engine.ConveyorOn(0);
                        Engine.ConveyorSpeed1();
                        //Engine.SpeedDown(EngineMode.Conveyor);
                        break;
                    }
                }
                break;

                case KeyboardCode.ConveyorStart:
                {
                    if (mState != SystemState.Failure)
                    {
                        Engine.ConveyorOn(0);
                    }

                    /*
                     * switch (mState)
                     * {
                     *  // можем запускать только из состояния, когда включен только насос
                     *  case SystemState.Ready:
                     *      {
                     *          Engine.SetMode(EngineMode.Conveyor);
                     *
                     *          // если нет блокировок на запуск, то mIsActionBlock == false
                     *          if (!mIsActionBlock)
                     *              SetState(SystemState.Active, SystemStateCodes.State.ConveyorMode);
                     *      }
                     *
                     *      break;
                     * }
                     */
                }
                break;

                case KeyboardCode.ConveyorStop:
                {
                    Engine.ConveyorOff();

                    /*
                     *  if(Engine.Mode == EngineMode.Conveyor)
                     *  switch (mState)
                     *  {
                     *      case SystemState.Active:
                     *          Engine.SetMode(EngineMode.Deactivate);
                     *          SetState(SystemState.Ready, SystemStateCodes.State.ReadyToUse);
                     *          break;
                     *  }
                     */
                }
                break;

                    #endregion

                    #region pump

                case KeyboardCode.PumpStart:
                {
                    switch (mState)
                    {
                    case SystemState.Ready:
                        Pump.Start();
                        break;
                    }
                }
                break;

                case KeyboardCode.PumpStop:
                {
                    Pump.Stop();
                    SetState(SystemState.Init, SystemStateCodes.State.Initialization);
                }
                break;

                    #endregion

                    #region alarm

                case KeyboardCode.SoundAlarm:
                {
                    SoundAlarm.On();
                }
                break;

                    #endregion
                }
            };

            Keyboard.OnRelese += code =>
            {
                switch (code)
                {
                    #region alarm

                case KeyboardCode.SoundAlarm:
                {
                    SoundAlarm.Off();
                }
                break;

                    #endregion

                    #region conveyor

                case KeyboardCode.ConveyorStart:
                {
                    Engine.ConveyorOff();
                }
                break;

                    #endregion
                //not used
                case KeyboardCode.UserLock:
                {
                    /*
                     * if (DateTime.Now.Subtract(pressLockTime).TotalMilliseconds > 3000)
                     * {
                     *  mJournal.Debug("Станция заблокирована оператором", MessageLevel.System);
                     *  //SetState(SystemState.UserLock);
                     * }
                     */
                }
                break;
                }
            };
        }
예제 #8
0
파일: FNTGZ60.cs 프로젝트: Mokarski/Vagonka
        /// <summary>
        /// Установка параметров частотника для разных рамп (по рекомендации Дарека от 19.10.2015)
        // read before set new value
        // 40325 - value = 5 for conveyor mode or value = 0 for motion mode
        /// </summary>
        internal void SetInvertorMode()
        {
            if (Status != EngineStatus.Stopped)
            {
                return;
            }

            try
            {
                mConnection.Open();
                if (!mConnection.IsOpen())
                {
                    return;
                }

                const ushort kConveyorModeSetting = 5;
                const ushort kMotionModeSetting   = 0;

                #region read
                var rv = mConnection.ReadHoldings(mModbusId, 325, 1);
                if (rv == null)
                {
                    return;
                }

                //if ((Engine.Mode == EngineMode.Conveyor && rv[0] != kConveyorModeSetting) ||
                if (Engine.Mode == EngineMode.Motion && rv[0] != kMotionModeSetting)//)
                {
                    return;

                    var rampMode = kMotionModeSetting;
                    //var rampMode = 0;
                    //var rampMode = Engine.Mode == EngineMode.Conveyor ? kConveyorModeSetting : kMotionModeSetting;
                    mJournal.Debug(string.Format("попытка Установки {0} в {1} по {2}", mModbusId, Engine.Mode, rampMode), MessageLevel.System);

                    #region write
                    //return; // запрещаем смену рамп
                    if (mConnection.Write(mModbusId, 325, new[] { rampMode }))
                    {
                        mJournal.Debug(":: успешно", MessageLevel.System);

                        //mJournal.Debug(string.Format("{0}: modbus success write", modbusId), MessageLevel.System);
                    }
                    else
                    {
                        mJournal.Debug(":: защита при смене рампы", MessageLevel.System);
                    }

                    #endregion
                }

                #endregion
            }
            catch (Exception e)
            {
                if (e is SocketException ||
                    e is TimeoutException ||
                    e is IOException)
                {
                    mConnection.Close();
                }
                else
                {
                    throw;
                }
            }
        }