Code:
/*********************************************************************************
*********************************************************************************/
#include <stdio.h>
#include "HLGrab.h"
#include <memory.h>
#include <stdlib.h>
#include "stdint.h"
#include "imaq.lib"
// error checking macro
#define errChk(fCall) if (error = (fCall), error < 0) {goto Error;} else
//prototypes
void DisplayIMAQError(int32_t error);
int AnalogueCardSnap(uint32_t Sid, uint8_t* ImaqBuffer, uint32_t top, uint32_t left, uint32_t height, uint32_t width);
int AnalogueCardInit (uint32_t *Sid, uint32_t *Iid, uint16_t *width, uint16_t *height, uint8_t *image1D, uint8_t **image2D);
int AnalogueCardClose(uint32_t *Sid, uint32_t *Iid);
/*******************************************************************************************
DisplayIMAQError
If there is an error this will display the error
int32_t error Error code to be tranlated by imgShowError
Int8 ErrorMessage Address the error message will be written to
*******************************************************************************************/
void DisplayIMAQError(int32_t error)
{
int i;
int8_t ErrorMessage[256];
memset(ErrorMessage, 0x00, sizeof(ErrorMessage));
// converts error code to a message
imgShowError(error, ErrorMessage);
//show error message
for (i = 0; i < 256; i++) {
printf("%c", ErrorMessage[i]);
}
printf("\n");
}
/*******************************************************************************************
AnalogueCardSnap
Takes image using Analogue card with defined parameters.
unsigned int32_t Sid Session ID used to interact with card
Int8* Imaq Buffer 1D-Array which will store image data
unsigned int32_t top defines top of area where image will start to be taken out of total image area
unsigned int32_t left defines left side of area where image will start to be taken out of total image area
unsigned int32_t height defines height of image to be taken out of total image area
unsigned int32_t width defines width of image to be taken out of total image area
*******************************************************************************************/
int AnalogueCardSnap(uint32_t Sid, uint8_t* ImaqBuffer, uint32_t top, uint32_t left, uint32_t height, uint32_t width)
{
long error;
//Take image
//rval imgSnapArea(unsigned int32_t sid, void** bufAddr, unsigned int32_t top, unsigned int32_t left, unsigned int32_t height, unsigned int32_t width, unsigned int32_t rowPixels);
errChk(imgSnapArea(Sid, (void**)&ImaqBuffer, top, left, height, width, width));
return 0;
Error:
if(error<0){
printf("Error while trying to take image \n");
DisplayIMAQError(error);
}
return 0;
}
/*******************************************************************************************
AnalogueCardInit
Initializes card and takes needed parameters from image
unsigned int32_t *Sid Session ID used to interact with card
unsigned int32_t *Iid Interface ID used to interact with card
int *width Width of image read by frame grabber
int *height Height of image read by frame grabber
int *pixels Number of pixels read by frame grabber (usually = width)
*******************************************************************************************/
int AnalogueCardInit (uint32_t *Sid, uint32_t *Iid, uint16_t *width, uint16_t *height, uint8_t *image1D, uint8_t **image2D)
{
long error;
int i;
char intfName[64];
unsigned int BitsInPixel = 0;
unsigned int plotFlag;
intfName[0] = 'i';
intfName[1] = 'm';
intfName[2] = 'g';
intfName[3] = '2';
intfName[4] = 'a';
// Open an interface and a session
errChk(imgInterfaceOpen (intfName, Iid));
errChk(imgSessionOpen (*Iid, Sid));
width = 640;
height = 480;
/*
// Get Aquisition window height and width
errChk(imgGetAttribute (*Sid, IMG_ATTR_ROI_WIDTH, width));
errChk(imgGetAttribute (*Sid, IMG_ATTR_ROI_HEIGHT, height));
errChk(imgGetAttribute (*Sid, IMG_ATTR_BITSPERPIXEL, &BitsInPixel));
// Set pixel length
errChk(imgSetAttribute (*Sid, IMG_ATTR_ROWPIXELS, *height));
// get the pixel depth of the camera.
switch(BitsInPixel)
{
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:
// assumes that a 24 bits camera is a color camera.
// in this mode, even if the camera is 24 bits the board returns 32 bits values
plotFlag = IMGPLOT_COLOR_RGB32;
break;
default:
plotFlag = IMGPLOT_MONO_8;
break;
}
*/
//Make buffer size for image1D and image2D
*image1D = (uint8_t) malloc ((*width)*(*height)*sizeof(int8_t));
if (image1D==NULL) printf("Allocating memory for image in memory failed.");
**image2D = (uint8_t) malloc ((*width)*(*height)*sizeof(int8_t));
if (image2D==NULL) printf("Allocating memory for image in memory failed.");
//Make image2D point to parts of image1D to make a 2D array of image1D
for (i=0;i<480;i++){
image2D[i][0]=image1D[(i*640)];
}
return 0;
Error :
if(error<0){
printf("Error during card initialization \n");
DisplayIMAQError(error);
}
return 0;
}
/*******************************************************************************************
AnalogueCardClose
Closes the interface and the session
unsigned int32_t *Sid Session ID used to interact with card
unsigned int32_t *Iid Interface ID used to interact with card
*******************************************************************************************/
int AnalogueCardClose(uint32_t *Sid, uint32_t *Iid)
{
if(Sid)
imgClose (*Sid, TRUE);
if(Iid)
imgClose (*Iid, TRUE);
return 0;
}
int main(void)
{
return(0);
}