DAS  3.1.6 - 18/09/2017
Simple camera test.
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <io.h>
#include <conio.h>
#include <stdio.h>
#include <windows.h>
#include <malloc.h>
#include <conio.h>
#include "dcl.h"
struct camera {
double expo; // Time exposure
double temp; // CCD Temp
int gain; // 0..3 CCD gain
int vbin; // Vertical binning
int hbin; // Horiz. binning
}CAM;
// CCD & Camera vars
ccd DC_CCD; // CCD settings
ptf DC_HP; // Platform settings
config Cfg; // Camera controls & Options
void Status(void)
{
double t;
char buf[256];
puts("");
printf("Time exp. : [%.3lf], CCD Gain: [%d], Binning (HxV): [%dx%d]\n", CAM.expo, CAM.gain, CAM.hbin, CAM.vbin);
t = DC_GetTemp(buf, CELSIUS, 0);
printf("CCD Temp..: [%.3lfC], Cool-Pwr.: [%.1lf%%], BckGnd: [%ld], cpu overhead: [%ld] ms\n\n", t, DC_GetPower(Cfg.FDL_PCI_Index), DC_BckGnd(Cfg.FDL_PCI_Index), DC_BckBusy(Cfg.FDL_PCI_Index));
}
void Menu(void)
{
puts(" Available commands:\n");
puts("1 - Time exposure");
puts("2 - Vertical binning");
puts("3 - Horizzontal binning");
puts("4 - Square binning");
puts("5 - CCD Gain");
puts("6 - Set temperature");
puts("7 - Get an Image");
puts("8 - Get a Dark image");
puts("9 - Get Region of interest");
puts("D - Dump image");
puts("F - Save current image");
puts("N - Get # frames");
puts("S - Show current status");
puts("T - GetCCD with hardware trigger");
puts("P - Set cooler power");
puts("x - Stop Background");
puts("X - Start Background");
puts("Q - Exit\n");
printf("Command: ");
}
// This procedure show exposure countdown
void __stdcall expo(const char *str)
{
printf("Expose: %s\r", str);
}
// This procedure show percentage value 0-100%
void __stdcall vrange(const char *str, int perc)
{
static int vopen, vclose;
if(str == NULL && vopen)
{
vclose = 1;
putchar('*');
}
if(str != NULL && vopen == 0)
{
vopen = 1;
printf("\n%s [", str);
}
if(perc == 100 && vclose)
{
vopen = vclose = 0;
puts("]");
}
}
void Pause(void)
{
puts("Press any key to continue....");
_getch();
}
void Dump(U16 *mem)
{
int y;
for(y = 0; y < 16384; y++)
{
if((y % 8) == 0)
{
printf("\n[%05d] %05u ", y, mem[y]);
}
else
printf("%05u ", mem[y]);
}
puts("");
}
// This file can be viewed as raw image using Vista
void SaveImage(char *str, U16 *m)
{
int fd, y, n = (DC_CCD.dx / CAM.hbin) << 1;
U16 *ptr = m;
fd = open(str, O_WRONLY | O_CREAT | O_BINARY, S_IWRITE);
if(fd >= 0)
{
for(y = 0; y < (DC_CCD.dy / CAM.vbin); y++)
{
write(fd, ptr, n);
ptr += (DC_CCD.dx / CAM.hbin);
}
close(fd);
}
else printf("Error! Image not saved\n");
}
void Input(char *tit, char *buf)
{
printf("\n%s", tit);
gets(buf);
puts("");
}
U16 *mem;
int main()
{
int er, p[4], n, c;
char buf[256], com, par[256];
long sn;
double a;
CAM.expo = 0.01;
CAM.vbin = 1;
CAM.hbin = 1;
Cfg.FDL_PCI_Index = 0;
DC_Ver(buf);
printf("\nTest Program for DTA DCL Library, Rev.%s\n\n", buf);
Pause();
// I use this command only when I debug the program!
// Set the DCL default directory. As default DCL look into the current directory.
//DC_SetPathName("d:/dta_src_jobs/cameralibrary/bin/dcl/");
// Retrive camera selection and settings made with dcs.exe command and saved into camera.cfg file
if(DC_LoadCameraConfig("camera.cfg", &Cfg))
{
printf("I/O error reading camera config\n");
return 1;
}
// Init the camera
DC_OpenByConfig(&Cfg, 0, expo, vrange);
if(er)
{
puts(DC_ErrorMessage(er));
Pause();
}
else
{
// Retrive CCD information by dcl
DC_RWData(CCD_INFO, READ_DATA, (void *) &DC_CCD, Cfg.FDL_PCI_Index);
printf("\nCamera Found. SN [%lu]\n\n", sn);
mem = malloc((size_t) ((long) DC_CCD.dx * (long) DC_CCD.dy * 2));
if(mem)
{
do
{
Menu();
com = _getche();
switch(com)
{
case '0': Input("A/D channel (0-7): ", buf);
sscanf(buf, "%d", &n);
printf("AD[%d] = %d\n", n, DC_GetAD(n, Cfg.FDL_PCI_Index));
break;
case '1': Input("Time Exp.: ", buf);
sscanf(buf, "%lf", &CAM.expo);
break;
case '2': Input("V. Bin: ", buf);
sscanf(buf, "%d", &CAM.vbin);
DC_SetBinning(CAM.hbin, CAM.vbin, Cfg.FDL_PCI_Index);
break;
case '3': Input("H. Bin: ", buf);
sscanf(buf, "%d", &CAM.hbin);
DC_SetBinning(CAM.hbin, CAM.vbin, Cfg.FDL_PCI_Index);
break;
case '4': Input("Binning: ", buf);
sscanf(buf, "%d", &CAM.hbin);
CAM.vbin = CAM.hbin;
DC_SetBinning(CAM.hbin, CAM.vbin, Cfg.FDL_PCI_Index);
break;
case '5': Input("Gain: ", buf);
sscanf(buf, "%d", &CAM.gain);
DC_SetGain(CAM.gain, Cfg.FDL_PCI_Index);
break;
case '6': Input("CCD Temp.: ", buf);
sscanf(buf, "%lf", &CAM.temp);
DC_SetTemp(CAM.temp, CELSIUS, Cfg.FDL_PCI_Index);
break;
case '7': DC_GetCCD(1, CAM.expo, mem, Cfg.FDL_PCI_Index);
break;
case '8': DC_GetCCD(0, CAM.expo, mem, Cfg.FDL_PCI_Index);
break;
case '9': Input("X Start: ", buf);
sscanf(buf, "%d", &p[0]);
Input("Y Start: ", buf);
sscanf(buf, "%d", &p[1]);
Input("X Width: ", buf);
sscanf(buf, "%d", &p[2]);
Input("Y Width: ", buf);
sscanf(buf, "%d", &p[3]);
DC_GetWinCCD(1, CAM.expo, p[0], p[1], p[2], p[3], mem, Cfg.FDL_PCI_Index);
break;
case 'd':
case 'D': Dump(mem);
break;
case 'f':
case 'F': Input("File name: ", buf);
SaveImage(buf, mem);
break;
case 'n':
case 'N': Input("Frames: ", buf);
Input("Save the images (Y/N): ", par);
sscanf(buf, "%d", &n);
for(c = 0; c < n; c++)
{
printf("Image %d of %d\n", c, n);
DC_GetCCD(1, CAM.expo, mem, Cfg.FDL_PCI_Index);
if(par[0] == 'y' || par[0] == 'Y')
{
sprintf(buf, "frame_%04d.raw", c);
SaveImage(buf, mem);
}
}
break;
case 'e': printf("\nEnvironment temperature = %.lf\n", (((F64) DC_GetAD(1, Cfg.FDL_PCI_Index) * (2.5 / 4096) * 10e2 / 4.99 - 273.15)));
break;
case 's':
case 'S': Status();
break;
case 'p':
case 'P':
Input("Cooler Power: ", buf);
sscanf(buf, "%lf", &a);
break;
case 'x': DC_StopNow(); break;
case 'X': DC_StartNow(); break;
case 'q':
case 'Q':
break;
case 't':
case 'T':
DC_TGetCCD(0, CAM.expo, mem, Cfg.FDL_PCI_Index);
break;
case 'j': DC_SetFW(0, 1, 0, Cfg.FDL_PCI_Index);
break;
case 'y': DC_SetFW(0, 1, 0, Cfg.FDL_PCI_Index);
break;
default: puts("Unknown command");
}
if(er)
{
puts(DC_ErrorMessage(er));
Pause();
break;
}
}while(com != 'Q' && com != 'q');
}
else
{
puts("Memory allocation error!");
return 1;
}
free(mem);
}
return 0;
}
______________________________________________________________________________________
Generated on Mon Sep 18 2017 11:47:03 for DAS - Rel. 3.1.6 - 18/09/2017.