LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

CIN crash in LabVIEW 8.5

The problem:
A VI that includes a CIN calls a different DLL that was compiled by Matlab 6.5, using an LSB file that performs type casting for Matlab mxArray type variables.
 
The VI crashs when entering the CIN.
It seems the code crashs whenever we attempt to access pointers returned by the Matlab DLL.
 
The same VI with the same LSB and Matlab DLL runs correctly in LabVIEW 7.1.1.
The Matlab DLL was compiled via the Matlab MCC command.
We also compiled the LSB using LabVIEW 8.5 - Multithreaded DLL + 1 byte alignment, via VC 6.0 - this didn't solve the problem.
There are no int64 variables. We tried to remove the complex 128 and float64 variables and change them to float without success.
We also compiled the LSB using LabVIEW 8.5 - Singlethreaded* + 1 byte alignment or Debug Singlethreaded + 1 byte alignment - again with no success.
 
Below is the CIN source code:
 
#include "extcode.h"
#include "probepattern.h"
#include "matlab.h"
#define PI 3.1415926535897931;
typedef struct {
 int32 dimSizes[2];
 cmplx128 Numeric[1];
 } TD1;

typedef TD1 **TD1Hdl;
 
typedef struct {
 int32 dimSize;
 float64 Numeric[1];
 } TD2;
typedef TD2 **TD2Hdl;
 
typedef struct {
 LVBoolean status;
 int32 code;
 LStrHandle source;
 } TD3;

CIN MgErr CINRun(TD2Hdl paramv, TD1Hdl Ecopolar, TD1Hdl Ecrosspolar,
     TD2Hdl Probe_Az, TD2Hdl Probe_El, float64 *gain, TD3 *herror);
CIN MgErr CINRun(TD2Hdl paramv, TD1Hdl Ecopolar, TD1Hdl Ecrosspolar,
     TD2Hdl Probe_Az, TD2Hdl Probe_El, float64 *gain, TD3 *herror)
{
 float64 *cparamv;
 float64 *cProbe_Az,*cProbe_El;
 float64 *Re_Ecopolar,*Im_Ecopolar;
 float64 *Re_Ecrosspolar,*Im_Ecrosspolar;
 int32 vsize,i,j,size;
 int32 rows, cols;
 MgErr err = noErr;
 float64 *cerror_in, *cerror_out;
 char *ssource;
 int32 len;
 FILE *stream;
 mxArray *merror_in = NULL;
 mxArray *merror_out = NULL;
 mxArray *mEcopolar = NULL;
 mxArray *mEcrosspolar = NULL;
 mxArray *mProbe_Az = NULL;
 mxArray *mProbe_El = NULL;
 mxArray *mparamv = NULL;
 mxArray *mgain = NULL;

// *********************** INPUT DATA INTO THE MATLAB DLL ***********************
   stream = fopen( "getModelPattern_Test.txt", "w" );
   fprintf(stream, "Checkpoint #1\n");
 vsize=(*paramv)->dimSize;
 cparamv=(*paramv)->Numeric;
 mlfAssign(&mparamv,mlfDoubleMatrix(vsize,1,cparamv,NULL));

//********************  ACTIVATE THE PROBE PATTERN DLL  ****************************
    fprintf(stream, "Checkpoint #2\n");
 ProbePatternInitialize();
 
    fprintf(stream, "Checkpoint #3\n");
 len = LStrLen(*herror->source);
 cerror_in = (float64 *)malloc((len+2)*sizeof(float64));
 ssource = (char *)malloc(len*sizeof(char));
 cerror_in[0] = (float64)herror->status;
 cerror_in[1] = (float64)herror->code;
 SPrintf(ssource, "%H", herror->source);
 for(i=2;i<(len+2);i++) cerror_in[i] = (float64)ssource[i-2];
 mlfAssign(&merror_in, mlfDoubleMatrix(1,(len+2), cerror_in,NULL));
 free(cerror_in);
 free(ssource);
    fprintf(stream, "Checkpoint #3.2\n");
 mEcopolar = mlfModelpattern(&mEcrosspolar,
                          &mProbe_Az,
        &mProbe_El,
        &mgain,
        &merror_out,
        mparamv,
        merror_in);
 fprintf(stream, "Checkpoint #4\n");
 ProbePatternTerminate();
    fprintf(stream, "Checkpoint #5\n");
 cerror_out = mxGetPr(merror_out);
 len = mxGetDimensions(merror_out)[1]-2;
 ssource = (char *)malloc(len*sizeof(char));
 for(i=0;i<len;i++) ssource[i] = (char)cerror_out[i+2];
 if (err = NumericArrayResize(uB, 1L,(UHandle *)&herror->source, len))
  goto out;
 LStrLen(*herror->source) = len;
 MoveBlock(ssource, LStrBuf(*herror->source), len);
 herror->status = (LVBoolean)cerror_out[0];
 herror->code =   (int32)cerror_out[1];
 free(ssource);
    fprintf(stream, "Checkpoint #6\n");
//**************************************************************************************

 rows = mxGetDimensions(mEcopolar)[0];
 cols = mxGetDimensions(mEcopolar)[1];
    rows = 1;
 cols = 1;
 size = cols*rows;
    fprintf(stream, "Checkpoint #6.1\n");
 Re_Ecopolar = mxGetPr(mEcopolar);
 Im_Ecopolar = mxGetPi(mEcopolar);
    fprintf(stream, "Checkpoint #6.15\n");
 if(SetCINArraySize((UHandle)Ecopolar, 1, size)) goto out;
 (*Ecopolar)->dimSizes[0] = rows;
 (*Ecopolar)->dimSizes[1] = cols;
 fprintf(stream, "Checkpoint #6.2\n");
 for (i=0;i<cols;i++)
  for (j=0;j<rows;j++){
   (*Ecopolar)->Numeric[j*cols+i].re = Re_Ecopolar[i*rows+j];
   (*Ecopolar)->Numeric[j*cols+i].im = Im_Ecopolar[i*rows+j];
  }
    fprintf(stream, "Checkpoint #6.3\n");
 Re_Ecrosspolar = mxGetPr(mEcrosspolar);
 Im_Ecrosspolar = mxGetPi(mEcrosspolar);
 if(SetCINArraySize((UHandle)Ecrosspolar, 2, size)) goto out;
 (*Ecrosspolar)->dimSizes[0] = rows;
 (*Ecrosspolar)->dimSizes[1] = cols;
 for (i=0;i<cols;i++)
  for (j=0;j<rows;j++){
   (*Ecrosspolar)->Numeric[j*cols+i].re = Re_Ecrosspolar[i*rows+j];
   (*Ecrosspolar)->Numeric[j*cols+i].im = Im_Ecrosspolar[i*rows+j];
  }
    fprintf(stream, "Checkpoint #6.4\n");
 cProbe_Az = mxGetPr(mProbe_Az);
 cols = mxGetDimensions(mProbe_Az)[1];
 if(SetCINArraySize((UHandle)Probe_Az, 3, cols)) goto out;
 (*Probe_Az)->dimSize = cols;
 for (i=0;i<cols;i++) (*Probe_Az)->Numeric[i] = cProbe_Az[i];
 
    fprintf(stream, "Checkpoint #6.5\n");
 cProbe_El = mxGetPr(mProbe_El);
 cols = mxGetDimensions(mProbe_El)[1];
    fprintf(stream, "Checkpoint #6.6\n");
 if(SetCINArraySize((UHandle)cProbe_El, 4, cols)) goto out;
    fprintf(stream, "Checkpoint #6.61\n");
 (*Probe_El)->dimSize = cols;
 fprintf(stream, "Checkpoint #6.7\n");
 for (i=0;i<cols;i++) (*Probe_El)->Numeric[i] = cProbe_El[i];
    fprintf(stream, "Checkpoint #7\n");
 *gain = *mxGetPr(mgain);
 mxDestroyArray(mEcopolar);
 mxDestroyArray(mEcrosspolar);
 mxDestroyArray(mProbe_El);
 mxDestroyArray(mProbe_Az);
 mxDestroyArray(mparamv);
 mxDestroyArray(merror_in);
 mxDestroyArray(merror_out);
 mxDestroyArray(mgain);

out:
 fprintf(stream, "Checkpoint #8\n");
 fclose(stream);
 return noErr;
}
0 Kudos
Message 1 of 2
(2,683 Views)

Hello lior,

If LabVIEW is crashing, you should elect to Report the Error in the message window. This will automatically send an email to NI's support department whereupon an Applications Engineer can troubleshoot this issue directly with you. The error log file will automatically be included as well. The AE can then look into possible workarounds and work with R&D to eliminate the issue in future releases of LabVIEW if it is a bug. I would suggest you refer to your original forum post in the Additional Comments.

Cheers,

Emilie K

 

0 Kudos
Message 2 of 2
(2,666 Views)