本文整理汇总了C#中Controller.RequestStop方法的典型用法代码示例。如果您正苦于以下问题:C# Controller.RequestStop方法的具体用法?C# Controller.RequestStop怎么用?C# Controller.RequestStop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Controller
的用法示例。
在下文中一共展示了Controller.RequestStop方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SealLeak
public void SealLeak(
[Values(10000, 20000, 50000)] double sampleRate
)
{
Converters.Clear();
Converters.Register("V", "V",
// just an identity conversion for now, to pass Validate()
(IMeasurement m) => m);
HekaDAQInputStream.RegisterConverters();
HekaDAQOutputStream.RegisterConverters();
Assert.That(HekaDAQController.AvailableControllers().Count(), Is.GreaterThan(0));
foreach (var daq in HekaDAQController.AvailableControllers())
{
const double epochDuration = 10; //s
//Configure DAQ
daq.InitHardware();
try
{
daq.SampleRate = new Measurement((decimal)sampleRate, "Hz");
var controller = new Controller();
controller.Clock = daq.Clock;
controller.DAQController = daq;
const decimal expectedBackgroundVoltage = 3.2m;
var expectedBackground = new Measurement(expectedBackgroundVoltage, "V");
var dev0 = new UnitConvertingExternalDevice("Device0", "Manufacturer", controller, expectedBackground)
{
MeasurementConversionTarget = "V",
Clock = daq.Clock,
OutputSampleRate = daq.SampleRate,
InputSampleRate = daq.SampleRate
};
dev0.BindStream(daq.GetStreams("ao0").First() as IDAQOutputStream);
dev0.BindStream(daq.GetStreams("ai0").First() as IDAQInputStream);
controller.DiscardedEpoch += (c, args) => Console.WriteLine("Discarded epoch: " + args.Epoch);
// Setup Epoch
var e = new Epoch("HekaIntegration");
HekaDAQController cDAQ = daq;
var stim = new DelegatedStimulus("TEST_ID", "V", cDAQ.SampleRate, new Dictionary<string, object>(),
(parameters, duration) =>
DataForDuration(duration, cDAQ.SampleRate),
parameters => Option<TimeSpan>.None()
);
e.Stimuli[dev0] = stim;
e.Backgrounds[dev0] = new Background(expectedBackground, daq.SampleRate);
//Run single epoch
var fakeEpochPersistor = new FakeEpochPersistor();
new TaskFactory().StartNew(() =>
{
Thread.Sleep(TimeSpan.FromSeconds(epochDuration));
controller.RequestStop();
},
TaskCreationOptions.LongRunning
);
controller.RunEpoch(e, fakeEpochPersistor);
}
finally
{
if (daq.IsHardwareReady)
daq.CloseHardware();
}
}
}
示例2: RunEpochShouldRespectEpochWaitForTrigger
public void RunEpochShouldRespectEpochWaitForTrigger()
{
var c = new Controller();
var daq = new SimpleDAQController();
daq.Clock = new SystemClock();
c.DAQController = daq;
var e = new Epoch(UNUSED_PROTOCOL) { ShouldWaitForTrigger = true };
new TaskFactory().StartNew(() =>
{
Thread.Sleep(TimeSpan.FromSeconds(1));
c.RequestStop();
},
TaskCreationOptions.LongRunning);
c.RunEpoch(e, new FakeEpochPersistor());
Assert.IsTrue(daq.WaitedForTrigger);
}
示例3: ContinuousAcquisition
public void ContinuousAcquisition(
[Values(1000, 10000, 20000, 50000)] double sampleRate,
[Values(20)] int nEpochs)
{
Converters.Clear();
HekaDAQInputStream.RegisterConverters();
HekaDAQOutputStream.RegisterConverters();
Assert.That(HekaDAQController.AvailableControllers().Count(), Is.GreaterThan(0));
foreach (var daq in HekaDAQController.AvailableControllers())
{
const double epochDuration = 1; //s
try
{
daq.InitHardware();
daq.SampleRate = new Measurement((decimal)sampleRate, "Hz");
var controller = new Controller { Clock = daq.Clock, DAQController = daq };
var dev0 = new UnitConvertingExternalDevice("Device0", "Manufacturer", controller, new Measurement(0, "V"))
{
MeasurementConversionTarget = "V",
Clock = daq.Clock,
OutputSampleRate = daq.SampleRate,
InputSampleRate = daq.SampleRate
};
dev0.BindStream((IDAQOutputStream)daq.GetStreams("ao0").First());
dev0.BindStream((IDAQInputStream)daq.GetStreams("ai0").First());
var dev1 = new UnitConvertingExternalDevice("Device1", "Manufacturer", controller, new Measurement(0, "V"))
{
MeasurementConversionTarget = "V",
Clock = daq.Clock,
OutputSampleRate = daq.SampleRate,
InputSampleRate = daq.SampleRate
};
dev1.BindStream((IDAQOutputStream)daq.GetStreams("ao1").First());
dev1.BindStream((IDAQInputStream)daq.GetStreams("ai1").First());
var nDAQStarts = 0;
daq.Started += (evt, args) =>
{
nDAQStarts++;
};
var completedEpochs = new Queue<Epoch>();
controller.CompletedEpoch += (evt, args) =>
{
completedEpochs.Enqueue(args.Epoch);
if (completedEpochs.Count >= nEpochs)
{
controller.RequestStop();
}
};
var epochs = new Queue<Epoch>();
var nSamples = (int)TimeSpan.FromSeconds(epochDuration).Samples(daq.SampleRate);
// Triangle wave
var data = Enumerable.Range(0, nSamples/2)
.Select(k => new Measurement(k/(nSamples/2.0/10.0), "V") as IMeasurement)
.ToList();
var stimData = data.Concat(Enumerable.Reverse(data)).ToList();
var fakeEpochPersistor = new FakeEpochPersistor();
bool start = true;
for (int j = 0; j < nEpochs; j++)
{
var e = new Epoch("HekaIntegration" + j);
e.Stimuli[dev0] = new RenderedStimulus("Stim",
new Dictionary<string, object>(),
new OutputData(stimData, daq.SampleRate));
e.Responses[dev0] = new Response();
e.SetBackground(dev1, new Measurement(1, "V"), daq.SampleRate);
e.Responses[dev1] = new Response();
epochs.Enqueue(e);
controller.EnqueueEpoch(e);
if (start)
{
controller.StartAsync(fakeEpochPersistor);
start = false;
}
}
while (controller.IsRunning)
{
Thread.Sleep(1);
}
controller.WaitForCompletedEpochTasks();
var stopTime = controller.Clock.Now;
//.........这里部分代码省略.........
示例4: RunEpochShouldDiscardEpochWhenRequestStopCalled
public void RunEpochShouldDiscardEpochWhenRequestStopCalled()
{
Converters.Register("V", "V",
// just an identity conversion for now, to pass Validate()
(IMeasurement m) => m);
var c = new Controller { DAQController = new SimpleDAQController2() };
c.DAQController.Clock = c.DAQController as IClock;
var sampleRate = new Measurement(1, "Hz");
var e = new Epoch(UNUSED_PROTOCOL);
var dev1 = new UnitConvertingExternalDevice("dev1", "co", c, new Measurement(0, "V"))
{
MeasurementConversionTarget = "V",
Clock = c.Clock,
OutputSampleRate = sampleRate
};
var outStream = new DAQOutputStream("out")
{
MeasurementConversionTarget = "V",
Clock = c.Clock
};
dev1.BindStream(outStream);
e.Stimuli[dev1] = new DelegatedStimulus("ID1", "units", sampleRate, new Dictionary<string, object>(),
(parameters, duration) =>
new OutputData(new List<IMeasurement>(), sampleRate, false),
objects => Option<TimeSpan>.None());
bool epochDiscarded = false;
c.DiscardedEpoch += (sender, args) =>
{
epochDiscarded = true;
};
c.DAQController.ProcessIteration += (o, eventArgs) =>
{
Console.WriteLine("Process iteration");
c.RequestStop();
};
c.RunEpoch(e, new FakeEpochPersistor());
Assert.True(epochDiscarded);
}