private void buttonStart_Click(object sender, EventArgs e) { uint status; status = Imports.SetChannel(_handle, Imports.Channel.ChannelA, 1, Imports.Coupling.PS5000A_DC, Imports.Range.Range_2V, 0); status = Imports.SetChannel(_handle, Imports.Channel.ChannelB, 0, Imports.Coupling.PS5000A_DC, Imports.Range.Range_2V, 0); status = Imports.SetChannel(_handle, Imports.Channel.ChannelC, 0, Imports.Coupling.PS5000A_DC, Imports.Range.Range_2V, 0); status = Imports.SetChannel(_handle, Imports.Channel.ChannelD, 0, Imports.Coupling.PS5000A_DC, Imports.Range.Range_2V, 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 = 1000; PinnedArray <short>[] minPinned = new PinnedArray <short> [_channelCount]; PinnedArray <short>[] maxPinned = new PinnedArray <short> [_channelCount]; int timeIndisposed; short[] minBuffers = new short[sampleCount]; short[] maxBuffers = new short[sampleCount]; minPinned[0] = new PinnedArray <short>(minBuffers); maxPinned[0] = new PinnedArray <short>(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; 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"); 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); foreach (PinnedArray <short> p in minPinned) { if (p != null) { p.Dispose(); } } foreach (PinnedArray <short> p in maxPinned) { if (p != null) { p.Dispose(); } } }
private void buttonStart_Click(object sender, EventArgs e) { uint status; status = Imports.SetChannel(_handle, Imports.Channel.ChannelA, 1, Imports.Coupling.PS5000A_DC, Imports.Range.Range_2V, 0); status = Imports.SetChannel(_handle, Imports.Channel.ChannelB, 0, Imports.Coupling.PS5000A_DC, Imports.Range.Range_2V, 0); status = Imports.SetChannel(_handle, Imports.Channel.ChannelC, 0, Imports.Coupling.PS5000A_DC, Imports.Range.Range_2V, 0); status = Imports.SetChannel(_handle, Imports.Channel.ChannelD, 0, Imports.Coupling.PS5000A_DC, Imports.Range.Range_2V, 0); short enable = 0; uint delay = 0; short threshold = 25000; short auto = 0; Imports.tPS5000ATriggerChannelPropertiesV2[] properties = new Imports.tPS5000ATriggerChannelPropertiesV2[1]; // status = Imports.SetSimpleTrigger(_handle, enable, Imports.Channel.ChannelA, threshold, Imports.ThresholdDirection.Rising, delay, auto); properties[0].thresholdLower = 25000; properties[0].thresholdUpper = 25000; properties[0].hysteresisLower = 100; properties[0].hysteresisUpper = 100; properties[0].Channel = Imports.Channel.ChannelA; Imports.tPS5000ACondition[] conditions = new Imports.tPS5000ACondition[1]; conditions[0].source = Imports.Channel.ChannelA; conditions[0].condition = Imports.TriggerState.True; Imports.tPS5000ADirection[] directions = new Imports.tPS5000ADirection[1]; directions[0].channel = Imports.Channel.ChannelA; directions[0].direction = Imports.ThresholdDirection.Above; directions[0].mode = Imports.ThresholdMode.Level; status = Imports.SetTriggerChannelConditionsV2(_handle, conditions, 1, Imports.PS5000A_CONDITIONS_INFO.PS5000A_CLEAR); status = Imports.SetTriggerChannelPropertiesV2(_handle, properties, 1, 1); status = Imports.SetTriggerChannelConditionsV2(_handle, conditions, 1, Imports.PS5000A_CONDITIONS_INFO.PS5000A_ADD); status = Imports.SetTriggerChannelDirectionsV2(_handle, directions, 1); status = Imports.SetAutoTriggerMicroSeconds(_handle, 0); _ready = false; _callbackDelegate = BlockCallback; _channelCount = 4; string data; int x; textMessage.Clear(); textData.Clear(); bool retry; uint sampleCount = 1000; PinnedArray <short>[] minPinned = new PinnedArray <short> [_channelCount]; PinnedArray <short>[] maxPinned = new PinnedArray <short> [_channelCount]; int timeIndisposed; short[] databuffer = new short[sampleCount]; //short[] minBuffers = new short[sampleCount]; //short[] maxBuffers = new short[sampleCount]; //minPinned[0] = new PinnedArray<short>(minBuffers); //maxPinned[0] = new PinnedArray<short>(maxBuffers); //status = Imports.SetDataBuffers(_handle, Imports.Channel.ChannelA, maxBuffers, minBuffers, (int)sampleCount, 0, Imports.RatioMode.None); status = Imports.SetDataBuffer(_handle, Imports.Channel.ChannelA, databuffer, (int)sampleCount, 0, Imports.RatioMode.None); textMessage.AppendText("BlockData\n"); /*Find the maximum number of samples and the time interval(in nanoseconds). * If the function returns PICO_OK, the timebase will be used. */ 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; 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.RatioMode.None, 0, out overflow); if (status == (short)StatusCodes.PICO_OK) { textMessage.AppendText("Have Data\n"); chartData.Series[0].Points.Clear(); for (int I = 0; I < 1000; I++) { chartData.Series[0].Points.AddXY(I, databuffer[I]); } // 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); foreach (PinnedArray <short> p in minPinned) { if (p != null) { p.Dispose(); } } foreach (PinnedArray <short> p in maxPinned) { if (p != null) { p.Dispose(); } } }
void start(uint sampleCountAfter = 50000, uint sampleCountBefore = 50000, int write_every = 100) { uint all_ = sampleCountAfter + sampleCountBefore; uint status; int ms; status = Imports.MemorySegments(_handle, 1, out ms); Voltage_Range = 200; status = Imports.SetChannel(_handle, Imports.Channel.ChannelA, 1, Imports.Coupling.PS5000A_AC, Imports.Range.Range_200mV, 0); //status = Imports.SetChannel(_handle, Imports.Channel.ChannelA, 1, Imports.Coupling.PS5000A_DC, Imports.Range.Range_200mV, 0); const short enable = 1; const uint delay = 0; const short threshold = 25000; const short auto = 22222; status = Imports.SetBandwidthFilter(_handle, Imports.Channel.ChannelA, Imports.BandwidthLimiter.PS5000A_BW_20MHZ); status = Imports.SetSimpleTrigger(_handle, enable, Imports.Channel.External, threshold, Imports.ThresholdDirection.Rising, delay, auto); _ready = false; _callbackDelegate = BlockCallback; _channelCount = 1; //string data; int x; bool retry; PinnedArray <short>[] minPinned = new PinnedArray <short> [_channelCount]; PinnedArray <short>[] maxPinned = new PinnedArray <short> [_channelCount]; int timeIndisposed; short[] minBuffersA = new short[all_]; short[] maxBuffersA = new short[all_]; minPinned[0] = new PinnedArray <short>(minBuffersA); maxPinned[0] = new PinnedArray <short>(maxBuffersA); status = Imports.SetDataBuffers(_handle, Imports.Channel.ChannelA, maxBuffersA, minBuffersA, (int)sampleCountAfter + (int)sampleCountBefore, 0, Imports.RatioMode.None); //int timeInterval; //int maxSamples; //while (Imports.GetTimebase(_handle, _timebase, (int)sampleCount, out timeInterval, out maxSamples, 0) != 0) //{ // _timebase++; //} _ready = false; _callbackDelegate = BlockCallback; do { retry = false; status = Imports.RunBlock(_handle, (int)sampleCountBefore, (int)sampleCountAfter, _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(30); } Imports.Stop(_handle); if (_ready) { short overflow; status = Imports.GetValues(_handle, 0, ref all_, 1, Imports.RatioMode.None, 0, out overflow); if (status == (short)StatusCodes.PICO_OK) { for (x = 0; x < all_; x++) { masA[x] += maxBuffersA[x] + minBuffersA[x];//=========================================================! } } } Imports.Stop(_handle); foreach (PinnedArray <short> p in minPinned) { if (p != null) { p.Dispose(); } } foreach (PinnedArray <short> p in maxPinned) { if (p != null) { p.Dispose(); } } }