public void ResetControlVars() { HVSteps = new List <HVStatus>(); xp = null; hvp = IntegrationHelpers.GetCurrentHVCalibrationParams(NC.App.Opstate.Measurement.Detector); hvCalibPoint = hvMinCalibPoint = hvp.MinHV; // starting point for stepping hvMaxCalibPoint = hvp.MaxHV; hvStep = hvp.Step; hvDelayms = hvp.DelayMS; if (hvp.HVDuration < hvp.DelayMS / 1000) // seconds to milliseconds { hvp.DelayMS = (hvp.HVDuration / 1000) + 1000; hvDelayms = hvp.DelayMS; ctrllog.TraceEvent(LogLevels.Warning, 604, "HV delay modified to {0} milliseconds because the HV cycle duration ({1} sec) must be less than HV delay", hvp.DelayMS, hvp.HVDuration); } hvx = NC.App.Opstate.Measurement.AcquireState.lm.HVX; // excel monitor flag }
public void ResetControlVars() { HVSteps = new List<HVStatus>(); xp = null; hvp = IntegrationHelpers.GetCurrentHVCalibrationParams(NC.App.Opstate.Measurement.Detector); hvCalibPoint = hvMinCalibPoint = hvp.MinHV; // starting point for stepping hvMaxCalibPoint = hvp.MaxHV; hvStep = hvp.Step; hvDelayms = hvp.DelayMS; if (hvp.HVDuration < hvp.DelayMS / 1000) // seconds to milliseconds { hvp.DelayMS = (hvp.HVDuration/1000) + 1000; hvDelayms = hvp.DelayMS; ctrllog.TraceEvent(LogLevels.Warning, 604, "HV delay modified to {0} milliseconds because the HV cycle duration ({1} sec) must be less than HV delay", hvp.DelayMS, hvp.HVDuration); } hvx = NC.App.Opstate.Measurement.AcquireState.lm.HVX; // excel monitor flag }
// meant to support SR and LM public bool HVCalibRun() { // only for first active instrument. Instrument inst = Instruments.Active.FirstActive(); if (inst == null) { ctrllog.TraceInformation("No active instruments for HV calibration. . ."); return(false); } if (hvx) { if (xp == null) { if (ExcelPush.ExcelPresent(ctrllog)) { xp = new HVExcel(ctrllog); xp.ShowWB(); xp.AddHeaderRow(typeof(SimpleHVReport.HVVals)); } } } instId = inst.id.DetectorId + "-" + inst.id.SRType.ToString(); bool res = true; if (hvCalibPoint <= hvMaxCalibPoint) { // todo: catch spurious exceptions and return false if (DAQControl.CurState.IsQuitRequested) // leave and do not finish calibration { ctrllog.TraceInformation("HV calibration cancelled"); inst.DAQState = DAQInstrState.Online; DAQControl.CurState.State = DAQInstrState.Online; ctrllog.Flush(); DAQControl.gControl.MajorOperationCompleted(); // causes pending control thread caller to move forward inst.PendingComplete(); // each instr must complete for the waitall to move forward } else { if (inst.id.SRType.IsListMode()) { if (inst.id.SRType == InstrType.PTR32 || inst.id.SRType == InstrType.MCA527) { Thread.Sleep(hvDelayms); // wait for HV to settle, nominally 2 seconds inst.StartHVCalibration(hvCalibPoint, TimeSpan.FromSeconds(hvp.HVDuration)); } else if (inst.id.SRType == InstrType.LMMM) { int LM = control.FirstActiveIndexOf(inst); DAQControl.LMMMComm.FormatAndSendLMMMCommand(LMMMLingo.Tokens.hvprep, hvCalibPoint, LM); Thread.Sleep(hvDelayms); // wait for HV to settle, nominally 2 seconds DAQControl.LMMMComm.FormatAndSendLMMMCommand(LMMMLingo.Tokens.hvcalib, 0, LM); } } else { // (re)init the SR int status = 0; if (hvCalibPoint == hvMinCalibPoint) // starting point { status = control.SRWrangler.StartSRActionAndWait(inst.id, SRTakeDataHandler.SROp.InitializeSR, hvCalibPoint, hvp.HVDuration); } else // reinit the SR to the next step up in the plateaux { status = control.SRWrangler.StartSRActionAndWait(inst.id, SRTakeDataHandler.SROp.ReInitializeSR, hvCalibPoint, hvp.HVDuration); } if (status == INCCSR.SUCCESS || status == INCCSR.MEAS_CONTINUE) { // do the run status = control.SRWrangler.StartSRActionAndWait(inst.id, SRTakeDataHandler.SROp.StartSRDAQ); // NEXT: check if pending here is going to be an issue if (status == INCCSR.MEAS_CONTINUE) // the SR started { control.SRWrangler.SetAction(inst.id, SRTakeDataHandler.SROp.WaitForResults); // event handler will pick up results when the internal timer polling in the thread detects results and fires the event } } else { res = false; } } control.FireEvent(ActionEvents.EventType.ActionInProgress, control); hvCalibPoint += hvStep; } } else // we are done { ctrllog.TraceInformation("HV calibration complete. . ."); inst.DAQState = DAQInstrState.Online; DAQControl.CurState.State = DAQInstrState.Online; ctrllog.Flush(); DAQControl.gControl.MajorOperationCompleted(); // causes pending control thread caller to move forward inst.PendingComplete(); // each instr must complete for the waitall to move forward } return(res); }
// meant to support SR and LM public bool HVCalibRun() { // only for first active instrument. Instrument inst = Instruments.Active.FirstActive(); if (inst == null) { ctrllog.TraceInformation("No active instruments for HV calibration. . ."); return false; } if (hvx) { if (xp == null) { if (ExcelPush.ExcelPresent(ctrllog)) { xp = new HVExcel(ctrllog); xp.ShowWB(); xp.AddHeaderRow(typeof(SimpleHVReport.HVVals)); } } } instId = inst.id.DetectorId + "-" + inst.id.SRType.ToString(); bool res = true; if (hvCalibPoint <= hvMaxCalibPoint) { // todo: catch spurious exceptions and return false if (DAQControl.CurState.IsQuitRequested) // leave and do not finish calibration { ctrllog.TraceInformation("HV calibration cancelled"); inst.DAQState = DAQInstrState.Online; DAQControl.CurState.State = DAQInstrState.Online; ctrllog.Flush(); DAQControl.gControl.MajorOperationCompleted(); // causes pending control thread caller to move forward inst.PendingComplete(); // each instr must complete for the waitall to move forward } else { if (inst.id.SRType.IsListMode()) { if (inst.id.SRType == InstrType.PTR32 || inst.id.SRType == InstrType.MCA527) { Thread.Sleep(hvDelayms); // wait for HV to settle, nominally 2 seconds inst.StartHVCalibration(hvCalibPoint, TimeSpan.FromSeconds(hvp.HVDuration)); } else if (inst.id.SRType == InstrType.LMMM) { int LM = control.FirstActiveIndexOf(inst); DAQControl.LMMMComm.FormatAndSendLMMMCommand(LMMMLingo.Tokens.hvprep, hvCalibPoint, LM); Thread.Sleep(hvDelayms); // wait for HV to settle, nominally 2 seconds DAQControl.LMMMComm.FormatAndSendLMMMCommand(LMMMLingo.Tokens.hvcalib, 0, LM); } } else { // (re)init the SR int status = 0; if (hvCalibPoint == hvMinCalibPoint) // starting point status = control.SRWrangler.StartSRActionAndWait(inst.id, SRTakeDataHandler.SROp.InitializeSR, hvCalibPoint, hvp.HVDuration); else // reinit the SR to the next step up in the plateaux status = control.SRWrangler.StartSRActionAndWait(inst.id, SRTakeDataHandler.SROp.ReInitializeSR, hvCalibPoint, hvp.HVDuration); if (status == INCCSR.SUCCESS || status == INCCSR.MEAS_CONTINUE) { // do the run status = control.SRWrangler.StartSRActionAndWait(inst.id, SRTakeDataHandler.SROp.StartSRDAQ); // NEXT: check if pending here is going to be an issue if (status == INCCSR.MEAS_CONTINUE) // the SR started { control.SRWrangler.SetAction(inst.id, SRTakeDataHandler.SROp.WaitForResults); // event handler will pick up results when the internal timer polling in the thread detects results and fires the event } } else res = false; } control.FireEvent(ActionEvents.EventType.ActionInProgress, control); hvCalibPoint += hvStep; } } else // we are done { ctrllog.TraceInformation("HV calibration complete. . ."); inst.DAQState = DAQInstrState.Online; DAQControl.CurState.State = DAQInstrState.Online; ctrllog.Flush(); DAQControl.gControl.MajorOperationCompleted(); // causes pending control thread caller to move forward inst.PendingComplete(); // each instr must complete for the waitall to move forward } return res; }