Jump to content

multiple CIN call in a single VI


Recommended Posts

I need to call a single CIN multiple times in a loop and the second time it doesn't finish but the program crashes. i think it is because of memory allocation problems. the first call is OK, only the second is troublesome. could somebody plz explain how i can allocate enough memory or somehow else solve this problem? thank you very much

Link to comment

first of all, I have some global data, in it 2 structures

typedef struct {

LVBoolean status;

int32 code;

LStrHandle source;

} LVError;

typedef struct {

int32 dimSizes[2];

float64 arg1[1];

} LVpotty;

typedef LVpotty **LVpottyHdl;

the first is the error handler, the second is a simple labview array

double toltes[120][3]; //this is an array in which i collect the data and then tranform it

to a labview type array and pass it through the CIN

in the CINInit I have place calls that start up the device i will be using, these are calls

to functions in the device's SDK

the ints and floats in the CINRun routine are values whose value is decided in the CINInit()

LVpottyHdl potty - this is the struct above, the array

VError *zebriserror - is error handling

CIN MgErr CINRun(int32 *lchannelcount, float64 *latomduration, float64 *lfrequency,

int32 *lmotionquantsperatom, LVpottyHdl potty, float64 *kijelzo, LVError *zebriserror)

{

zebriserror->status = LVTRUE; // means there is no error

*lchannelcount = motionChannelCount; // decided in CINInit

*latomduration = atomDuration;

*lmotionquantsperatom = motionQuantsPerAtom;

*lfrequency = motionQuantsPerAtom/atomDuration;

// start the device //this is maybe where the problem is. if i don't use the activate flag

//than the program stops here and it sais that the current configuration

//won't allow this to execute (error handling tells me)

//so when i put this in, the second time this CIN executes, it just crashes

if (active==false) {

active = true;

if (!ZebDevice_Start(device))

goto __end;

}

if (!motionFeed(1)) //call the routine that gathers the data

goto __end;

k = 6/motionChannelCount; //determines how many data a sensor has (it can be adjusted...)

*kijelzo = k;

// fill up the out array, and in order

for (i=0; i<6; i++)

switch (i % motionChannelCount){

case 0:

for(j=0; j<3; j++)

(**potty).arg1[i/motionChannelCount*3 + j] = toltes[j];

break;

case 1:

for(j=0; j<3; j++)

(**potty).arg1[k*3 + i/motionChannelCount*3 + j] = toltes[j];

break;

case 2:

for(j=0; j<3; j++)

(**potty).arg1[k*6 + i/motionChannelCount*3 + j] = toltes[j];

break;

case 3:

for(j=0; j<3; j++)

(**potty).arg1[k*12 + i/motionChannelCount*3 + j] = toltes[j];

break;

case 4:

for(j=0; j<3; j++)

(**potty).arg1[k*24 + i/motionChannelCount*3 + j] = toltes[j];

break;

case 5:

for(j=0; j<3; j++)

(**potty).arg1[k*48 + i/motionChannelCount*3 + j] = toltes[j];

break;

}

// stop the device

if (!ZebDevice_Stop(device))

goto __end;

zebriserror->status = LVFALSE; // there was no error

__end:

if (device)

ZebDevice_Release(device);

if (zebriserror->status) //error handling

{

const char *cerrorstr = Zeb_GetLastError();

int32 length = strlen(cerrorstr);

if (cinerror = NumericArrayResize(uB, 1L, (UHandle*)&zebriserror->source, length))

goto out;

LStrLen(*zebriserror->source) = length;

MoveBlock((const void*)cerrorstr, LStrBuf(*zebriserror->source), length);

}

return noErr;

out:

return cinerror;

}

BOOL motionFeed(int atomCount) //the main data gathering routine

{

if (!motionInput)

return TRUE;

const ZebVector3* pos[MAX_MOTION_CHANNELS];

for(int ch = 0; ch < motionChannelCount; ch++)

{

if (!ZebMotionChannel_GetPos(motionChannels[ch], &pos[ch]))

return FALSE;

}

for(int ctr = atomCount*motionQuantsPerAtom; ctr--; )

{

for(int ch = 0; ch < motionChannelCount; ch++)

{

const ZebVector3* v = pos[ch]++;

//this is where i fill up the array (a global array)

toltes[szamlalo][0] = v->x; toltes[szamlalo][1] = v->y; toltes[szamlalo][2] = v->z;

szamlalo++;

}

}

return TRUE;

}

i tried using a dynamic array but then labview crashed even on the first run...

Link to comment
// start the device

//this is maybe where the problem is. if i don't use the activate flag

//than the program stops here and it sais that the current configuration

//won't allow this to execute (error handling tells me)

//so when i put this in, the second time this CIN executes, it just crashes

if (active==false) {

active = true;

if (!ZebDevice_Start(device))

goto __end;

}

if (!motionFeed(1)) //call the routine that gathers the data

goto __end;

k = 6/motionChannelCount; //determines how many data a sensor has (it can be adjusted...)

*kijelzo = k;

// fill up the out array, and in order

for (i=0; i<6; i++)

switch (i % motionChannelCount){

....

In the above code, I have two questions.

1) I'm unclear on where the variable "active" is defined

2) The "for (i=0; i<6; i++)" line above your switch statement seems to be a left over snippet of code, as if someone copied/pasted a line out of place on accident (not that I have ever done this...only a few hundred times). ;)

Hope this helps... I'm a little rusty with C, but those two things jumped out at me.

Joe (orko)

Link to comment
  • 1 month later...
active is defined as a global variable, to keep its value when the CIN runs again

and the second question is right, i will fix it now.... no, i think it's all right. also, i deleted it and the problem persists....

Did you solve the problem by now or found the perfect reference? The same happens with me, but with a dll call. I'm quite sure there's no memory leak or so. Would be really interested...

Thanks,

Gudrun

Link to comment
Did you solve the problem by now or found the perfect reference? The same happens with me, but with a dll call. I'm quite sure there's no memory leak or so. Would be really interested...

If you get this kind of error when calling DLLs then you are doing something wrong in the Call Library Node configuration. Show us the prototype(s) of your function(s) and the according VIs then we might be able to help you point out possible problems.

Rolf Kalbermatter

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.