Ejemplo n.º 1
0
        public void Step()
        {
            if (DeviceMgr.IsInAction()) //communication action is going on
            {
                return;
            }

            if (currRx.i_State == RUN_STATE.STOPPING)   //user choose to stop
            {
                DeviceMgr.Reset();
                act_mgr.Reset();
                bPaused        = false;
                bRunning       = false;
                currRx.i_State = RUN_STATE.IDLE;
            }
            if (bPaused || !bRunning || act_mgr.IsBusy)
            {
                return;
            }


            if (stm == ACTION_STATE.INIT_FOR_START)//search the next valid channel
            {
                currRx.i_State = RUN_STATE.SEARCHING;
                StatusChanged(this, "search");
                stm = act_mgr.Do(ACTION_REQUEST.INIT_NAV_RANGE, stm);
                return;
            }
            if (stm == ACTION_STATE.INIT_FOR_SEARCH) //prepare the capture with 1:1 mode
            {
                currRx.i_State = RUN_STATE.SEARCHING;
                StatusChanged(this, "search");
                stm = act_mgr.Do(ACTION_REQUEST.INITKI_FOR_SEARCH, stm);
                return;
            }
            if (stm == ACTION_STATE.INIT_FOR_RS_KTTP) //capture once //set to KTTP mode and delay 1s
            {
                currRx.i_State = RUN_STATE.SEARCHING;
                StatusChanged(this, "search");
                stm = act_mgr.Do(ACTION_REQUEST.SET_FOR_RS_KTTP, stm);
                return;
            }
            if (stm == ACTION_STATE.INIT_FOR_RS_KTTN)
            {
                currRx.i_State = RUN_STATE.SEARCHING;
                StatusChanged(this, "search");

                double val = act_mgr.dStableReading;
                if (val < -999)
                {
                    currRx.i_State = RUN_STATE.STOPPING;
                    StatusChanged(this, "stopping");
                    return;
                }
                currRx.var.vRs = val;
                stm            = act_mgr.Do(ACTION_REQUEST.SET_FOR_RS_KTTN, stm);
                return;
            }
            if (stm == ACTION_STATE.COMPLETE_ISRC) //capture once //set to KTTP mode
            {
                currRx.i_State = RUN_STATE.SEARCHING;
                StatusChanged(this, "search");
                double val = act_mgr.dStableReading;
                if (val < -999)
                {
                    currRx.i_State = RUN_STATE.STOPPING;
                    StatusChanged(this, "stopping");
                    return;
                }
                currRx.var.vRs  = Math.Abs(currRx.var.vRs - val) / 2.0;
                currRx.var.iSrc = currRx.var.vRs / currRx.var.rRs;
                currRx.var.iSrc = currRx.var.iSrc * RX_VAR.INIT_LOOP / (double)currRx.var.iK;
                double stdcurr = RunWnd.syscfg.GetStdCurrent(currRx.iIx, currRx.bSqrt);
                if (currRx.var.iSrc < 0 || (Math.Abs(stdcurr - currRx.var.iSrc) > stdcurr * 0.5))
                {
                    if (retry == 0)
                    {
                        retry++;
                        stm = ACTION_STATE.INIT_FOR_SEARCH;
                        DeviceMgr.SysLog(String.Format("Incorrect current {0} vs std:{1}, bSqrt is {2}, iIx is {3}",
                                                       currRx.var.iSrc.ToString(), stdcurr.ToString(), currRx.bSqrt.ToString(), currRx.iIx.ToString()));
                    }
                    else
                    {
                        currRx.i_State = RUN_STATE.STOPPING;
                        StatusChanged(this, "stopping");
                        return;
                    }
                }
                else
                {
                    stm = act_mgr.Do(ACTION_REQUEST.SET_FOR_TRACKP, stm);
                }
                return;
            }
            #region  no use

            /*
             * if (stm == ACTION_STATE.INIT_FOR_RX_KTTP) //capture once //set to KTTP mode
             * {
             *  currRx.i_State = RUN_STATE.SEARCHING;
             *  StatusChanged(this, "search");
             *  double val = act_mgr.dStableReading;
             *  if (val < -999)
             *  {
             *      currRx.i_State = RUN_STATE.STOPPING;
             *      StatusChanged(this, "stopping");
             *      return;
             *  }
             *
             *  currRx.var.vRs = Math.Abs(currRx.var.vRs - val) / 2.0;
             *  currRx.var.iSrc = currRx.var.vRs / currRx.var.rRs;
             *  stm = act_mgr.Do(ACTION_REQUEST.SET_FOR_RX_KTTP, stm);
             *  return;
             * }
             * if (stm == ACTION_STATE.INIT_FOR_RX_KTTN)
             * {
             *  currRx.i_State = RUN_STATE.SEARCHING;
             *  StatusChanged(this, "search");
             *  double val = act_mgr.dStableReading;
             *  if (val < -999)
             *  {
             *      currRx.i_State = RUN_STATE.STOPPING;
             *      StatusChanged(this, "stopping");
             *      return;
             *  }
             *  currRx.var.vRx = val;
             *  stm = act_mgr.Do(ACTION_REQUEST.SET_FOR_RX_KTTN, stm);
             *  return;
             * }
             * if (stm == ACTION_STATE.INIT_K_ADJUST) //adjust K
             * {
             *  double val = act_mgr.dStableReading;
             *  if (val < -999)
             *  {
             *      currRx.i_State = RUN_STATE.STOPPING;
             *      StatusChanged(this, "stopping");
             *      return;
             *  }
             *
             *  currRx.var.vRx = Math.Abs(currRx.var.vRx - val)/ 2;
             *  currRx.var.rRx = currRx.var.vRx / currRx.var.iSrc;
             *
             *  currRx.var.iK = currRx.var.calc_capture_nextk();
             *  DeviceMgr.Action("turnk", Convert.ToUInt32(currRx.var.iK));
             *  stm = ACTION_STATE.INIT_FOR_TRACKP;
             * }
             */
            #endregion
            if (stm == ACTION_STATE.INIT_FOR_TRACKP) //capture once //set to KTTP mode
            {
                currRx.i_State = RUN_STATE.TRACKING;
                StatusChanged(this, "tracking");

                stm = act_mgr.Do(ACTION_REQUEST.SET_FOR_TRACKP, stm);
                return;
            }
            if (stm == ACTION_STATE.INIT_FOR_TRACKN)
            {
                currRx.i_State = RUN_STATE.TRACKING;
                StatusChanged(this, "tracking");
                double val = act_mgr.dStableReading;
                if (val < -999)
                {
                    currRx.i_State = RUN_STATE.STOPPING;
                    StatusChanged(this, "stopping");
                    return;
                }
                currRx.var.vCrossP = val;
                stm = act_mgr.Do(ACTION_REQUEST.SET_FOR_TRACKN, stm);
                return;
            }
            if (stm == ACTION_STATE.UPDATE_K_TRACK)
            {
                currRx.i_State = RUN_STATE.TRACKING;
                StatusChanged(this, "tracking");

                double val = act_mgr.dStableReading;
                if (val < -999)
                {
                    currRx.i_State = RUN_STATE.STOPPING;
                    StatusChanged(this, "stopping");
                    return;
                }
                currRx.var.vCrossN = val;

                stm = act_mgr.Do(ACTION_REQUEST.SET_NEXT_K, stm);
                if (stm == ACTION_STATE.SHOW_NEW_VALUE)
                {
                    currRx.var.log_start(currRx.iRRange);
                }
                return;
            }
            if (stm == ACTION_STATE.SHOW_NEW_VALUE)
            {
                if (data_mgr.AddNewValue(ref currRx.var.rRx))
                {
                    StatusChanged(this, "newvalue");
                }
                if (data_mgr.iMeasCnt == RunWnd.syscfg.iMeasTimes)
                {
                    stm = ACTION_STATE.COMPLETE;
                }
                else
                {
                    stm = ACTION_STATE.INIT_FOR_TRACKP;
                }
                return;
            }

            if (stm == ACTION_STATE.COMPLETE) //update the display and try the next channel
            {
                currRx.i_State = RUN_STATE.IDLE;
                bRunning       = false;
                StatusChanged(this, "complete");
                act_mgr.Do(ACTION_REQUEST.INIT_NAV_RANGE, stm);
                DeviceMgr.Reset();
                while (DeviceMgr.IsInAction())
                {
                    ;
                }
                stm = ACTION_STATE.IDLE;
            }
        }
Ejemplo n.º 2
0
        public void pc_cmd(string cmd)
        {
            DeviceMgr.SysLog(cmd);
            if (cmd == "ECHO")
            {
                DeviceMgr.Resend();
                return;
            }
            if (cmd == "S")
            {
                if (task.bRunning)
                {
                    statusBar1_StartStopClick(null, null); //click stop
                }
                return;
            }

            if (cmd == "H")
            {
                if ((!task.bRunning) && (!DeviceMgr.IsInAction()))
                {
                    DeviceMgr.Reset();//reset
                }
                return;
            }
            Match m;

            m = reg_mode.Match(cmd);
            if (m.Success)
            {
                oper_mode = m.Groups[1].Value;
                return;
            }
            m = reg_statistic.Match(cmd);
            if (m.Success)
            {
                syscfg.iFilter = Convert.ToInt32(m.Groups[1].Value);
                return;
            }
            m = reg_filter.Match(cmd);
            if (m.Success)
            {
                if (m.Groups[1].Value == "2")
                {
                    syscfg.sFilterType = "filtertype3";
                }
                else if (m.Groups[1].Value == "1")
                {
                    syscfg.sFilterType = "filtertype2";
                }
                else if (m.Groups[1].Value == "3")
                {
                    syscfg.sFilterType = "filtertype4";
                }
                else
                {
                    syscfg.sFilterType = "filtertype1";
                }
                return;
            }
            m = reg_ix.Match(cmd);
            if (m.Success)
            {
                #region current convert
                double myIx = double.Parse(m.Groups[1].Value) / 1000;
                if (myIx >= 5.5)
                {
                    Program.lst_rxinfo[0].iIx   = 5; //5A x 2
                    Program.lst_rxinfo[0].bSqrt = true;
                    return;
                }
                if (myIx >= 2.2)
                {
                    Program.lst_rxinfo[0].iIx   = 5; //5A
                    Program.lst_rxinfo[0].bSqrt = false;
                    return;
                }
                if (myIx >= 1.1)
                {
                    Program.lst_rxinfo[0].iIx   = 4; //1A x 2
                    Program.lst_rxinfo[0].bSqrt = true;
                    return;
                }
                if (myIx >= 0.66)
                {
                    Program.lst_rxinfo[0].iIx   = 4; //1A x 2
                    Program.lst_rxinfo[0].bSqrt = false;
                    return;
                }
                if (myIx >= 0.33)
                {
                    Program.lst_rxinfo[0].iIx   = 3; //0.3A x 2
                    Program.lst_rxinfo[0].bSqrt = true;
                    return;
                }
                if (myIx >= 0.22)
                {
                    Program.lst_rxinfo[0].iIx   = 3; //0.3A
                    Program.lst_rxinfo[0].bSqrt = false;
                    return;
                }
                if (myIx >= 0.11)
                {
                    Program.lst_rxinfo[0].iIx   = 2; //0.1A x 2
                    Program.lst_rxinfo[0].bSqrt = true;
                    return;
                }
                if (myIx >= 0.022)
                {
                    Program.lst_rxinfo[0].iIx   = 2; //0.1A
                    Program.lst_rxinfo[0].bSqrt = false;
                    return;
                }
                if (myIx >= 0.011)
                {
                    Program.lst_rxinfo[0].iIx   = 1; //10mA x 2
                    Program.lst_rxinfo[0].bSqrt = true;
                    return;
                }
                if (myIx >= 0.0022)
                {
                    Program.lst_rxinfo[0].iIx   = 1; //10mA
                    Program.lst_rxinfo[0].bSqrt = false;
                    return;
                }

                if (myIx >= 0.0011)
                {
                    Program.lst_rxinfo[0].iIx   = 0; //1mA x 2
                    Program.lst_rxinfo[0].bSqrt = true;
                    return;
                }
                if (myIx >= 0.00022)
                {
                    Program.lst_rxinfo[0].iIx   = 0; //1mA
                    Program.lst_rxinfo[0].bSqrt = false;
                    return;
                }
                if (myIx >= 0.00011)
                {
                    Program.lst_rxinfo[0].iIx   = -1; //0.1mA x 2
                    Program.lst_rxinfo[0].bSqrt = true;
                    return;
                }
                {
                    Program.lst_rxinfo[0].iIx   = -1; //0.1mA
                    Program.lst_rxinfo[0].bSqrt = false;
                    return;
                }
                #endregion
            }
            m = reg_delay.Match(cmd);
            if (m.Success)
            {
                syscfg.iMeasDelay = Convert.ToInt32(m.Groups[1].Value);
                return;
            }
            m = reg_meastimes.Match(cmd);
            if (m.Success)
            {
                syscfg.iMeasTimes = Convert.ToInt32(m.Groups[1].Value);
                return;
            }
            m = reg_switch.Match(cmd);
            if (m.Success)
            {
                syscfg.iKTT = Convert.ToInt32(m.Groups[1].Value);
                return;
            }
            m = reg_measure.Match(cmd);
            if (m.Success)
            {
                syscfg.iMeasTimes = Convert.ToInt32(m.Groups[1].Value);
                RsInfo rs = Program.lst_rsinfo[Program.mainwnd.selectedRs];
                RxInfo rx = Program.lst_rxinfo[Program.mainwnd.selectedRx];
                if (!task.bRunning)
                {
                    statusBar1_StartStopClick(null, null); //click start
                }
                return;
            }
            m = reg_sampletimes.Match(cmd);
            if (m.Success)
            {
                syscfg.iSampleTimes = Convert.ToInt32(m.Groups[1].Value);
                return;
            }
            m = reg_alpha.Match(cmd);
            if (m.Success)
            {
                Program.lst_rsinfo[0].iRRange = ActionMgr.RNG_INVALID;
                Program.lst_rsinfo[0].dAlpha  = Convert.ToDouble(m.Groups[1].Value);
                return;
            }
            m = reg_beta.Match(cmd);
            if (m.Success)
            {
                Program.lst_rsinfo[0].iRRange = ActionMgr.RNG_INVALID;
                Program.lst_rsinfo[0].dBeta   = Convert.ToDouble(m.Groups[1].Value);

                return;
            }
            m = reg_temp.Match(cmd);
            if (m.Success)
            {
                syscfg.dTemp = Convert.ToDouble(m.Groups[1].Value);
                return;
            }
            m = reg_rsa.Match(cmd);
            if (m.Success)
            {
                Program.lst_rsinfo[0].iRRange  = ActionMgr.RNG_INVALID;
                Program.lst_rsinfo[0].dValue   = Convert.ToDouble(m.Groups[1].Value);
                Program.lst_rxinfo[0].cStdChan = 'A';
                return;
            }
            m = reg_rsid.Match(cmd);
            if (m.Success)
            {
                Program.lst_rsinfo[0].iRRange = ActionMgr.RNG_INVALID;
                Program.lst_rsinfo[0].sSerial = m.Groups[1].Value;
                return;
            }
            m = reg_rxid.Match(cmd);
            if (m.Success)
            {
                Program.lst_rxinfo[0].sSerial = m.Groups[1].Value;
                return;
            }

            m = reg_rsb.Match(cmd);
            if (m.Success)
            {
                Program.lst_rxinfo[0].dRxInput = Convert.ToDouble(m.Groups[1].Value);
                ActionMgr.SetIxRange(0, Program.lst_rxinfo[0].dRxInput, false);
                Program.lst_rxinfo[0].cStdChan = 'B';
                return;
            }
        }