예제 #1
0
        internal DeviceConnectionState Initialize()
        {
            m_ConnectionState = DeviceConnectionState.ConnectionInProcess;
            FireConnectionEvent(m_ConnectionState, "Gateway initializing");

            if (m_IsGatewayEmulation)
            {
                m_ConnectionState = DeviceConnectionState.ConnectionSuccess;
                FireConnectionEvent(m_ConnectionState, "Gateway initialized");

                return(m_ConnectionState);
            }

            try
            {
                ReadRegister(REG_DEVICE_STATE);

                m_Thread.StartCycle(ThreadWorker, REQUEST_DELAY_MS);

                m_ConnectionState = DeviceConnectionState.ConnectionSuccess;
                FireConnectionEvent(m_ConnectionState, "Gateway initialized");
            }
            catch (Exception ex)
            {
                m_ConnectionState = DeviceConnectionState.ConnectionFailed;

                FireConnectionEvent(m_ConnectionState, String.Format("Gateway initialization error: {0}", ex.Message));
            }

            return(m_ConnectionState);
        }
예제 #2
0
        internal DeviceConnectionState Initialize()
        {
            m_ConnectionState = DeviceConnectionState.ConnectionInProcess;
            FireConnectionEvent(m_ConnectionState, "Commutation initializing");

            if (m_IsCommutationEmulation)
            {
                m_ConnectionState = DeviceConnectionState.ConnectionSuccess;
                FireConnectionEvent(m_ConnectionState, "Commutation initialized");

                return(m_ConnectionState);
            }

            try
            {
                ClearFault();
                ClearWarning();

                var devState = (Types.Commutation.HWDeviceState)GetDeviceState();

                if (devState != Types.Commutation.HWDeviceState.PowerReady)
                {
                    if (devState == Types.Commutation.HWDeviceState.Fault)
                    {
                        ClearFault();
                        Thread.Sleep(1000);

                        devState = (Types.Commutation.HWDeviceState)GetDeviceState();

                        if (devState == Types.Commutation.HWDeviceState.Fault)
                        {
                            throw new Exception(string.Format("Device is in fault state, reason: {0}",
                                                              (Types.Commutation.HWFaultReason)ReadRegister(REG_FAULT_REASON)));
                        }
                    }

                    if (devState == Types.Commutation.HWDeviceState.Disabled)
                    {
                        throw new Exception(string.Format("Device is in disabled state, reason: {0}",
                                                          (Types.Commutation.HWDisableReason)ReadRegister(REG_DISABLE_REASON)));
                    }
                }

                Thread.Sleep(1000);

                devState = (Types.Commutation.HWDeviceState)GetDeviceState();

                if (devState == Types.Commutation.HWDeviceState.Fault)
                {
                    throw new Exception(string.Format("Device is in fault state, reason: {0}",
                                                      (Types.Commutation.HWFaultReason)ReadRegister(REG_FAULT_REASON)));
                }
                if (devState == Types.Commutation.HWDeviceState.Disabled)
                {
                    throw new Exception(string.Format("Device is in disabled state, reason: {0}",
                                                      (Types.Commutation.HWDisableReason)ReadRegister(REG_DISABLE_REASON)));
                }

                if (devState == Types.Commutation.HWDeviceState.SafetyTrig || devState == Types.Commutation.HWDeviceState.SafetyActive)
                {
                    CallAction(ACT_DISABLE_POWER);
                }

                CallAction(ACT_ENABLE_POWER);

                if (m_Type6)
                {
                    WriteRegister(REG_MODULE_TYPE, (ushort)Types.Commutation.HWModuleCommutationType.MT3);
                    WriteRegister(REG_MODULE_POSITION,
                                  (ushort)Types.Commutation.HWModulePosition.Position1);
                    CallAction(ACT_COMM6_SL);
                    CallAction(ACT_COMM6_NONE);
                    WriteRegister(REG_MODULE_POSITION,
                                  (ushort)Types.Commutation.HWModulePosition.Position2);
                    CallAction(ACT_COMM6_SL);
                    CallAction(ACT_COMM6_NONE);
                }
                else
                {
                    CallAction(ACT_COMM2_SL);
                    CallAction(ACT_COMM2_NONE);
                }

                //если поток, контролирующий состояние оптической шторки создан, значит стенд оборудован оптической шторкой безопасности
                if (m_CheckSafetyThread != null)
                {
                    //запускаем поток контроля состояния системы коммутации если он ещё не работает
                    if (!m_CheckSafetyThread.IsRunning)
                    {
                        //поток не работает. в переменной осталось значение от предыдущего теста, сбрасываем его
                        m_SafetyAlarm = false;

                        //уведомляем UI о состоянии оптической шторки
                        FireSafetyEvent(m_SafetyAlarm);

                        m_CheckSafetyThread.StartCycle(SafetyThreadWorker, REQUEST_DELAY_MS);
                        SystemHost.Journal.AppendLog(m_ID, LogMessageType.Info, "Safety thread cycle started");
                    }
                }


                WriteRegister(REG_EN_SFTY_IN4, 0);
                SystemHost.Journal.AppendLog(m_ID, LogMessageType.Info, "REG_EN_SFTY_IN4 write state 0");

                m_ConnectionState = DeviceConnectionState.ConnectionSuccess;

                FireConnectionEvent(m_ConnectionState, "Commutation initialized");
            }
            catch (Exception ex)
            {
                m_ConnectionState = DeviceConnectionState.ConnectionFailed;
                FireConnectionEvent(m_ConnectionState,
                                    String.Format("Commutation initialization error: {0}", ex.Message));
            }

            return(m_ConnectionState);
        }
예제 #3
0
        internal DeviceConnectionState Initialize(bool Enable, int Timeout)
        {
            m_Timeout             = Timeout;
            m_IsClampingEmulation = m_IsClampingEmulationHard || !Enable;

            m_ConnectionState = DeviceConnectionState.ConnectionInProcess;
            FireConnectionEvent(m_ConnectionState, "Clamping initializing");

            if (m_IsClampingEmulation)
            {
                m_ConnectionState = DeviceConnectionState.ConnectionSuccess;

                m_Thread.StartCycle(OnTimedHeating, REQUEST_DELAY_MS);

                FireConnectionEvent(m_ConnectionState, "Clamping initialized");

                return(m_ConnectionState);
            }

            try
            {
                var timeStamp = Environment.TickCount + m_Timeout;

                ClearWarning();

                var devState = (HWDeviceState)ReadRegister(REG_DEVICE_STATE);
                if (devState != HWDeviceState.Ready)
                {
                    if (devState == HWDeviceState.Fault)
                    {
                        ClearFault();
                        Thread.Sleep(100);

                        devState = (HWDeviceState)ReadRegister(REG_DEVICE_STATE);

                        if (devState == HWDeviceState.Fault)
                        {
                            throw new Exception(string.Format("Clamping is in fault state, reason: {0}",
                                                              ReadRegister(REG_FAULT_REASON)));
                        }
                    }

                    if (devState == HWDeviceState.ClampingDone)
                    {
                        CallAction(ACT_RELEASE_CLAMPING);
                    }
                    else
                    {
                        CallAction(ACT_HOMING);
                    }
                }

                while (Environment.TickCount < timeStamp)
                {
                    Thread.Sleep(100);

                    devState = (HWDeviceState)ReadRegister(REG_DEVICE_STATE, true);

                    if (devState == HWDeviceState.Ready)
                    {
                        break;
                    }

                    if (devState == HWDeviceState.Fault)
                    {
                        throw new Exception(string.Format("Clamping is in fault state, reason: {0}",
                                                          (Types.VTM.HWFaultReason)ReadRegister(REG_FAULT_REASON)));
                    }
                    if (devState == HWDeviceState.Disabled)
                    {
                        throw new Exception(string.Format("Clamping is in disabled state, reason: {0}",
                                                          (Types.VTM.HWDisableReason)ReadRegister(REG_DISABLE_REASON)));
                    }
                }

                if (Environment.TickCount > timeStamp)
                {
                    throw new Exception("Timeout while waiting for homing is done");
                }

                m_ConnectionState = DeviceConnectionState.ConnectionSuccess;

                m_Thread.StartCycle(OnTimedHeating, REQUEST_DELAY_MS);

                FireConnectionEvent(m_ConnectionState, "Clamping initialized");
            }
            catch (Exception ex)
            {
                m_ConnectionState = DeviceConnectionState.ConnectionFailed;
                FireConnectionEvent(m_ConnectionState,
                                    String.Format("Clamping initialization error: {0}", ex.Message));
            }

            return(m_ConnectionState);
        }