PicoScope 7 Software
Available on Windows, Mac and Linux
Code: Select all
timebase = 20000;
CollectBlockImmediate(timebase, 1000, channel);
----
public void CollectBlockImmediate(uint timebase, uint samples, int channel)
{
try
{
SetDefaults();
SetTrigger(null, 0, null, 0, null, null, 0, 0, 0);
_timebase = timebase;
BlockDataHandler(0, samples, 2, channel); //is the same on SDK example.
}
catch (Exception ex)
{
System.Console.WriteLine(ex.Message);
}
}
Code: Select all
timebase = 20000;
_channelSettings[0].range = Imports.Range.Range_20V;
CollectBlockImmediate(timebase, 100, 0);
---
public void CollectBlockImmediate(uint timebase, uint samples, int channel)
{
try
{
SetDefaults();
SetTrigger(null, 0, null, 0, null, null, 0, 0, 0);
_timebase = timebase;
BlockDataHandler(0, samples, 2, channel);
}
catch (Exception ex)
{
System.Console.WriteLine(ex.Message);
}
}
void BlockDataHandler(int offset, uint samples, int type, int channel)
{
uint status;
uint sampleCount = samples;
ushort segmentIndex = 0;
int i = 0;
PinnedArray[] minPinned = new PinnedArray[_channelCount];
PinnedArray[] maxPinned = new PinnedArray[_channelCount];
int timeIndisposed;
short[] minBuffers = new short[sampleCount];
short[] maxBuffers = new short[sampleCount];
minPinned[channel] = new PinnedArray(minBuffers);
maxPinned[channel] = new PinnedArray(maxBuffers);
try
{
//status = Imports.SetDataBuffers(_handle, (Imports.Channel)channel, maxBuffers, minBuffers, (int)sampleCount, segmentIndex, Imports.RatioMode.Average);
status = Imports.SetDataBuffers(handle, (Imports.Channel)channel, maxBuffers, minBuffers, (int)sampleCount, segmentIndex, Imports.RatioMode.None);
if (status != Imports.PICO_OK)
{
}
int maxSamples;
while (Imports.GetTimebase(handle, _timebase, (int)sampleCount, out timeInterval, _oversample, out maxSamples, 0) != 0)
{
_timebase++;
}
/* Start it collecting, then wait for completion*/
_ready = false;
_callbackDelegate = BlockCallback;
status = Imports.RunBlock(handle, 0, (int)sampleCount, _timebase, _oversample, out timeIndisposed, 0, _callbackDelegate, IntPtr.Zero);
Thread.Sleep(300);
int countRetry = 0;
while ((!_ready) && (countRetry < 10))
{
Thread.Sleep(1);
countRetry++;
}
Imports.Stop(handle);
if (_ready)
{
short overflow;
uint startIndex = 0;
uint downSampleRatio = 0;
int numR = 0;
status = 10;
long sumValueVoltage = 0;
while ((status != 0) && (numR < 3))
{
Application.DoEvents();
status = Imports.GetValues(handle, startIndex, ref sampleCount, downSampleRatio, Imports.RatioMode.None, segmentIndex, out overflow);
numR++;
}
if (status == (short)Imports.PICO_OK)
{
try
{
if (type == 0)
{
for (i = 0; i < sampleCount; i++)
{
mVReadPeriod[i] = adc_to_mv(maxPinned[channel].Target[i], (int)_channelSettings[(int)(channel)].range);
minVoltageRead = mVReadPeriod.Min();
maxVoltageRead = mVReadPeriod.Max();
}
}
if (type == 1)
{
for (i = 0; i < sampleCount; i++)
{
mVReadTFallTRis[i] = adc_to_mv(maxPinned[channel].Target[i], (int)_channelSettings[(int)(channel)].range);
}
}
if (type == 2)
{
for (i = 0; i < sampleCount; i++)
{
mVReadPeriod[i] = adc_to_mv(maxPinned[channel].Target[i], (int)_channelSettings[(int)(channel)].range);
sumValueVoltage += adc_to_mv(maxPinned[channel].Target[i], (int)_channelSettings[(int)(channel)].range);
}
averageVoltageValue = (int)(sumValueVoltage / sampleCount);
}
}
catch (Exception ex)
{
System.Console.WriteLine(ex.Message);
}
}
}
Imports.Stop(handle);
foreach (PinnedArray p in minPinned)
{
if (p != null)
p.Dispose();
}
foreach (PinnedArray p in maxPinned)
{
if (p != null)
p.Dispose();
}
}
catch (Exception ex)
{
System.Console.WriteLine(ex.Message);
}
}
Code: Select all
SetDefaults();