LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

FATAL RUN-TIME ERROR: "PyAcqCfile.c", line 62, col 11, thread id 9144: The program has caused a 'General Protection' fault at 0x1008A71B.

I tried to acquire some image with PCIe-1429 and basler linescan camera spl 4096-140km. But a fatal run-time error was raised. I tried by changing the "Trigger type" in imgSessionTriggerConfigure2(Sid, IMG_SIGNAL_RTSI, 0, IMG_TRIG_POLAR_ACTIVEH, 500, IMG_TRIG_ACTION_BUFFER), but it's still not working. Thank you in advance!

 

Following is my code:

 

#include <utility.h>
#include <userint.h>
#include <niimaq.h>
#include <ansi_c.h>

#define NUM_RING_BUFFERS 50
int AcqWinHeight = 400;
int AcqWinWidth = 2048;
int bytesPerPixel = 2;
int bufSize;
int i;
int bufCmd;
int img;
static BUFLIST_ID Bid;
static SESSION_ID Sid;
static INTERFACE_ID Iid;
static Int8* ImaqBuffers[NUM_RING_BUFFERS];
char *CamID = "img0";


int main (int argc, char *argv[])
{

imgInterfaceOpen(CamID,&Iid);
imgSessionOpen(Iid,&Sid);


// Create a buffer list with n elements
imgCreateBufList(NUM_RING_BUFFERS, &Bid);
// Compute the size of the required buffer
imgGetAttribute (Sid, IMG_ATTR_BYTESPERPIXEL, &bytesPerPixel);
bufSize = AcqWinWidth * AcqWinHeight * bytesPerPixel;

/* The following configuration makes theseassignments to the buffer list
elements:

buffer pointer that will contain image
size of the buffer for buffer element 0
command to go to next buffer or loop when the last element is reached

*/
for (i = 0; i < NUM_RING_BUFFERS; i++)
{
imgCreateBuffer(Sid, IMG_HOST_FRAME, bufSize, &ImaqBuffers[i]);
imgSetBufferElement(Bid, i, IMG_BUFF_ADDRESS, (uInt32)ImaqBuffers[i]);
imgSetBufferElement(Bid, i, IMG_BUFF_SIZE, bufSize);
bufCmd = (i == (NUM_RING_BUFFERS - 1)) ? IMG_CMD_LOOP : IMG_CMD_NEXT;
imgSetBufferElement(Bid, i, IMG_BUFF_COMMAND, bufCmd);
}


// Lock down the buffers contained in the buffer list
imgMemLock(Bid);

// Configure the session to use this buffer list
imgSessionConfigure(Sid, Bid);


imgSessionTriggerConfigure2(Sid, IMG_SIGNAL_RTSI, 0, IMG_TRIG_POLAR_ACTIVEH, 500, IMG_TRIG_ACTION_BUFFER);

img = imgSessionExamineBuffer(Sid, ImaqBuffers, NUM_RING_BUFFERS, IMG_BUFF_ADDRESS);

imgSessionReleaseBuffer(Sid);


}

0 Kudos
Message 1 of 4
(2,486 Views)

solved for now, still working on some other debugging...

0 Kudos
Message 2 of 4
(2,452 Views)

If you may add some more info (e.g. the line where the error arises and what you did for solving it) it may help other users that may find similar problems.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 3 of 4
(2,448 Views)

Please see the new code. I am getting use to the c coding. sorry for the late reply

 

 

#include <userint.h>
#include <stdio.h>
#include "utility.h"
#include "ansi_c.h"

#define _NIWIN

#include "niimaq.h"
#include "llring.h"
#include "expDll.h"

 

// Number of buffers used in the ring
#define NUM_RING_BUFFERS 50

// Globals
static int panelHandle;
static BUFLIST_ID Bid;
static SESSION_ID Sid;
static INTERFACE_ID Iid;
static void* ImaqBuffers[NUM_RING_BUFFERS];
static int CanvasWidth, CanvasHeight, CanvasTop, CanvasLeft;
static unsigned int BufNum;
//static int CVIWndHndl, PlotFlag;
static int TotalFrame = 1000;
static unsigned int *pointer;
static float frameRate;
struct Tuple OutStr;
//static int imageToExtract;
//static int imageNumber;
//Image* img;

struct Tuple
{
unsigned int *pt;
unsigned int bfNum;
float frameRate;
};


int StopAcq()
{
int i;
unsigned int bufNum;

{

// Stop the acquisition
imgSessionAbort(Sid, &bufNum);

// Unlock the buffers in the buffer list
if (Bid != 0)
imgMemUnlock(Bid);

// Dispose of the buffers
for (i = 0; i < NUM_RING_BUFFERS; i++)
if (ImaqBuffers[i] != NULL)
imgDisposeBuffer(ImaqBuffers[i]);

// Close this buffer list
if (Bid != 0)
imgDisposeBufList(Bid, FALSE);

// Close the interface and the session
imgClose (Sid, TRUE);
imgClose (Iid, TRUE);
}
return 0;
}

 

 

int ImaqLoop(Sid, BufNum)
{
static int nbFrame;
static float t1, t2;
static unsigned int currBufNum;
static unsigned int bufAddr;

while (1)
{
t2 = Timer();

// Hold the buffer whose index is BufNum. This is a cumulative buffer
// index, if the buffer has not been acquired yet this function will block
// until it is available. If the buffer has been overwritten this function
// will return the last available buffer. Once the buffer is held the buffer
// will not be overwritten until it is released with imgSessionReleaseBuffer.

imgSessionExamineBuffer2 (Sid, BufNum, &currBufNum, (void**)&bufAddr);


pointer = (unsigned int *)bufAddr;

// Accessing to buffer values
//printf ("Address is %d, value is %d\n", bufAddr, pointer);

//printf ("value is %d, value2 is %d, value3 is %d\n", pointer[0], pointer[1], pointer[2047]);


// Reinsert the buffer back in the ring
imgSessionReleaseBuffer (Sid);

// Now get the next buffer
BufNum ++;

nbFrame++;
if (nbFrame>10)
{
frameRate = nbFrame/(t2-t1);
t1 = t2;
nbFrame=0;

}


if (BufNum >= TotalFrame)
{
//printf ("Buffer number is %d, frameRate is %f\n", BufNum, frameRate);
StopAcq();
break;
}

}
return BufNum;

//return 0;

}

struct Tuple __fastcall imaqAcq (int AcqWinWidth, int AcqWinHeight)
{
int i;
unsigned int bufSize, bufCmd, bytesPerPixel, bitDepth;
//char intfName[64];

// Open an interface and a session
imgInterfaceOpen ("img0", &Iid);
imgSessionOpen (Iid, &Sid);

// Check that the Acquisition window is not smaller than the Canvas
/* imgGetAttribute (Sid, IMG_ATTR_ROI_WIDTH, &AcqWinWidth);
imgGetAttribute (Sid, IMG_ATTR_ROI_HEIGHT, &AcqWinHeight);*/


// Set the ROI to the size of the Canvas so that it will fit nicely
imgSetAttribute2 (Sid, IMG_ATTR_ROI_WIDTH, AcqWinWidth);
imgSetAttribute2 (Sid, IMG_ATTR_ROI_HEIGHT, AcqWinHeight);
imgSetAttribute2 (Sid, IMG_ATTR_ROWPIXELS, AcqWinWidth);

// Set the plot Flag depending on the bitDepth
imgGetAttribute (Sid, IMG_ATTR_BITSPERPIXEL, &bitDepth);
//switch(bitDepth)
//{
// case 10:
// PlotFlag = IMGPLOT_MONO_10;
// break;
// case 12:
// PlotFlag = IMGPLOT_MONO_12;
// break;
// case 14:
// PlotFlag = IMGPLOT_MONO_14;
// break;
// case 16:
// PlotFlag = IMGPLOT_MONO_16;
// break;
// case 24:
// case 32:
// PlotFlag = IMGPLOT_COLOR_RGB32;
// break;
// default:
// PlotFlag = IMGPLOT_MONO_8;
// break;
//}

// Create a buffer list with n elements
imgCreateBufList(NUM_RING_BUFFERS, &Bid);

// Compute the size of the required buffer
imgGetAttribute (Sid, IMG_ATTR_BYTESPERPIXEL, &bytesPerPixel);
//printf("bytesPerPixel is %d", bytesPerPixel);

bufSize = AcqWinWidth * AcqWinHeight * bytesPerPixel;

/* The following configuration assigns the following to the buffer list
elements:

1) buffer pointer that will contain image
2) size of the buffer for buffer element 0
3) command to go to next buffer or loop when the last element is reached

*/
for (i = 0; i < NUM_RING_BUFFERS; i++)
{
imgCreateBuffer(Sid, FALSE, bufSize, &ImaqBuffers[i]);
imgSetBufferElement2(Bid, i, IMG_BUFF_ADDRESS, (uInt32)ImaqBuffers[i]);
imgSetBufferElement2(Bid, i, IMG_BUFF_SIZE, bufSize);
bufCmd = (i == (NUM_RING_BUFFERS - 1)) ? IMG_CMD_LOOP : IMG_CMD_NEXT;
imgSetBufferElement2(Bid, i, IMG_BUFF_COMMAND, bufCmd);
}


// Lock down the buffers contained in the buffer list
imgMemLock(Bid);

// Configure the session to use this buffer list

imgSessionLineTrigSource2(Sid, IMG_SIGNAL_RTSI, 0, IMG_TRIG_POLAR_ACTIVEH, 0);

imgSessionConfigure(Sid, Bid);
// Start the acquisition asynchronously
imgSessionAcquire(Sid, TRUE, NULL);

BufNum = 0;

// Activate the IMAQ Loop

BufNum = ImaqLoop(Sid, BufNum);

struct Tuple pbf = {pointer, BufNum, frameRate};

return pbf;

}


int main ()
{ static int AcqWinWidth = 2048, AcqWinHeight = 200;

OutStr = imaqAcq(AcqWinWidth, AcqWinHeight);
printf ("Pointer is %d, Buffer number is %d, frameRate is %f\n", OutStr.pt, OutStr.bfNum, OutStr.frameRate);
return 0;
}

0 Kudos
Message 4 of 4
(2,407 Views)