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); }
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); }