Jump to content
  • 0

CInScan returns 0s when reading multiple channels


bsee

Question

I'm successfully reading a single channel at a time and receiving data back.  However, when I read 3 channels at once, all data is 0.  None of the functions return an error code.  Am I doing something wrong? None of the examples I saw show reading from multiple channels.  Here is the full set of code. 

  • CTR-04
  • InstaCal: 6.74
  • C# universal Library
  • Windows 10, latest updates

// Init the board
DaqBoard = new MccBoard(0);
for (int i = 0; i < 3; i++)
{
    var error = DaqBoard.CConfigScan(i, CounterMode.PulseWidth, CounterDebounceTime.Debounce25500us,
        CounterDebounceMode.TriggerAfterStable, CounterEdgeDetection.RisingEdge, CounterTickSize.Tick20pt83ns, i);
}

int rate = 1000;
int dataPoints = 3;
long[] array1 = new long[3];
long[] array2 = new long[3];
long[] array3 = new long[3];
long[,] multiArray = new long[3, 3];

IntPtr memoryHandle = IntPtr.Zero;
memoryHandle = MccService.WinBufAlloc64Ex(1000);

// The following 3 individual CInScan calls return data successfully.
var scanError1 = DaqBoard.CInScan(0, 0, dataPoints, ref rate, memoryHandle, ScanOptions.Ctr64Bit);
var channelCopy1 = MccService.WinBufToArray64(memoryHandle, array1, 0, 3);

var scanError2 = DaqBoard.CInScan(1, 1, dataPoints, ref rate, memoryHandle, ScanOptions.Ctr64Bit);
var channelCopy2 = MccService.WinBufToArray64(memoryHandle, array2, 0, 3);

var scanError3 = DaqBoard.CInScan(2, 2, dataPoints, ref rate, memoryHandle, ScanOptions.Ctr64Bit);
var channelCopy3 = MccService.WinBufToArray64(memoryHandle, array3, 0, 3);

// The CInScan to read from multiple channels returns all 0s.
var scanErrorMulti = DaqBoard.CInScan(0, 2, dataPoints * 3, ref rate, memoryHandle, ScanOptions.Ctr64Bit);
var multiChannelCopy = MccService.WinBufToArray64(memoryHandle, multiArray, 0, 3, 3);

 

Link to comment
Share on other sites

8 answers to this question

Recommended Posts

  • 0

You must use a single CInScan to read all the channels. I suspect the problem is the number of scans to acquire. Increase the number of scans. For example:

MccDaq.ErrorInfo errInfo = DaqBoard.CInScan(0, 2, 3 * 256, ref rate, memoryHandle, ScanOptions.Ctr64Bit);

if(errInfo.Value !=0) Console.Writeline(errInfo.Message);

 

 

 

 

Link to comment
Share on other sites

  • 0

I think I have a workaround, but I still cannot make MccService.WinBufToArray64() work with a multidimensional array.

CInScan was working fine. No changes needed there.  Since it collects 9 datapoints, apparently I can copy the data to a single dimensional array.  The order of the data is Ch0-P0, Ch1-P0,Ch2-P0,Ch1-P0, etc.  I'll map it into separate arrays myself.

However, I was unable to make MccService.WinBufToArray64() work with a multidimensional array.  The code in my initial post returns all 0s, even when my workaround is returning valid data.  Should this be working?

Link to comment
Share on other sites

  • 0

The demo works fine, but only uses WinBufToArray64 on a single dimension array, which I already have working.  I am unable to make that function work on a multidimensional array.  I'm currently copying multi-channel data out of it using an undocumented workaround. 

Link to comment
Share on other sites

  • 0

The UL help document also lists this overload:

Quote

Copies data to a two-dimensional array of double values:

public MccDaq.ErrorInfo WinBufToArray(IntPtr memHandle, double[,] dataArray, int firstPoint, int numPoints, int numChannels)

 

That said, I am happy to copy to a single dimension array.  Is there documentation that says how to read a multichannel scan to a single dimension array?  In my 2nd post, I believe I identified the structure, but I'm still just guessing.  I'd be more comfortable with official documentation.

Link to comment
Share on other sites

  • 0

The UL Help says the function will copy to a 2D array, but it doesn't work. The only method I know of is manually transferring the channel from the interleaved array to a 1D with a nested loop. I've reattached my example, which I modified to parse the channels into separate arrays. 

 

Program.cs

Link to comment
Share on other sites

  • 0

Perfect.  Your example matches what I had above, but until your example I hadn't found official documentation saying the data values for channels were interleaved.  I will continue with this method. Thank you

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...