PicoScope 7 Software
Available on Windows, Mac and Linux
Code: Select all
while (true)
{
_ready = false;
_callbackDelegate = BlockCallback;
stopwatchDataAcqDuration.Restart();
do
{
retry = false;
status = Imports.RunBlock(_handle, 0, (int)sampleCount, _timebase, out timeIndisposed, 0, _callbackDelegate, IntPtr.Zero);
if (status == (short)StatusCodes.PICO_POWER_SUPPLY_CONNECTED || status == (short)StatusCodes.PICO_POWER_SUPPLY_NOT_CONNECTED || status == (short)StatusCodes.PICO_POWER_SUPPLY_UNDERVOLTAGE)
{
status = Imports.ChangePowerSource(_handle, status);
retry = true;
}
else
{
//textMessage.AppendText("Run Block Called\n");
}
}
while (retry);
while (!_ready)
{
//Thread.Sleep(100);
}
if (_ready)
{
short overflow;
status = Imports.GetValues(_handle, 0, ref sampleCount, 1, Imports.DownSamplingMode.None, 0, out overflow);
if (status == (short)StatusCodes.PICO_OK)
{
System.Diagnostics.Debug.Print(stopwatchDataAcqDuration.ElapsedMilliseconds.ToString());
}
else
{
//textMessage.AppendText("No Data\n");
}
}
else
{
//textMessage.AppendText("data collection aborted\n");
}
}
});
Code: Select all
public void getBlockData()
{
uint status;
//---------------------------------------------------------------------------------------------------------------------------------
//********************************* Initialize signal gen *************************************************
//---------------------------------------------------------------------------------------------------------------------------------
try
{
startFreq = Convert.ToDouble("13560000");
pkToPk = Convert.ToUInt32("2000") * 1000;
offset = Convert.ToInt32("0");
}
catch
{
MessageBox.Show("Error with start frequency, offset and/or pktopk", "INVALID VALUES", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
stopFreq = startFreq;
increment = 0;
dwellTime = 0;
sweeptype = Imports.SweepType.PS5000A_UP;
Imports.WaveType wavetype = Imports.WaveType.PS5000A_SINE;
if (wavetype == Imports.WaveType.PS5000A_DC_VOLTAGE)
{
pkToPk = 0;
}
status = Imports.SetSigGenBuiltInV2(_handle, offset, pkToPk, wavetype, startFreq, stopFreq, increment, dwellTime, sweeptype,
operations, shots, sweeps, triggertype, triggersource, extinthreshold);
if (status != StatusCodes.PICO_OK)
{
MessageBox.Show("Error SetSigGenBuiltInV2 error code :" + status.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
//---------------------------------------------------------------------------------------------------------------------------------
status = Imports.SetChannel(_handle, Imports.Channel.ChannelA, 1, Imports.Coupling.PS5000A_DC, Imports.Range.Range_10V, 0);
status = Imports.SetChannel(_handle, Imports.Channel.ChannelB, 1, Imports.Coupling.PS5000A_DC, Imports.Range.Range_10V, 0);
short enable = 1;
uint delay = 0;
short threshold = 1000;
short auto = 0;
status = Imports.SetSimpleTrigger(_handle, enable, Imports.Channel.ChannelA, threshold, Imports.ThresholdDirection.Rising, delay, auto);
_ready = false;
_callbackDelegate = BlockCallback;
_channelCount = 4;
string data;
int x;
bool retry;
uint sampleCount = 185;
PinnedArray[] minPinned = new PinnedArray[_channelCount];
PinnedArray[] maxPinned = new PinnedArray[_channelCount];
int timeIndisposed;
short[] minBuffersChA = new short[sampleCount];
short[] maxBuffersChA = new short[sampleCount];
short[] minBuffersChB = new short[sampleCount];
short[] maxBuffersChB = new short[sampleCount];
bufferValueChA = new short[sampleCount];
bufferValueChB = new short[sampleCount];
minPinned[0] = new PinnedArray(minBuffersChA);
maxPinned[0] = new PinnedArray(maxBuffersChA);
status = Imports.SetDataBuffers(_handle, Imports.Channel.ChannelA, maxBuffersChA, minBuffersChA, (int)sampleCount, 0, Imports.RatioMode.None);
status = Imports.SetDataBuffers(_handle, Imports.Channel.ChannelB, maxBuffersChB, minBuffersChB, (int)sampleCount, 0, Imports.RatioMode.None);
int timeInterval;
int maxSamples;
while (Imports.GetTimebase(_handle, _timebase, (int)sampleCount, out timeInterval, out maxSamples, 0) != 0)
{
_timebase++;
}
_timebase = 2;
/* Start it collecting, then wait for completion*/
_ready = false;
_callbackDelegate = BlockCallback;
while (true)
{
do
{
retry = false;
status = Imports.RunBlock(_handle, 0, (int)sampleCount, _timebase, out timeIndisposed, 0, _callbackDelegate, IntPtr.Zero);
if (status == (short)StatusCodes.PICO_POWER_SUPPLY_CONNECTED || status == (short)StatusCodes.PICO_POWER_SUPPLY_NOT_CONNECTED || status == (short)StatusCodes.PICO_POWER_SUPPLY_UNDERVOLTAGE)
{
status = Imports.ChangePowerSource(_handle, status);
retry = true;
}
else
{
//textMessage.AppendText("Run Block Called\n");
}
}
while (retry);
//textMessage.AppendText("Waiting for Data\n");
while (!_ready)
{
//Thread.Sleep();
}
Imports.Stop(_handle);
if (_ready)
{
short overflow;
status = Imports.GetValues(_handle, 0, ref sampleCount, 1, Imports.DownSamplingMode.None, 0, out overflow);
if (status == (short)StatusCodes.PICO_OK)
{
lock (lockForDataAcq)
{
Array.Copy(maxBuffersChA, bufferValueChA, maxBuffersChA.Length);
Array.Copy(maxBuffersChB, bufferValueChB, maxBuffersChB.Length);
}
}
else
{
//textMessage.AppendText("No Data\n");
}
}
else
{
//textMessage.AppendText("data collection aborted\n");
}
Imports.Stop(_handle);
}
foreach (PinnedArray p in minPinned)
{
if (p != null)
p.Dispose();
}
foreach (PinnedArray p in maxPinned)
{
if (p != null)
p.Dispose();
}
}
private void OnTimedEvent(object sender, MicroLibrary.MicroTimerEventArgs timerEventArgs)
{
lock (lockForDataAcq)
{
Array.Copy(bufferValueChA, receivedDataChA, bufferValueChA.Length);
Array.Copy(bufferValueChB, receivedDataChB, bufferValueChB.Length);
}
System.Diagnostics.Debug.Print(stopwatchDataAcqDuration.ElapsedMilliseconds.ToString() + " " + receivedDataChA[0].ToString() + " " + receivedDataChB[0].ToString());
}