PicoScope 7 Software
Available on Windows, Mac and Linux
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, 0, Imports.Coupling.PS5000A_DC, Imports.Range.Range_10V, 0);
//status = Imports.SetChannel(_handle, Imports.Channel.ChannelC, 0, Imports.Coupling.PS5000A_DC, Imports.Range.Range_10V, 0);
//status = Imports.SetChannel(_handle, Imports.Channel.ChannelD, 0, Imports.Coupling.PS5000A_DC, Imports.Range.Range_10V, 0);
short enable = 0;
uint delay = 0;
short threshold = 25000;
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;
//textMessage.Clear();
//textData.Clear();
bool retry;
uint sampleCount = 1024;
PinnedArray[] minPinned = new PinnedArray[_channelCount];
PinnedArray[] maxPinned = new PinnedArray[_channelCount];
int timeIndisposed;
short[] minBuffers = new short[sampleCount];
short[] maxBuffers = new short[sampleCount];
minPinned[0] = new PinnedArray(minBuffers);
maxPinned[0] = new PinnedArray(maxBuffers);
status = Imports.SetDataBuffers(_handle, Imports.Channel.ChannelA, maxBuffers, minBuffers, (int)sampleCount, 0, Imports.RatioMode.None);
//textMessage.AppendText("BlockData\n");
/* find the maximum number of samples, the time interval (in timeUnits),
* the most suitable time units, and the maximum _oversample at the current _timebase*/
int timeInterval;
int maxSamples;
while (Imports.GetTimebase(_handle, _timebase, (int)sampleCount, out timeInterval, out maxSamples, 0) != 0)
{
//textMessage.AppendText("Timebase selection\n");
_timebase++;
}
//textMessage.AppendText("Timebase Set\n");
/* Start it collecting, then wait for completion*/
_ready = false;
_callbackDelegate = BlockCallback;
// _timebase = 3;
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(100);
}
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)
{
//textMessage.AppendText("Have Data\n");
double chRange = 20;
int chResolution = 14;
listCh1RawData.Clear();
for (int i = 0; i < maxBuffers.Length; i++)
{
listCh1RawData.Add(i, (double)maxBuffers[i] * chRange / (2 ^ chResolution));
}
this.Invoke((MethodInvoker)delegate
{
zedGraphControlOscView.AxisChange();
zedGraphControlOscView.Invalidate();
zedGraphControlOscView.Refresh();
});
//for (x = 0; x < sampleCount; x++)
//{
// data = maxBuffers[x].ToString();
// //textData.AppendText(data);
// //textData.AppendText("\n");
//}
}
else
{
//textMessage.AppendText("No Data\n");
}
}
else
{
//textMessage.AppendText("data collection aborted\n");
}
Imports.Stop(_handle);
Thread.Sleep(500);
}
foreach (PinnedArray p in minPinned)
{
if (p != null)
p.Dispose();
}
foreach (PinnedArray p in maxPinned)
{
if (p != null)
p.Dispose();
}
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
_timebase = (uint)numericUpDown1.Value;
int intervalTmp = 0;
int maxSamplesTmp = 0;
Imports.GetTimebase(_handle, _timebase, 1024, out intervalTmp, out maxSamplesTmp, 0);
kryptonLabelSampleInterbal.Text = intervalTmp.ToString() + " ns";
}