PicoScope 7 Software
Available on Windows, Mac and Linux
Code: Select all
status = (PICO_INFO)Imports.RunStreaming(_handle, ref sampleInterval, sampleTimeUnits, maxPreTriggerSamples, maxPostTriggerSamples, setAutoStop, downSampleRatio, Imports.DownSamplingMode.None, (uint)tempBufferSize);
Code: Select all
void StreamDataHandler(uint preTrigger)
{
DateTime start, stop, curr;
int numberOfLoops = 0, counter = 0;
int tempBufferSize = 1024 * 100; /* *100 is to make sure buffer large enough */
appBuffers = new short[_channelCount * 2][];
buffers = new short[_channelCount * 2][];
short setAutoStop = 0; // before it was 1
uint totalSamples = 0;
uint triggeredAt = 0;
uint sampleInterval = 1;
uint downSampleRatio = 1;
uint status;
uint maxPostTriggerSamples = uint.MaxValue; // 1000000 - preTrigger;
uint minPostTriggerSamples = uint.MaxValue; // will replace preTrigger
maxPostTriggerSamples = 4294960000; // maxPostTriggerSamples;
minPostTriggerSamples = 4294960000; // minPostTriggerSamples;
// Use Pinned Arrays for the application buffers
PinnedArray[] appBuffersPinned = new PinnedArray[_channelCount * 2];
for (int ch = 0; ch < _channelCount * 2; ch += 2) // create data buffers
{
if (_channelSettings[ch / 2].enabled == true)
{
buffers[ch] = new short[tempBufferSize];
buffers[ch + 1] = new short[tempBufferSize];
appBuffers[ch] = new short[tempBufferSize];
appBuffers[ch + 1] = new short[tempBufferSize];
appBuffersPinned[ch] = new PinnedArray(appBuffers[ch]);
appBuffersPinned[ch + 1] = new PinnedArray(appBuffers[ch + 1]);
status = Imports.SetDataBuffers(_handle, (Imports.Channel)(ch / 2), buffers[ch], buffers[ch + 1], tempBufferSize, 0, Imports.DownSamplingMode.None);
}
}
Console.WriteLine("Waiting for trigger...Press a key to abort");
_autoStop = false;
status = Imports.RunStreaming(_handle, ref sampleInterval, Imports.ReportedTimeUnits.MicroSeconds, minPostTriggerSamples, maxPostTriggerSamples, setAutoStop, downSampleRatio,
Imports.DownSamplingMode.None, (uint)tempBufferSize);
Console.WriteLine("Run Streaming : {0} ", status);
Console.WriteLine("Streaming data...Press a key to abort");
TextWriter writer = new StreamWriter("stream.txt", false);
//writer.Write("For each of the enabled Channels, results shown are....");
//writer.WriteLine();
//writer.WriteLine("Maximum Aggregated value ADC Count & mV, Minimum Aggregated value ADC Count & mV");
//writer.WriteLine();
writer.WriteLine("Started" + DateTime.Now.ToLongTimeString() + "." + DateTime.Now.Millisecond + "\t");
writer.Write("Time1\t\t\tidx\tsc\t");
for (int ch = 0; ch < _channelCount; ch++)
{
if (_channelSettings[ch].enabled)
{
writer.Write("Ch Max ADC Max mV Min ADC Min mV ");
}
}
writer.WriteLine();
while (!_autoStop && !Console.KeyAvailable)
{
// changed by @uk
numberOfLoops++;
/* Poll until data is received. Until then, GetStreamingLatestValues wont call the callback */
Thread.Sleep(0);
_ready = false;
start = DateTime.Now;
status = Imports.GetStreamingLatestValues(_handle, StreamingCallback, IntPtr.Zero);
stop = DateTime.Now;
Console.Write((status > 0 && status != 39 /*PICO_BUSY*/) ? "Status = {0}\n" : "", status);
if (_ready && _sampleCount > 0) /* can be ready and have no data, if autoStop has fired */
{
if (_trig > 0)
{
triggeredAt = (uint)totalSamples + _trigAt;
}
totalSamples += (uint) _sampleCount;
Console.Write("\nCollected {0,4} samples, index = {1,5}, Total = {2,5}", _sampleCount, _startIndex, totalSamples);
if (_trig > 0)
{
Console.Write("\tTrig at Index {0}", triggeredAt);
}
curr = start;
for (uint i = _startIndex; i < (_startIndex + _sampleCount); i++)
{
// changed by @uk
counter++;
curr = curr.AddMilliseconds(1);
writer.Write("[" + counter + "]\t" + curr.ToLongTimeString() + "." + curr.Millisecond + "\t");
writer.Write(numberOfLoops + "\t" + i + "\t" + _sampleCount + "\t");
for (int ch = 0; ch < _channelCount * 2; ch += 2)
{
if (_channelSettings[ch / 2].enabled)
{
writer.Write("Ch{0} {1,7} {2,7} {3,7} {4,7} ",
(char)('A' + (ch / 2)),
appBuffersPinned[ch].Target[i],
adc_to_mv(appBuffersPinned[ch].Target[i], (int)_channelSettings[(int)(Imports.Channel.CHANNEL_A + (ch / 2))].range),
appBuffersPinned[ch + 1].Target[i],
adc_to_mv(appBuffersPinned[ch + 1].Target[i], (int)_channelSettings[(int)(Imports.Channel.CHANNEL_A + (ch / 2))].range));
}
}
writer.WriteLine();
}
}
}
if (Console.KeyAvailable)
{
Console.ReadKey(true); // clear the key
}
writer.WriteLine("Stopped : " + DateTime.Now.ToLongTimeString() + "." + DateTime.Now.Millisecond + "\t");
Imports.Stop(_handle);
writer.Close();
if (!_autoStop)
{
Console.WriteLine();
Console.WriteLine("Data collection aborted - press any key to continue.");
WaitForKey();
}
}
Code: Select all
[DllImport(_DRIVER_FILENAME, EntryPoint = "ps4000aRunStreaming", SetLastError = true)]
public static extern UInt32 RunStreaming(
short handle,
ref uint sampleInterval,
ReportedTimeUnits sampleIntervalTimeUnits,
uint maxPreTriggerSamples,
uint maxPostPreTriggerSamples,
short autoStop,
uint downSampleRatio,
DownSamplingMode downSamplingRatioMode,
uint overviewBufferSize);