public int StartSRActionAndWait(DataSourceIdentifier dsid, SROp op, int setpt = -1, int runtime = -1) { SRControlThread srct; int res = SR.SUCCESS; if (threads.ContainsKey(dsid)) { srct = threads[dsid]; if (srct == null || !srct.IsBusy) { return(res); } try { if (setpt >= 0) { srct.SRCtrl.HVSet(setpt, runtime); } srct.op = op; // tell caller to wait, then kick the thread into action srct.callwait.Reset(); // tell the thread to go ahead srct.opgate.Set(); // caller will now wait for completion srct.callwait.Wait(srct.cts.Token); // fire the operation completed event here, consciously placed out of the executing SR service thread context srct.SROpCompletedEvent(srct.status); } catch (OperationCanceledException) { } finally { res = srct.SRCtrl.LastMeasStatus; } } return(res); }
public void SetAction(DataSourceIdentifier dsid, SROp op) { SRControlThread srct; if (threads.ContainsKey(dsid)) { srct = threads[dsid]; if (!srct.IsBusy) { return; } srct.op = op; // tell caller to wait, then kick the waiting thread into action srct.callwait.Reset(); srct.opgate.Set(); } }
public SROpCompletedEventArgs(SROp op, int statusNow, object userState) { Op = op; OpStatus = statusNow; UserState = userState; }
public void Shutdown() { op = SROp.Shutdown; CancelMe(); }
public int StartSRActionAndWait(DataSourceIdentifier dsid, SROp op, int setpt = -1, int runtime = -1) { SRControlThread srct; int res = SR.SUCCESS; if (threads.ContainsKey(dsid)) { srct = threads[dsid]; if (srct == null || !srct.IsBusy) return res; try { if (setpt >= 0) srct.SRCtrl.HVSet(setpt, runtime); srct.op = op; // tell caller to wait, then kick the thread into action srct.callwait.Reset(); // tell the thread to go ahead srct.opgate.Set(); // caller will now wait for completion srct.callwait.Wait(srct.cts.Token); // fire the operation completed event here, consciously placed out of the executing SR service thread context srct.SROpCompletedEvent(srct.status); } catch (OperationCanceledException) { } finally { res = srct.SRCtrl.LastMeasStatus; } } return res; }
// a general idea of what to do next in an SR processing sequence public static SROp NextOp(SROp thisOp, int curStatus) { SROp next = SROp.Nothing; switch (thisOp) { case SROp.Shutdown: next = SROp.Nothing; break; case SROp.Nothing: next = SROp.InitializeContext; break; case SROp.InitializeContext: next = SROp.InitializeSR; break; case SROp.InitializeSR: if (curStatus != sr_h.SR_SUCCESS) // status here is an sr.h machine code only { next = SROp.CloseSR; } else { next = SROp.StartSRDAQ; } break; case SROp.StartSRDAQ: if (curStatus != SR.MEAS_CONTINUE) // MEAS_ABORT or MEAS_TERMINATE { next = SROp.StartSRDAQ; } else { next = SROp.CloseSR; } break; case SROp.WaitForResults: if ((curStatus == SR.ZERO_COUNT_TIME) || (curStatus == SR.SR_TRY_AGAIN)) // dev note: empty cycles are eliminated by this step { next = SROp.StartSRDAQ; } else if (curStatus != SR.SUCCESS) // MEAS_ABORT or MEAS_TERMINATE { next = SROp.CloseSR; } else { next = SROp.CloseSR; } break; case SROp.CloseSR: next = SROp.Shutdown; break; } return(next); }
public void SetAction(DataSourceIdentifier dsid, SROp op) { SRControlThread srct; if (threads.ContainsKey(dsid)) { srct = threads[dsid]; if (!srct.IsBusy) return; srct.op = op; // tell caller to wait, then kick the waiting thread into action srct.callwait.Reset(); srct.opgate.Set(); } }
// a general idea of what to do next in an SR processing sequence public static SROp NextOp(SROp thisOp, int curStatus) { SROp next = SROp.Nothing; switch (thisOp) { case SROp.Shutdown: next = SROp.Nothing; break; case SROp.Nothing: next = SROp.InitializeContext; break; case SROp.InitializeContext: next = SROp.InitializeSR; break; case SROp.InitializeSR: if (curStatus != sr_h.SR_SUCCESS) // status here is an sr.h machine code only next = SROp.CloseSR; else next = SROp.StartSRDAQ; break; case SROp.StartSRDAQ: if (curStatus != SR.MEAS_CONTINUE) // MEAS_ABORT or MEAS_TERMINATE next = SROp.StartSRDAQ; else next = SROp.CloseSR; break; case SROp.WaitForResults: if ((curStatus == SR.ZERO_COUNT_TIME) || (curStatus == SR.SR_TRY_AGAIN)) // dev note: empty cycles are eliminated by this step { next = SROp.StartSRDAQ; } else if (curStatus != SR.SUCCESS) // MEAS_ABORT or MEAS_TERMINATE { next = SROp.CloseSR; } else { next = SROp.CloseSR; } break; case SROp.CloseSR: next = SROp.Shutdown; break; } return next; }
public SRControlThread(int count, LMLoggers.LognLM log, Measurement meas, Detector det) { op = SROp.Nothing; SRCtrl = new SRControl(count, log, meas, det); opgate = new ManualResetEventSlim(false); callwait = new ManualResetEventSlim(false); cts = new CancellationTokenSource(); }