Exemplo n.º 1
0
        private void flowHome(TProcVar S)
        {
            switch (S.Step1)
            {
                #region flow init

            case 0:
                //關掉軟體極限,
                DisableSoftLimit();
                Stop(StopType.SlowDown, false);
                ServoOn(CmdStatus.ON);
                status.Home = false;
                S.Step1     = 1;
                S.Timeout   = 30000;
                if (HomeStarted != null)
                {
                    HomeStarted(DeviceName);
                }
                break;

            case 1:
                if (!IsBusy)
                {
                    switch (axisPara.HomeMode)
                    {
                    case HomeMode.OnePoint:
                        S.Step1 = 1000;
                        break;

                    case HomeMode.TwoPoint:
                        S.Step1 = 2000;
                        break;

                    case HomeMode.ThreePointWithZPhase:
                        S.Step1 = 2000;
                        break;

                    case HomeMode.ThreePoint:
                        S.Step1 = 3000;
                        break;
                    }
                }
                break;

                #endregion flow init

                #region OnePoint

            case 1000:
                //不在原點上
                if (!status.ORG)
                {
                    JogM(axisPara.OPRDevVelH, RotationDirection.CCW);
                }
                S.Step1 = 1010;
                break;

            case 1010:
                if (status.ORG)
                {
                    Stop(StopType.Emergency, false);
                    S.TM1.Restart();
                    S.Step1 = 1020;
                }
                break;

            case 1020:
                if (S.TM1.ElapsedMilliseconds > 100)
                {
                    JogM(5, RotationDirection.CW);
                    S.TM1.Restart();
                    S.Step1 = 1030;
                }
                break;

            case 1030:
                if (S.TM1.ElapsedMilliseconds > S.Timeout)
                {
                    S.Result.Value   = -1030;
                    S.Result.Message = LanguageResourceManager.GetString("TimeoutOutOfORG") + "(" + DeviceName + ")";
                    S.Step1          = 9000;
                }
                else
                {
                    if (!status.ORG)
                    {
                        Stop(StopType.Emergency, false);
                        doHomeOrg();
                        S.TM1.Restart();
                        S.Step1 = 7000;
                    }
                }
                break;

                #endregion OnePoint

                #region TwoPoint

            case 2000:
                if (status.LimitN)
                {
                    JogM(axisPara.OPRDevVelH, RotationDirection.CW);
                    S.TM1.Restart();
                    S.Step1 = 2100;
                }
                else if (status.LimitP)
                {
                    JogM(axisPara.OPRDevVelH, RotationDirection.CCW);
                    S.TM1.Restart();
                    S.Step1 = 2100;
                }
                else
                {
                    S.TM1.Restart();
                    S.Step1 = 2100;
                }
                break;

            case 2100:
                if (S.TM1.ElapsedMilliseconds > S.Timeout)
                {
                    S.Result.Value   = -2100;
                    S.Result.Message = LanguageResourceManager.GetString("TimeoutOutOfLimitN") + "(" + DeviceName + ")";
                    S.Step1          = 9000;
                }
                else
                {
                    if (!status.LimitN && !status.LimitP)
                    {
                        Stop(StopType.Emergency, false);
                        S.TM1.Restart();
                        S.Step1 = 2010;
                    }
                }
                break;

            case 2010:
                if (S.TM1.ElapsedMilliseconds > S.Timeout)
                {
                    S.Result.Value   = -2010;
                    S.Result.Message = LanguageResourceManager.GetString("TimeoutOutOfLimitN") + "(" + DeviceName + ")";
                    S.Step1          = 9000;
                }
                else
                {
                    if (!status.LimitN)
                    {
                        JogM(axisPara.OPRDevVelH, RotationDirection.CCW);
                    }
                    S.Step1 = 2020;
                }
                break;

            case 2020:
                if (status.LimitN)
                {
                    Stop(StopType.Emergency, false);
                    S.TM1.Restart();
                    S.Step1 = 2030;
                }
                break;

            case 2030:
                if (S.TM1.ElapsedMilliseconds > 100)
                {
                    if (axisPara.HomeMode == HomeMode.ThreePointWithZPhase)
                    {
                        doHomeLimWithZPhase();
                    }
                    else
                    {
                        doHomeLim();
                    }
                    S.Step1 = 7000;
                }
                break;

            case 2040:
                if (status.LimitN)
                {
                    Stop(StopType.Emergency, false);
                    S.Step1 = 7000;
                }
                break;

                #endregion TwoPoint

                #region ThreePoint

            case 3000:
                if (!status.ORG && !status.LimitN)
                {
                    JogM(axisPara.OPRDevVelH, RotationDirection.CCW);
                }
                S.Step1 = 3010;
                break;

            case 3010:
                if (status.ORG || status.LimitN)
                {
                    Stop(StopType.Emergency, false);
                    S.TM1.Restart();
                    S.Step1 = 3020;
                }
                break;

            case 3020:
                if (S.TM1.ElapsedMilliseconds > 100)
                {
                    JogM(axisPara.CreepDevVelH, RotationDirection.CW);
                    S.Step1 = 3030;
                }
                break;

            case 3030:
                if (S.TM1.ElapsedMilliseconds > S.Timeout)
                {
                    S.Result.Value   = -3030;
                    S.Result.Message = LanguageResourceManager.GetString("TimeoutEnterORG") + "(" + DeviceName + ")";
                    S.Step1          = 9000;
                }
                else
                {
                    if (status.ORG)
                    {
                        S.Step1 = 3040;
                    }
                }
                break;

            case 3040:
                if (!status.ORG)
                {
                    Stop(StopType.Emergency, false);
                    S.TM1.Restart();
                    S.Step1 = 3050;
                }
                break;

            case 3050:
                if (S.TM1.ElapsedMilliseconds > 100)
                {
                    doHomeOrg();
                    S.Step1 = 7000;
                }
                break;

                #endregion ThreePoint

                #region flow continue

            case 7000:
                if (S.TM1.ElapsedMilliseconds > 500 && !IsBusy)
                {
                    S.Step1 = 7010;
                }
                break;

            case 7010:
                ResetPos();
                Move(axisPara.OffsetH, SpeedMode.Manual);
                S.Step1 = 7020;
                break;

            case 7020:
                if (IsReached)
                {
                    S.TM1.Restart();
                    S.Step1 = 7030;
                }
                break;

            case 7030:
                if (S.TM1.ElapsedMilliseconds >= axisPara.ClearDelay * 1000)
                {
                    ResetPos();
                    S.Step1 = 8000;
                }
                break;

                #endregion flow continue

                #region flow end

            //flow finish
            case 8000:
                if (HomeCompleted != null)
                {
                    HomeCompleted(DeviceName);
                }
                status.Home = true;
                homeTask.TurnOff(itemHome);
                break;

            //flow trip
            case 9000:
                if (HomeFailure != null)
                {
                    HomeFailure(DeviceName);
                }
                status.Home = false;
                homeTask.TurnOff(itemHome);

                break;

                #endregion flow end
            }
        }
Exemplo n.º 2
0
        protected void parameterInitialize()
        {
            bool isModulesParameterClassExisted = checkModulesParameterClass(modulesType);
            bool isSerialModule = checkModuleIsSerial(modulesType);
            bool isSocketModule = checkModuleIsSocket(modulesType);

            //檢查所指定的參數資料夾是否存在
            if (!Directory.Exists(this.ParameterFolderPath))
            {
                Directory.CreateDirectory(ParameterFolderPath);
            }
            string parameterFilePath = string.Format(@"{0}\{1}.ini", this.ParameterFolderPath, this.DeviceName);

            //參數檔不存在--> 訊息提示 --> 顯示對應屬性修改視窗
            if (!File.Exists(parameterFilePath))
            {
                ExceptionHelper.CommonMessageShow(LanguageResourceManager.GetString("DefaultParameter") + "(" + DeviceName + ")", "SystemHint");

                //在LibraryResource中有找到對應的Parameter參數資源
                if (isModulesParameterClassExisted)
                {
                    //[底層] 此部份要測試,可能會有型別問題
                    //如果有自訂參數檔且是Serial模組 用FrmParameterSerialSetting設定屬性
                    if (isSerialModule)
                    {
                        parameter = createGeneralSerialParameter(modulesType, this.ParameterFolderPath, this.DeviceName);
                        ParameterSerialSettingForm parameterSerialSettingForm = new ParameterSerialSettingForm(parameter, this.DeviceName);
                        parameterSerialSettingForm.ShowDialog();
                        ((ParameterINI)parameter).Save();
                    }
                    else if (isSocketModule)
                    {
                        parameter = createGeneralSocketParameter(modulesType, this.ParameterFolderPath, this.DeviceName);
                        ParameterSocketSettingForm parameterSocketSettingForm = new ParameterSocketSettingForm(parameter, this.DeviceName);
                        parameterSocketSettingForm.ShowDialog();
                        ((ParameterINI)parameter).Save();
                    }
                    else
                    {
                        parameter = createCustomParameter(modulesType, this.ParameterFolderPath, this.DeviceName);
                        ParameterINIForm propertyGridForm = new ParameterINIForm(parameter, this.DeviceName);
                        propertyGridForm.ShowDialog();
                        ((ParameterINI)parameter).Save();
                    }
                }
                //在LibraryResource中沒有對應的參數資源
                else
                {
                    //確認是否為serialModule 有些serial通訊模組不會另外自訂參數檔
                    //從LibraryResource讀取預設的ParameterSerial
                    if (isSerialModule)
                    {
                        parameter = createGeneralSerialParameter(modulesType, this.ParameterFolderPath, this.DeviceName);
                        ParameterSerialSettingForm frmParameterSerialSetting = new ParameterSerialSettingForm(parameter, this.DeviceName);
                        frmParameterSerialSetting.ShowDialog();
                        ((ParameterINI)parameter).Save();
                    }
                    else if (isSocketModule)
                    {
                        parameter = createGeneralSocketParameter(modulesType, this.ParameterFolderPath, this.DeviceName);
                        ParameterSocketSettingForm frmParameterSocketSetting = new ParameterSocketSettingForm(parameter, this.DeviceName);
                        frmParameterSocketSetting.ShowDialog();
                        ((ParameterINI)parameter).Save();
                    }
                    //沒有自訂的參數檔 也不是serialModule 先傳回exception 日後依照需要去修正
                    else
                    {
                        throw new Exception(ExceptionHelper.GetFullCurrentMethod(ResourceHelper.Language.GetString("WrongClassName") + "(" + this.DeviceName + ")"));
                    }
                }
            }
            //參數檔存在--> 直接讀回該檔案之屬性值
            else
            {
                if (isModulesParameterClassExisted)
                {
                    parameter = createCustomParameter(modulesType, this.ParameterFolderPath, this.DeviceName);
                    ((ParameterINI)parameter).Load();
                }
                else
                {
                    if (isSerialModule)
                    {
                        parameter = createGeneralSerialParameter(modulesType, this.ParameterFolderPath, this.DeviceName);
                        ((ParameterINI)parameter).Load();
                    }
                    else if (isSocketModule)
                    {
                        parameter = createGeneralSocketParameter(modulesType, this.ParameterFolderPath, this.DeviceName);
                        ((ParameterINI)parameter).Load();
                    }
                    else
                    {
                        throw new Exception(ExceptionHelper.GetFullCurrentMethod(ResourceHelper.Language.GetString("WrongClassName") + "(" + this.DeviceName + ")"));
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void slaveModuleInitialize()
        {
            uint mask = 0x00000001;

            uint[] deviceTable = DeviceTable;
            if ((deviceTable[0] == 0) && (deviceTable[1] == 0))
            {
                throw new Exception("Can't find slave A180, there is not any device !!! \n func = [_mnet_get_ring_active_table, deviceTable=0]");
            }

            for (int i = 0; i < 64; i++)
            {
                if (adcPara.SlaveIP > 63)
                {
                    throw new Exception("Wrong SlaveIP, SlaveIP must less than 63!!!");
                }

                if (adcPara.SlaveIP == i)
                {
                    if (i < 32)
                    {
                        if ((deviceTable[0] & mask) == 0)
                        {
                            throw new Exception("Have not found A180 !!!\n" + "SlaveIP = " + adcPara.SlaveIP);
                        }
                    }
                    else
                    {
                        if (i == 32)
                        {
                            mask = 0x00000001;
                        }
                        if ((deviceTable[1] & mask) == 0)
                        {
                            throw new Exception("Have not found A180 !!!\n" + "SlaveIP = " + adcPara.SlaveIP);
                        }
                    }
                }
                mask = mask << 1;
            }

            I16 retOfStartRing = CCMNet.CS_mnet_start_ring(RingNoOfMNet);

            if (retOfStartRing != 0)
            {
                throw new Exception("Error occur when start ring !!! \n func = [_mnet_start_ring]");
            }

            U8  slaveType         = 0;
            I16 retOfGetSlaveType = CCMNet.CS_mnet_get_slave_type(RingNoOfMNet, adcPara.SlaveIP, ref slaveType);

            if (retOfGetSlaveType == 0)
            {
                if (slaveType != 0xD1)
                {
                    throw new Exception("deviec type is not A180!!!\n" + "SlaveIP = " + adcPara.SlaveIP);
                }
            }
            else
            {
                throw new Exception("Error occur when get device type !!! \n func = [_mnet_get_slave_type]");
            }

            I16 rc = CADC_A180.CS_mnet_ai8_initial((U16)adcPara.CardSwitchNo, (U16)adcPara.SlaveIP);

            if (rc != 0)
            {
                throw new Exception(ExceptionHelper.GetFullCurrentMethod(LanguageResourceManager.GetString("InitializeErrorA180ADC") + "(" + DeviceName + ")"));
            }

            rc = CADC_A180.CS_mnet_ai8_set_cycle_time((U16)adcPara.CardSwitchNo, (U16)adcPara.SlaveIP, 0);
            if (rc != 0)
            {
                throw new Exception(ExceptionHelper.GetFullCurrentMethod(LanguageResourceManager.GetString("SetCycleErrorA180ADC") + "(" + DeviceName + ")"));
            }
        }