Test and Measurement Forum

C# setting databuffers in dual channel mode

Post your .Net discussions here

C# setting databuffers in dual channel mode

Postby cmos » Thu Apr 28, 2016 6:39 am

Hi
I am looking for some guidance setting up the data buffers using C#. We have a PS5244A and we have been using it in blockmode on a single channel based on your BlockModeExample.

I tried to implement the dual channel following the instructions of the API manual:
--Enabled and set both channels
--Call SetSimpleTrigger to setup channel A as my driving channel (I am assuming channel B will still be collected?)
--Set data buffers as follow:

Code: Select all
short[] minBuffersChA = new short[sampleCount];
short[] maxBuffersChA = new short[sampleCount];
minPinned[ictr] = new PinnedArray<short>(minBuffersChA);
maxPinned[ictr] = new PinnedArray<short>(maxBuffersChA);
status = Imports.SetDataBuffers(_handle, Imports.Channel.ChannelA , maxBuffersChA, minBuffersChA, (int)sampleCount, 0, Imports.RatioMode.None);

I do the same for channel B

--Call status = Imports.GetTimebase(_handle, _timebase, (int)sampleCount, out timeInterval, out maxSamples, 0);
--Call Imports.RunBlock(_handle, 0, (int)sampleCount, _timebase, out timeIndisposed, 0, _callbackDelegate, IntPtr.Zero);
--Poll callBackDelegate
--StopHandle
--Imports.GetValues(_handle, 0, ref sampleCount, 1, Imports.DownSamplingMode.None, 0, out overflow);

At this point I assume maxBuffersChA and maxBuffersChB has the data that I want to analyze. However I am getting zeros. I am not sure if I setup the buffer arrays properly or if I am calling proper functions. I have to say I feel a bit uneasy as I am not sure if the functions I listed before are taking into account what channels are active or not. I believe they are but then it makes me think, when I setup the buffer arrays, the size of those buffers is related to single channels? Also I am not sure what the PinnedArray template is doing here. I am not clear if I could access those objects instead of the short[] buffer objects when processing the data at the end of the block call. As you see, C# is not my forte.

Just to finished the details of my file setup, I would like to mention that when we were running in one channel mode, we were collecting 10^5 samples at 16 BitResolution with time base of 5 (aka. 32ns). When I setup two channels, I change my resolution to 15BitRes and I set my time base to 6 (to preserve 32ns).

Could I get you advice please? If desired, I could post my code but I have to clean it up a bit.

Cristian
cmos
Newbie
 
Posts: 0
Joined: Thu Apr 28, 2016 6:10 am

Re: C# setting databuffers in dual channel mode

Postby Hitesh » Fri Apr 29, 2016 8:20 am

Hi Cristian,

Which version of the ps5000a.dll are you using?

If a channel is enabled via the SetChannel() (ps5000aSetChannel()) function, then data will be collected for that channel provided that a data buffer has been set for it. The size of the buffers should be greater than or equal to the number of pre-trigger and post-trigger samples that you are collecting.

Also, as you are collecting data without aggregation the data should be present in the maxBuffersChA and minBuffersChB function.

If you step through your code are any of the status code values non-zero? If so, that will indicate an error somewhere in the code or operation.

The PinnedArray objects are used to ensure that the memory allocated for the data buffers is held so that the data values can be written there when the GetValues() function is called.

It might be useful to see your code in order to see the program flow.

Regards,
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 1999
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: C# setting databuffers in dual channel mode

Postby cmos » Sun May 01, 2016 7:08 pm

So one of the problems I was having initially was with the actual power of the device. I am using a single headed USB as the double headed one triggers a high current spike in our laptops. The single headed seems to work fine except in my current laptop. It only works in one of the four available USB ports.

After I was able to get proper power, then I found a bug in the code. everything is working now. Thank you.

I was a bit confused that you can activate a channel and then you have to assigned memory. I would prefer to do all in a single call as those two operations depend in order and are not exclusive.

Related to the Max and Min buffers, I understand the former contains values in the range [0..2^15] and the latter contains values from [-(2^15 - 1)..0]? I am not using the minbuffers at all in my application. If I use it, how would integrate the max and min buffers? Would you merge both buffers into a single object alternating values from those buffers?

For the record, here is how I assigned the buffer data in the case I am using one or two channels:

Code: Select all
           
            PinnedArray<short>[] minPinned = new PinnedArray<short>[_channelCount];
            PinnedArray<short>[] maxPinned = new PinnedArray<short>[_channelCount];

            short[] minBuffersChA = new short[sampleCount];
            short[] maxBuffersChA = new short[sampleCount];
            short[] minBuffersChB = new short[sampleCount];
            short[] maxBuffersChB = new short[sampleCount];

            minPinned[0] = new PinnedArray<short>(minBuffersChA);
            maxPinned[0] = new PinnedArray<short>(maxBuffersChA);
            status = Imports.SetDataBuffers(_handle, mainChan, maxBuffersChA, minBuffersChA, (int)sampleCount, 0, Imports.RatioMode.None);

            if (enableChanB == 1)
            {
                minPinned[1] = new PinnedArray<short>(minBuffersChB);
                maxPinned[1] = new PinnedArray<short>(maxBuffersChB);
                status = Imports.SetDataBuffers(_handle, secChan, maxBuffersChB, minBuffersChB, (int)sampleCount, 0, Imports.RatioMode.None);
            }


Cristian
cmos
Newbie
 
Posts: 0
Joined: Thu Apr 28, 2016 6:10 am

Re: C# setting databuffers in dual channel mode

Postby Hitesh » Wed May 04, 2016 3:34 pm

Hi Cristian,

Using a block mode capture as an example, the ps5000aSetDataBuffer() and ps5000aSetDataBuffers() functions allow the User to set different buffers for different channel/segment combinations. The advantage is that you can then request different views of the same data by specifying different ratio modes e.g. None and Average, and the data will be written into those respective buffers.

The max and min data refers to the maximum and minimum values found in a section of data values. For example, if you are collecting aggregated data and specify a ratio of 10, then for each portion consisting of 10 samples, the maximum and minimum value will be returned.

The values can be anywhere in the range of the maximum and minimum ADC counts for the resolution selected (use the ps5000aMaximumValue() and ps5000aMinimumValue() functions to check these values).

The aggregated data is used for display purposes so that you are not requesting too much data from the device during data collection given that you have a finite number of pixels to draw the signal on across the screen. You can draw from min to max for each pair and so on, and then request more data samples as you zoom in.

Regards,
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 1999
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire


Return to .Net Languages (C#, VB.Net, .)

Who is online

Users browsing this forum: No registered users and 0 guests