Esempio n. 1
0
        private ACTION_STATE InitKI(ACTION_STATE stm)
        {
            RxInfo currRx = rx;

            SetDelays();
            currRx.var.iSrc = RunWnd.syscfg.GetCurrent(currRx.iIx, currRx.bSqrt); //0.1mA
            currRx.var.rRx  = currRx.dRxInput;
            currRx.var.iK   = RX_VAR.INIT_LOOP;
            currRx.var.iK   = currRx.var.calc_capture_nextk();

            if (currRx.iRRange == RNG_P1)   //P1 ohm
            {
                currRx.var.iK = 100;        //10:1
            }
            if (currRx.iRRange == RNG_P01)  //P01 ohm
            {
                currRx.var.iK = 10;         //100:1
            }
            if (currRx.iRRange == RNG_P001) //P001 ohm
            {
                currRx.var.iK = 1;          //1000:1
            }
            DeviceMgr.Action("turnk", Convert.ToUInt32(currRx.var.iK));
            if ((currRx.iRRange == RNG_P1) || (currRx.iRRange == RNG_P01) || (currRx.iRRange == RNG_P001))
            {
                return(ACTION_STATE.INIT_FOR_RS_KTTP);
            }
            else
            {
                return(ACTION_STATE.INIT_FOR_TRACKP);
            }
        }
Esempio n. 2
0
        private bool RangeAdjustDown(double value)
        {
            string newnav = "";

            if (RunWnd.syscfg.sNavmeter == NAV_TYPE_2182)
            {
                newnav = "navto30v";
            }
            else
            {
                newnav = "navto1v";
            }
            if (value < 1) //while < 1V
            {
                newnav = "navto1v";
            }
            if (value < 0.100) //while < 100mV)
            {
                newnav = "navto120mv";
            }
            if ((value < 0.010) && (RunWnd.syscfg.sNavmeter == NAV_TYPE_2182 || RunWnd.syscfg.sNavmeter == "PZ2182")) //while < 10mV
            {
                newnav = "navto10mv";
            }

            if (nav_range != newnav)
            {
                nav_range = newnav;
                DeviceMgr.Action(nav_range, 0);
                return(true);
            }
            return(false);
        }
Esempio n. 3
0
        static Program()
        {
            sysinfo    = new SysConfig();
            testdata   = new DataMgr();
            lst_rxinfo = new List <RxInfo>();
            lst_rsinfo = new List <RsInfo>();

            for (int i = 0; i < sysinfo.iRxCnts; i++)
            {
                lst_rxinfo.Add(new RxInfo(i + 1));
            }

            for (int i = 0; i < sysinfo.iRsCnts; i++)
            {
                lst_rsinfo.Add(new RsInfo(i + 1));
            }

            syswnd  = new SysConfigWnd();
            rxwnd   = new RxConfigWnd();
            rswnd   = new RsConfigWnd();
            mcfgwnd = new MainConfigWnd();


            DeviceMgr.Dummy();
        }
Esempio n. 4
0
 void statusBar1_StartStopClick(object sender, EventArgs e)
 {
     if (task.bRunning)
     {
         statusBar1.pause  = false;
         statusBar1.status = RUN_STATE.STOPPING;
         task.Stop();
     }
     else
     {
         RsInfo rs = Program.lst_rsinfo[Program.mainwnd.selectedRs];
         RxInfo rx = Program.lst_rxinfo[Program.mainwnd.selectedRx];
         statusBar1.total  = syscfg.iMeasTimes;
         statusBar1.count  = 1;
         statusBar1.status = RUN_STATE.INITIALIZING;
         DeviceMgr.Log(String.Format(@"==== New Measurement Paramter========
                                     Measure times = {0}\r\nRs ID = {1}\r\nRs Value = {2}\r\nRs Temp. Alpha = {3}\r\nRs Temp. Beta = {4}\r\n
                                     Temperature = {5}\r\nRx ID = {6}\r\nSample times = {7}\r\nSwitch delay = {8}\r\n
                                     Filter = {9}\r\nFilter Length = {10}\r\nMeasure delay = {12}\r\n
                                     AutoFilter = {13}\r\nRx curr. = {14}\r\n
                                     New Measurement Started...", syscfg.iMeasTimes.ToString(), rs.sSerial, rs.dValue.ToString("F8"), rs.dAlpha.ToString("F3"), rs.dBeta.ToString("F3"),
                                     syscfg.dTemp.ToString("F3"), rx.sSerial, syscfg.iSampleTimes, syscfg.iKTT,
                                     syscfg.sFilterType, syscfg.iFilter, syscfg.iMeasDelay, syscfg.bThrow, rx.iIx
                                     ));
         task.Start();
         Program.data.ClearAll();
         foreach (RxDisplay rxdisp in Enumerable.Range(1, 4).Select(x => findrx(x)))
         {
             rxdisp.ReDraw();
         }
     }
 }
Esempio n. 5
0
 public void log_start(int iRange)
 {
     DeviceMgr.SysLog(String.Format("iK={0},Scale={1},vP={2},vN={3},Curr={4},Rx={5}", iK.ToString(),
                                    Util.FormatData(RunWnd.syscfg.GetScaleAdjust(iRange), 8),
                                    Util.FormatData(vCrossP, 8),
                                    Util.FormatData(vCrossN, 8),
                                    Util.FormatData(iSrc, 8),
                                    Util.FormatData(rRx, 8)));
 }
Esempio n. 6
0
 public void LogComplete()
 {
     DeviceMgr.Log("...... Summary Begin ......");
     DeviceMgr.Log(String.Format("Rx(mean):{0}\nMax:{1}\nMin:{2}\nRx/Rs:{3}\nStdev:{4}", GetData(RXDATA_MODE.AVERAGE),
                                 GetData(RXDATA_MODE.MAX),
                                 GetData(RXDATA_MODE.MIN),
                                 GetData(RXDATA_MODE.RATIO),
                                 GetData(RXDATA_MODE.VARIANCE)));
     DeviceMgr.Log("...... Summary End ...... ");
 }
Esempio n. 7
0
 private ACTION_STATE InitNavRange(ACTION_STATE stm)
 {
     nav_range = "navto1v";
     DeviceMgr.Action(nav_range, 0);
     if (stm == ACTION_STATE.INIT_FOR_START)
     {
         return(ACTION_STATE.INIT_FOR_SEARCH);
     }
     else
     {
         return(stm);
     }
 }
Esempio n. 8
0
        private void UpdateStatusBar(object sender, string msg)
        {
            if (msg == "newvalue")
            {
                RX_VAR rv = task.currRx.var;

                AddValue(task.currRx.iChan.ToString(), task.iMeasCnt, rv.rRx, 0, 0);

                lbl_aux1.Text    = UpdateDisplayReading(aux1_mode);
                lbl_aux2.Text    = UpdateDisplayReading(aux2_mode);
                lbl_bigdisp.Text = UpdateDisplayReading(bigdisp_mode);
                DeviceMgr.ReportData(task.iMeasCnt, rv.rRx);
                LogData(task.iMeasCnt, rv.rRx);

                /*
                 * statusBar1.total = syscfg.iMeasTimes;
                 * statusBar1.count = task.iMeasCnt;
                 */
            }
            else if (msg == "complete")
            {
                if (runstate.NumOfRunsLeft > 0)
                {
                    DoNextMeasure();
                }
                else
                {
                    if (Program.sysinfo.bThrow)
                    {
                        ThrowData();
                    }
                    LogComplete();
                    bt_run.Text    = StringResource.str("start");
                    btn_menu.Label = StringResource.str("menu");
                }
            }
            else
            {
                string txt = StringResource.str(msg);
                if (txt == msg)
                {
                    MsgDlg.Show(task.currRx.var.errMsg);
                }
                else
                {
                    bt_run.Text = txt;
                }
            }
        }
Esempio n. 9
0
 public void LogComplete()
 {
     DeviceMgr.Log(String.Format(@"...... 数据汇总 开始 ......
     Rx(平均值):{0}
     最大值:    {1}
     最小值:    {2}
     Rx/Rs:     {3}
     标准差:    {4}
     不确定度:  {4}", GetData(RXDATA_MODE.AVERAGE),
                                 GetData(RXDATA_MODE.MAX),
                                 GetData(RXDATA_MODE.MIN),
                                 GetData(RXDATA_MODE.RATIO),
                                 GetData(RXDATA_MODE.VARIANCE)));
     DeviceMgr.Log("...... 数据汇总 结束 ...... ");
 }
Esempio n. 10
0
 static Program()
 {
     kbd        = new kbdWnd();
     syswnd     = new SysConfigWnd();
     rxwnd      = new RxConfigWnd();
     rswnd      = new RsConfigWnd();
     choice     = new ChoiceWnd();
     lst_rxinfo = new List <RxInfo>();
     lst_rsinfo = new List <RsInfo>();
     for (int i = 0; i < 24; i++)
     {
         lst_rxinfo.Add(new RxInfo(i + 1));
         lst_rsinfo.Add(new RsInfo(i + 1));
     }
     DeviceMgr.Dummy();
 }
Esempio n. 11
0
 public void LogComplete()
 {
     /*
      * DeviceMgr.Log(String.Format(@"...... 数据汇总 开始 ......
      * Rx(平均值):{0}
      * 最大值:    {1}
      * 最小值:    {2}
      * Rx/Rs:     {3}
      * 标准差:    {4}
      * 不确定度:  {4}", GetData(RXDATA_MODE.AVERAGE),
      *  GetData(RXDATA_MODE.MAX),
      *  GetData(RXDATA_MODE.MIN),
      *  GetData(RXDATA_MODE.RATIO),
      *  GetData(RXDATA_MODE.VARIANCE)));
      */
     DeviceMgr.Log("...... 数据汇总 结束 ...... ");
 }
Esempio n. 12
0
        public void Start()
        {
            if (!bRunning)
            {
                curr_ch        = 0;
                currRx         = Program.lst_rxinfo[curr_ch];
                currRx.var.rRs = Program.lst_rsinfo[0].dTValue;

                act_mgr.Reset();
                act_mgr.rx = currRx;
                act_mgr.rs = Program.lst_rsinfo[0];
                data_mgr.Reset();
                data_mgr.rx = currRx;
                data_mgr.rs = Program.lst_rsinfo[0];
                DeviceMgr.ReportHeader(RunWnd.syscfg.iMeasTimes);
                bRunning = true;
            }
        }
Esempio n. 13
0
        //change the new reading base on history
        public bool AddNewValue(ref double newreading)
        {
            int drop = 2;

            if (valfilter.Count == 0) //1st reading
            {
                SysConfig syscfg = RunWnd.syscfg;
                DeviceMgr.Log(String.Format(@"==== 新测量参数========
    测量次数 = {0}
    标准电阻ID = {1}
    标准电阻阻值 = {2}
    标准电阻温度系数. Alpha = {3}
    标准电阻温度系数. Beta = {4}
    温度 = {5}
    被测电阻ID = {6}
    单次采样次数 = {7}
    换向时间(秒) = {8}
    测量间隔(秒) = {9}
    电流值(A) = {10}
    滤波器 = {11}
    新测量开始...", syscfg.iMeasTimes.ToString(), rs.sSerial, rs.dValue.ToString("F8"), rs.dAlpha.ToString("F3"),
                                            rs.dBeta.ToString("F3"),
                                            syscfg.dTemp.ToString("F3"), rx.sSerial, syscfg.iSampleTimes, syscfg.iKTT,
                                            syscfg.iMeasDelay, rx.var.iSrc, syscfg.iFilter
                                            ));
            }
            valfilter.Add(newreading);
            if (valfilter.Count < 4)
            {
                return(false);
            }

            if ((RunWnd.syscfg.iFilter + drop) >= valfilter.Count)
            {
                newreading = valfilter.Skip(2).Average();
            }
            else
            {
                newreading = valfilter.Skip(valfilter.Count - RunWnd.syscfg.iFilter).Average();
            }
            iMeasCnt++;
            return(true);
        }
Esempio n. 14
0
 void UpdateStatusBar(object sender, string msg)
 {
     if (msg == "newvalue")
     {
         RX_VAR rv = task.currRx.var;
         rxDisplay1.AddValue(task.iMeasCnt, rv.rRx);
         DeviceMgr.ReportData(task.iMeasCnt, rv.rRx);
         rxDisplay1.LogData(task.iMeasCnt, rv.rRx);
         statusBar1.total = syscfg.iMeasTimes;
         statusBar1.count = task.iMeasCnt;
     }
     if (msg == "complete")
     {
         if (RunWnd.syscfg.bThrow)
         {
             rxDisplay1.ThrowData();
         }
         rxDisplay1.LogComplete();
     }
     statusBar1.status  = task.currRx.i_State;
     statusBar1.message = task.currRx.var.errMsg;
 }
Esempio n. 15
0
        public double CalibrateCurr(RxInfo rx)
        {
            double vp, vn;

            DeviceMgr.Action("turnk", rx.var.iK);
            Thread.Sleep(1000);
            while (DeviceMgr.IsInAction())
            {
                ;
            }
            DeviceMgr.Action("MEAS_RS|KTTP|" + DeviceMgr.ComposeAction(rx), 0);
            Reset();
            this.rx = rx;
            this.rs = Program.lst_rsinfo[0];
            Thread.Sleep(20000);
            bInReading = true;
            Thread.Sleep(500);
            while (IsBusy)
            {
                Thread.Sleep(1000);
            }
            vp = DeviceMgr.reading;

            DeviceMgr.Action("MEAS_RS|KTTN|" + DeviceMgr.ComposeAction(rx), 0);
            Thread.Sleep(20000);
            bInReading = true;
            Thread.Sleep(500);
            while (IsBusy)
            {
                DeviceMgr.IsInAction();
                Thread.Sleep(1000);
            }
            vn = DeviceMgr.reading;
            double val = (Math.Abs((vp - vn) / 2.0)) / rx.var.rRs;

            val = val * RX_VAR.INIT_LOOP / rx.var.iK;
            RunWnd.syscfg.SetCurrent(rx.iIx, rx.bSqrt, val);
            return(val);
        }
Esempio n. 16
0
        private void DoNextMeasure()
        {
            RsInfo rs = runstate.selectedRs.Dequeue();
            RxInfo rx = runstate.selectedRx.Dequeue();

            status = RUN_STATE.INITIALIZING;

            if (false)
            {
                SysConfig syscfg = Program.sysinfo;

                DeviceMgr.Log(String.Format(@"==== New Measurement Paramter========
                                            Measure times = {0}\r\nRs ID = {1}\r\nRs Value = {2}\r\nRs Temp. Alpha = {3}\r\nRs Temp. Beta = {4}\r\n
                                            Temperature = {5}\r\nRx ID = {6}\r\nSample times = {7}\r\nSwitch delay = {8}\r\n
                                            Filter = {9}\r\nFilter Length = {10}\r\nMeasure delay = {12}\r\n
                                            AutoFilter = {13}\r\nRx curr. = {14}\r\n
                                            New Measurement Started...", syscfg.iMeasTimes.ToString(), rs.sSerial, rs.dValue.ToString("F8"), rs.dAlpha.ToString("F3"), rs.dBeta.ToString("F3"),
                                            syscfg.dTemp.ToString("F3"), rx.sSerial, syscfg.iSampleTimes, syscfg.iKTT,
                                            syscfg.sFilterType, syscfg.iFilter, syscfg.iMeasDelay, syscfg.bThrow, rx.iIx
                                            ));
            }
            task.Start(rx, rs);
        }
Esempio n. 17
0
 private static bool tmlock = false; //lock for timer handler
 void uiTimer_Tick(object sender, EventArgs e)
 {
     if (tmlock)
     {
         return;
     }
     tmlock = true;
     if (DeviceMgr.Loaded && statusBar1.status == RUN_STATE.DISABLED)
     {
         statusBar1.status = RUN_STATE.IDLE;
     }
     if (lastcall != "")
     {
         if (lastcall == "newtime")
         {
             lastcall = "";
             Program.kbd.Init(StringResource.str("enter_newtime"), "newtime", false, KbdData);
         }
         tmlock = false;
         return;
     }
     else
     {
         if (task.bRunning)
         {
             task.Step();
             statusBar1.pause   = task.bPaused;
             statusBar1.waiting = task.waiting;
             if (!task.bRunning)
             {
                 statusBar1.status = RUN_STATE.IDLE;
                 DeviceMgr.Log("测量结束...");
             }
         }
     }
     tmlock = false;
 }
Esempio n. 18
0
        private static bool tmlock = false; //lock for timer handler
        void uiTimer_Tick(object sender, EventArgs e)
        {
            if (tmlock)
            {
                return;
            }
            tmlock = true;
            if (DeviceMgr.Loaded && status == RUN_STATE.DISABLED)
            {
                status = RUN_STATE.IDLE;
            }

            if (task.bRunning)
            {
                task.Step();
                if (!task.bRunning)
                {
                    status = RUN_STATE.IDLE;
                    DeviceMgr.Log("Measurement Stopped...");
                }
            }

            tmlock = false;
        }
Esempio n. 19
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;
            }
        }
Esempio n. 20
0
        public void pc_cmd(string cmd)
        {
            SysConfig syscfg = Program.sysinfo;

            if (cmd == "S")
            {
                task.Stop();//STOP; need reply //todo
                return;
            }
            if (cmd == "H")
            {
//                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
                {
                    syscfg.sFilterType = "filtertype1";
                }
                return;
            }
            m = reg_ix.Match(cmd);
            if (m.Success)
            {/*
              * //todo
              * if (currRx.iIx == 0) //1mA
              * if (currRx.iIx == 1) //10mA
              * if (currRx.iIx == 2) //0.1A
              * if (currRx.iIx == 3) //0.3A
              * if (currRx.iIx == 4) //1A
              * if (currRx.iIx == 5) //5A
              */
                double myIx = double.Parse(m.Groups[1].Value) / 1000;
                if (myIx >= 3)
                {
                    Program.lst_rxinfo[0].iIx = 5;
                }
                else if (myIx >= 0.65)
                {
                    Program.lst_rxinfo[0].iIx = 4;
                }
                else if (myIx >= 0.2)
                {
                    Program.lst_rxinfo[0].iIx = 3;
                }
                else if (myIx >= 0.05)
                {
                    Program.lst_rxinfo[0].iIx = 2;
                }
                else if (myIx >= 0.005)
                {
                    Program.lst_rxinfo[0].iIx = 1;
                }
                else if (myIx >= 0.0005)
                {
                    Program.lst_rxinfo[0].iIx = 0;
                }
                else
                {
                    Program.lst_rxinfo[0].iIx = -1;
                }
                return;
            }
            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_sampletimes.Match(cmd);
            if (m.Success)
            {
                syscfg.iSampleTimes = Convert.ToInt32(m.Groups[1].Value);
                return;
            }
            m = reg_measure.Match(cmd);
            if (m.Success)
            {
                syscfg.iMeasTimes = Convert.ToInt32(m.Groups[1].Value);
                Program.mainwnd.Invoke(new Action <object, EventArgs>(this.statusBar1_StartStopClick), new object[] { 0, 0 });
                //task.Start();
                return;
            }
            m = reg_rsa.Match(cmd);
            if (m.Success) //A mode
            {
                Program.lst_rsinfo[0].dValue   = Convert.ToDouble(m.Groups[1].Value);
                Program.lst_rxinfo[0].cStdChan = 'A';
                DeviceMgr.ReportHeader(syscfg.iMeasTimes);
                for (int i = 0; i < syscfg.iMeasTimes; i++)
                {
                    DeviceMgr.ReportData(i + 1, 10.01234566);
                    Thread.Sleep(1000);
                }
                return;
            }
            m = reg_rsb.Match(cmd);
            if (m.Success) //B mode
            {
                Program.lst_rsinfo[0].dValue   = Convert.ToDouble(m.Groups[1].Value);
                Program.lst_rxinfo[0].cStdChan = 'B';
                return;
            }
        }
Esempio n. 21
0
 public void LogData(int index, double value)
 {
     DeviceMgr.Log(String.Format("读数 {0} = {1}", index.ToString(), Util.FormatData(value, 8)));
 }
Esempio n. 22
0
        private void RangeAdjust()
        {
            if (DeviceMgr.IsInAction())
            {
                return;
            }
            if (!bFirstReadSent)
            {
                DeviceMgr.Action("navread", 0);
                bFirstReadSent = true;
                return;
            }
            if (RunWnd.syscfg.sNavmeter != NAV_TYPE_2182 && nav_range != "navto1v")
            {
                datafilter.Add(DeviceMgr.reading / 1000);
            }
            else
            {
                datafilter.Add(DeviceMgr.reading);
            }
            if (datafilter.Count < 4)
            {
                DeviceMgr.Action("navread", 0);
                return;
            }
            int total = datafilter.Count(x => Math.Abs(x) < 999);

            datafilter.Clear();
            if (range_dir == 1)
            {
                if (total > 0 || IsTopRange())
                {
                    range_dir = 0;
                    return;
                }
                if (RunWnd.syscfg.sNavmeter == NAV_TYPE_2182)
                {
                    if (nav_range == "navto1v")
                    {
                        nav_range = "navto30v";
                    }
                    else
                    {
                        nav_range = "navto1v";
                    }
                }
                else
                {
                    if (nav_range == "navto10mv")
                    {
                        nav_range = "navto120mv";
                    }
                    else
                    {
                        nav_range = "navto1v";
                    }
                }
                delay = 4;
                DeviceMgr.Action(nav_range, 0);
                return;
            }
            else
            {
                throw new NotImplementedException("unexpected down range");
            }
        }
Esempio n. 23
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;
            }
        }
Esempio n. 24
0
        private void CollectReading()
        {
            if (DeviceMgr.IsInAction())
            {
                return;
            }
            if (!bFirstReadSent)
            {
                DeviceMgr.Action("navread", 0);
                bFirstReadSent = true;
                return;
            }

            if (DeviceMgr.reading < -999)
            {
                badReadingCount++;
            }
            else
            {
                badReadingCount = 0;
                if (RunWnd.syscfg.sNavmeter != NAV_TYPE_2182 && nav_range != "navto1v")
                {
                    datafilter.Add(DeviceMgr.reading / 1000);
                }
                else
                {
                    datafilter.Add(DeviceMgr.reading);
                }
            }
            if (badReadingCount > 5) //to much invalid readings
            {
                dStableReading = -9999;
                bInReading     = false;
                return;
            }
            if (datafilter.Count < RunWnd.syscfg.iSampleTimes)
            {
                DeviceMgr.Action("navread", 0);
                return;
            }
            int cnt0  = 0; //count for no change
            int cnt1  = 0; //count for going up
            int cnt_1 = 0; //count for going down

            for (int i = 1; i < datafilter.Count; i++)
            {
                if (Math.Abs(datafilter[i] - datafilter[i - 1]) < 1e-12)
                {
                    cnt0++;
                }
                else if (datafilter[i] > datafilter[i - 1])
                {
                    cnt1++;
                }
                else
                {
                    cnt_1++;
                }
            }
            if ((cnt1 == datafilter.Count - 1) || (cnt_1 == datafilter.Count - 1)) //all up or all down
            {
//no jump check                datafilter.Clear();
//                return;
            }


            {
                double sqr;
                if (rx.iRRange == RNG_P001) //0.001
                {
                    sqr = GetSqrt3(10);
                }
                else if (rx.iRRange == RNG_P01) //0.01
                {
                    sqr = GetSqrt3(10);
                }
                else if (rx.iRRange == RNG_P1) //0.1
                {
                    sqr = GetSqrt3(5);
                }
                else
                {
                    sqr = GetSqrt3(3);
                }
                double avg     = datafilter.Average();
                int    removed = datafilter.RemoveAll(x => Math.Abs(x - avg) > sqr);

                string type = RunWnd.syscfg.sFilterType;

                if (type != "filtertype4" && removed > 0)
                {
                    DeviceMgr.reading = -9999; //clear the current reading
                    return;                    //not enough data now
                }

                if (type == "filtertype1")  //中位数平均值
                {
                    datafilter.Sort();
                    dStableReading = datafilter.Skip(datafilter.Count * 3 / 5).Take(datafilter.Count / 4).Average();
                    bInReading     = false;
                    return;
                }
                if (type == "filtertype2")  //最后值平均
                {
                    int len = 10;
                    dStableReading = datafilter.Skip(datafilter.Count - len).Take(len).Average();
                    bInReading     = false;
                }
                if (type == "filtertype3") //滑动滤波平均
                {
                    int len = datafilter.Count - 5;
                    if (len > 10)
                    {
                        len = 10;
                    }
                    if (len <= 0)
                    {
                        len = 2;
                    }
                    for (int i = (datafilter.Count - 1); i >= len; i--)
                    {
                        datafilter[i] = datafilter.Skip(i - len).Take(len).Average();
                    }
                    datafilter.RemoveRange(0, len);
                    datafilter.Sort();
                    dStableReading = datafilter.Skip(datafilter.Count / 3).Take(datafilter.Count / 3).Average();
                    bInReading     = false;
                }
                if (type == "filtertype4") //看分布平均
                {
                    int[]  bins = new int[] { 0, 0, 0, 0, 0 };
                    double max  = datafilter.Max();
                    double min  = datafilter.Min();
                    double step = (max - min) / (bins.Length - 2);
                    int    i;
                    foreach (double v in datafilter)
                    {
                        for (i = 0; i < bins.Length - 1; i++)
                        {
                            if (v < (min + i * step))
                            {
                                bins[i]++;
                                break;
                            }
                        }
                        if (i >= bins.Length)
                        {
                            bins[bins.Length - 1]++;
                        }
                    }

                    double bottom = -99999;
                    double top    = -9999;
                    for (i = 0; i < bins.Length - 1; i++)
                    {
                        bottom = top;
                        top    = min + i * step;
                        if (bins[i] == bins.Max())
                        {
                            break;
                        }
                    }
                    if (i == bins.Length - 1)
                    {
                        bottom = top;
                        top    = 10e9;
                    }
                    dStableReading = datafilter.Where(x => (x <= top && x >= bottom)).Average();
                    bInReading     = false;
                }

                return;
            }
            throw new NotImplementedException("unexpected action state in data processing");
        }
Esempio n. 25
0
        public ACTION_STATE Do(ACTION_REQUEST action, ACTION_STATE stm)
        {
            laststm = stm;
            if (action == ACTION_REQUEST.INIT_NAV_RANGE)
            {
                return(InitNavRange(stm));
            }
            if (action == ACTION_REQUEST.INITKI_FOR_SEARCH)
            {
                delay = 2;
                return(InitKI(stm));
            }

            if (action == ACTION_REQUEST.SET_FOR_RS_KTTP)
            {
                DeviceMgr.Action("MEAS_RS|KTTP|" + DeviceMgr.ComposeAction(rx), 0);
                range_dir  = 1;
                delay      = delayKI;
                bInReading = true;
                return(ACTION_STATE.INIT_FOR_RS_KTTN);
            }
            if (action == ACTION_REQUEST.SET_FOR_RS_KTTN)
            {
                DeviceMgr.Action("MEAS_RS|KTTN|" + DeviceMgr.ComposeAction(rx), 0);
                range_dir  = 1;
                delay      = delayKTT;
                bInReading = true;

                return(ACTION_STATE.COMPLETE_ISRC);
            }

            /*
             * if (action == ACTION_REQUEST.SET_FOR_RX_KTTP)
             * {
             *  DeviceMgr.Action("MEAS_RX|KTTP|" + DeviceMgr.ComposeAction(rx), 0);
             *  range_dir = 1;
             *  delay = delayKI;
             *  bInReading = true;
             *  return ACTION_STATE.INIT_FOR_RX_KTTN;
             * }
             * if (action == ACTION_REQUEST.SET_FOR_RX_KTTN)
             * {
             *  DeviceMgr.Action("MEAS_RX|KTTN|" + DeviceMgr.ComposeAction(rx), 0);
             *  range_dir = 1;
             *  delay = delayKTT;
             *  bInReading = true;
             *  return ACTION_STATE.INIT_FOR_TRACKP;
             * }
             */
            if (action == ACTION_REQUEST.SET_FOR_TRACKP)
            {
                DeviceMgr.Action("MEAS_DELTA|KTTP|" + DeviceMgr.ComposeAction(rx), 0);
                delay      = RunWnd.syscfg.iKTT; //adjust delay
                range_dir  = 1;
                bInReading = true;
                return(ACTION_STATE.INIT_FOR_TRACKN);
            }
            if (action == ACTION_REQUEST.SET_FOR_TRACKN)
            {
                if (RangeAdjustDown(Math.Abs(rx.var.vCrossP)))
                {
                    range_dir  = 1;
                    delay      = 2;
                    bInReading = false;
                    return(ACTION_STATE.INIT_FOR_TRACKP);
                }

                DeviceMgr.Action("MEAS_DELTA|KTTN|" + DeviceMgr.ComposeAction(rx), 0);
                delay      = RunWnd.syscfg.iKTT; //adjust delay
                range_dir  = 1;
                bInReading = true;
                return(ACTION_STATE.UPDATE_K_TRACK);
            }
            if (action == ACTION_REQUEST.SET_NEXT_K)
            {
                /*
                 * if (RangeAdjustDown(Math.Max(Math.Abs(rx.var.vCrossP), Math.Abs(rx.var.vCrossN))))
                 * {
                 *  range_dir = 1;
                 *  delay = 2;
                 *  bInReading = false;
                 *  return ACTION_STATE.INIT_FOR_TRACKP;
                 * }
                 */
                if ((rx.iRRange == RNG_P1) || (rx.iRRange == RNG_P01) || (rx.iRRange == RNG_P001))  //P1 ohm, P01 ohm, P001 ohm
                {
                    rx.var.calc_track_nextk(rx.iRRange);
                    return(ACTION_STATE.SHOW_NEW_VALUE);
                }
                int newN = rx.var.calc_track_nextk(rx.iRRange) - rx.var.iK;
                if (newN == 0)
                {
                    return(ACTION_STATE.SHOW_NEW_VALUE);
                }
                if ((!history_newk.ContainsKey(rx.var.iK)) || (history_newk[rx.var.iK] != newN)) //a different decision
                {
                    history_newk[rx.var.iK] = newN;
                    rx.var.iK += newN;
                    DeviceMgr.Action("turnk", rx.var.iK);
                    return(ACTION_STATE.INIT_FOR_TRACKP);
                }
                if (history_newk.ContainsKey(rx.var.iK + newN)) //it has an old decision
                {
                    int oldnewN = history_newk[rx.var.iK + newN];
                    if ((oldnewN + newN) == 0)   //just jump up and down
                    {
                        return(ACTION_STATE.SHOW_NEW_VALUE);
                    }
                    rx.var.iK += newN;
                    DeviceMgr.Action("turnk", rx.var.iK);
                    return(ACTION_STATE.INIT_FOR_TRACKP);
                }
                return(ACTION_STATE.SHOW_NEW_VALUE);
            }
            return(ACTION_STATE.IDLE);
        }