From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Problems sending CVI 2-D array to vb.NET public multidimensional array using .NET controller

Solved!
Go to solution

I have created a .NET controller to interface with CVI. I am passing a 2-D array from CVI to .NET, but am getting an out of bounds exception.

Does .NET handle multidimensional arrays in a different way? I looked into it and found that vb.NET allocates memory differently for multidimensional arrays.

I am using CVI .NET library functions to allocate memory, but am unsure why the arrays I'm passing are not being sent properly. Can someone shed some light

on this issue. Attached is my .c and .h file from CVI along with my instrument.

 

NOTE: Youll need to reload the instruments from the vb.net project and put the executable into the windows assembly GAC.

Message Edited by mdmorar on 08-31-2009 03:26 PM
Monil Morar
Control System Engineer
Secure Drilling Services (SDS)
Weatherford │ 16430 Park Ten Place │ Suite 200 │ Houston │ Texas │ 77084
Download All
0 Kudos
Message 1 of 2
(2,886 Views)
Solution
Accepted by topic author mdmorar

Try this. Sorry, not much commenting.

 

#include <cvidotnet.h>
#include "vbMath.h"
#include <cvirte.h>
static CDotNetHandle exceptionHandle;
static vbMathDLL_mathClass classHandle;


void init()
{
 double * result;
 double *myArray;
 int i,p;
 
 Initialize_vbMathDLL();
 vbMathDLL_mathClass__Create (&classHandle, &exceptionHandle);
 
 result=CDotNetAllocateMemory(sizeof(double));
 myArray = CDotNetAllocateMemory(sizeof(double)*5*5);
 
 for(i=0;i<5;i++)
  for(p=0;p<5;p++)
  {
   *myArray = p;
   myArray = myArray +1;
  }
 myArray=myArray-25;
 
 vbMathDLL_mathClass_addArray (classHandle, myArray, 5, 5, 5, 5, result, exceptionHandle);
 
 CDotNetDiscardHandle(classHandle);
 CDotNetDiscardHandle(exceptionHandle);
 Close_vbMathDLL();
 
 
 
}

int main (int argc, char *argv[])
{
 if (InitCVIRTE (0, argv, 0) == 0)
  return -1;    /* out of memory */
 init();
 
 return 0;
}

 

 


----------------------

Imports System.Reflection


Public Class mathClass
    Dim globalVal As Double

    Public Sub addArray(ByVal array(,) As Double, ByVal x As Integer, ByVal y As Integer, ByRef c As Double)
        Dim i As Integer
        Dim p As Integer
        c = 0
        For i = 0 To x - 1
            For p = 0 To y - 1
                c = c + array(i, p)
            Next
        Next


    End Sub
End Class

 

 

Message Edited by craige on 09-01-2009 10:16 AM
0 Kudos
Message 2 of 2
(2,865 Views)