#include <stdio.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#if defined(__linux__)
#define SLEEP usleep
#define MILLIS 1000
#elif defined(__APPLE__)
#define SLEEP usleep
#define MILLIS 1000
#include <unistd.h>
#elif defined(_WIN32)
#include <Windows.h>
#define SLEEP Sleep
#define MILLIS 1
#endif
{
int i=0;
double res =0.0;
for(i=0;i<NPixel;i++)
res+= (double)Img[i];
return res/(double)NPixel;
}
double mean_double(
double * Img,
UInt16 NPixel)
{
int i=0;
double res =0.0;
for(i=0;i<NPixel;i++)
res+= Img[i];
return res/(double)NPixel;
}
{
int i=0;
memset(hist,
'\0',65535*
sizeof(
UInt16));
for(i=0;i<2048;i++)
hist[Img[i]]++;
}
int main(void)
{
UInt16* Img= NULL,hist[65535],AppliedDT=0;
int loop = 1;
int i_c;
char header[1024]="";
int integFrames=10;
double read_bytes=0,total_bytes=0;
int i=0,j=0,k=0,out=0;
short trig=0;
double gateoff=0;
double gateoff_array[3] = { 0 };
double counts[3] = {0};
double *x = NULL,*y= NULL, *z = NULL, *Imgd=NULL;
double* data= NULL;
char c=0,*fname=NULL;
int counter = 0, aggressor=0;
FILE* f= NULL;
time_t start,stop,leap;
char *menu_strings[] = { "Live mode: write on stdout 10 images",
"Holdoff: mean number of photons at different holdoff values",
"Dead-time corrector improves the image quality",
"Background subtraction: 2 output files, with and without BG",
"Gate: 1000 images normal, 1000 images with gate 3 ns shift 5 ns",
"Synchronization output",
"Background statistics",
"Gate: calibrate the length of the gate signal",
"Triple gate mode",
"Read and write test images",
"Continuous acquisition on file",
"Continuous acquisition in memory",
"Reset overcurrent protection"
};
Imgd =(double*) calloc(1, 2048* sizeof(double));
data =(double*) calloc(1, 2048* sizeof(double));
x =(double*) calloc(1, 65535* sizeof(double));
y =(double*) calloc(1, 65535* sizeof(double));
z = (double*)calloc(1, 65535 * sizeof(double));
while (loop) {
printf("\n*******************************************************************************\n");
printf(" Hermes Test program\n");
printf("*******************************************************************************\n");
for (i = 0; i < sizeof(menu_strings) / sizeof(char*); i++) {
printf("\t%c) %s\n", i + 'a', menu_strings[i]);
}
printf("\tq) Quit\n> ");
c = getchar();
getchar();
if (c >= 'a' && c <= 'a' + sizeof(menu_strings) / sizeof(char*) - 1) {
printf("*******************************************************************************\n");
printf("%s\n", menu_strings[c - 'a']);
printf("*******************************************************************************\n");
}
switch (c)
{
case 'a':
for (i = 0; i < 10; i++)
{
printf("Image %d:\n", i);
for (j = 0; j < 32; j++)
{
for (k = 0; k < 32; k++)
printf("%d ", Img[32 * j + k]);
printf("\n");
}
else
break;
}
break;
case 'b':
k = 0;
printf("Acquiring:\n");
if ((f = fopen("DTValues.txt", "w")) == NULL)
{
printf("Unable to open the output file.\n");
break;
}
{
data[k] = 0.0;
x[k] = (double)AppliedDT;
data[k] = mean_double(Imgd, 2048);
printf("%d ns, Applied %d ns, %f\n", i, AppliedDT, data[k]);
fprintf(f, "%d %f\n", i, data[k]);
k++;
}
printf("\nDead-time calibration\n");
for (i = 0; i < k; i++)
{
printf("%f %f\n", x[i], data[i]);
}
fclose(f);
break;
case 'c':
printf("Acquire the image using the dead-time correction\n");
printf("\n\n\nClose the camera shutter and press ENTER...\n");
getchar();
for (i = 0; i < 2048; i++)
if (data[i] <= 65535)
Img[i] = (
UInt16)floor(data[i] + 0.5);
else
Img[i] = 65535;
printf("\n\n\nOpen the camera shutter and press ENTER...\n");
getchar();
printf("The the dead-time corrected image was acquired and stored on the hard disk succesfully!\n");
printf("\n\nAcquire the reference image without the dead-time correction\n");
printf("\n\n\nClose the camera shutter and press ENTER...\n");
getchar();
for (i = 0; i < 2048; i++)
if (data[i] <= 65535)
Img[i] = (
UInt16)floor(data[i] + 0.5);
else
Img[i] = 65535;
printf("\n\n\nOpen the camera shutter and press ENTER...\n");
getchar();
printf("The the dead-time corrected image was acquired and stored on the hard disk succesfully!\n");
break;
case 'd':
printf("\n\n\nClose the camera shutter and press ENTER...\n");
getchar();
for (i = 0; i < 2048; i++)
if (data[i] <= 65535)
Img[i] = (
UInt16)floor(data[i] + 0.5);
else
Img[i] = 65535;
printf("Open the camera shutter and press ENTER ...\n");
getchar();
break;
case 'e':
printf("Acquiring the reference image ...\n");
printf("Save the reference image ...\n");
printf("Acquiring the gated image ...\n");
printf("Save the gated image ...\n");
break;
case 'f':
printf("\n\nNo output ...\n");
printf("Press ENTER to continue\n");
getchar();
printf("\n\nGate synchronization signal ...\n");
printf("Press ENTER to continue\n");
getchar();
printf("\n\nFrame synchronization signal ...\n");
printf("Press ENTER to continue\n");
getchar();
printf("\n\nWait for the trigger input ...\n");
while (trig != 1)
printf("Trigger signal received!\n");
break;
case 'g':
f = fopen("BgHist.txt", "w");
printf("Close the camera shutter and press ENTER ...\n");
getchar();
printf("Acquiring: ");
for (i = 150; i >= 50; i -= 50)
{
printf("%d ns ", i);
for (k = 0; k < 2048; k++)
if (data[k] <= 65535)
Img[k] = (
UInt16)floor(data[k] + 0.5);
else
Img[k] = 65535;
Hist(Img, hist);
for (j = 0; j < 65535; j++)
fprintf(f, "%hd ", hist[j]);
fprintf(f, "\n");
}
printf("\n");
fclose(f);
break;
case 'h':
printf("Which counter do you want to acquire?\n");
scanf("%d", &counter);
if ((counter < 1) || (counter > 3))
{
printf("Insert a value between 1 and 3!\n");
break;
}
printf("Expose the Hermes camera to a time-independent luminous signal\n(room light might oscillate at 50 or 60 Hz)\nPress ENTER to continue ...\n");
getchar();
getchar();
if ((f = fopen("GateValues.txt", "w")) == NULL)
{
printf("Unable to open the output file.\n");
break;
}
gateoff = mean_double(data, 2048);
printf("Gate OFF counts: %.2f\n", gateoff);
fprintf(f, "Gate OFF counts: %.2f\n", gateoff);
printf("Acquiring:\n\nGate\t\tMean\t\tActual Gate\t\t\n");
for (i = 0; i <= 100; i += 1)
{
y[i] = mean_double(data, 2048);
y[i + 101] = y[i] / gateoff * 100;
x[i] = (double)i;
printf("%3.0f\t\t%.2f\t\t%.2f\n", x[i], y[i], y[i + 101]);
fprintf(f, "%.0f %.2f %.2f\n", x[i], y[i], y[i + 101]);
}
fclose(f);
printf("\n");
break;
case 'i':
fname = (char*)calloc(256, sizeof(char));
printf("Expose the Hermes camera to a luminuos signal (pulsed or constant)\nPress ENTER to continue ...\n");
getchar();
printf("Acquiring...\n");
sprintf(fname, "Triple gate mode.txt");
if ((f = fopen(fname, "w")) == NULL)
{
printf("Unable to open the file %s.\n", fname);
break;
}
for (counter = 1; counter <= 3; counter++)
{
gateoff_array[counter - 1] = mean_double(data, 2048);
printf("\nGate OFF counts on counter %d: %.2f\n", counter, gateoff_array[counter - 1]);
fprintf(f, "Gate OFF counts on counter %d: %.2f\n", counter, gateoff_array[counter - 1]);
}
for (j = -400; j < 400; j++)
{
if (error < 0) break;
for (counter = 1; counter <= 3; counter++)
{
counts[counter - 1] = mean_double(data, 2048);
}
printf("%d\t\t%.4f\t\t%.4f\t\t%.4f\n", j, counts[0] / gateoff_array[0] * 100, counts[2] / gateoff_array[2] * 100, counts[1] / gateoff_array[1] * 100);
fprintf(f, "%d\t\t%.4f\t\t%.4f\t\t%.4f\n", j, counts[0] / gateoff_array[0] * 100, counts[2] / gateoff_array[2] * 100, counts[1] / gateoff_array[1] * 100);
}
fclose(f);
printf("\n");
free(fname);
break;
case 'j':
printf("Acquiring 20 images and save them on the hard drive in the Hermes file format.\n");
printf("Read the images from the disk and print the value of the top-left-corner pixel for each frame.\n(Press ENTER to continue)\n");
getchar();
printf("Rows: %d, Columns: %d\n", header[100], header[101]);
for (i = 1; i <= 20; i++)
{
printf("Image %d, pixel value = %hu\n", i, Img[0]);
}
break;
case 'k':
printf("\n");
printf("Input the number of frames of 10.40us to be integrated (suggested > 10 to avoid data loss):\n");
scanf("%d", &integFrames);
printf("Total integration time: %.2fus\n", (float)(10.40*integFrames));
printf("Continuous acquisition will be started and 10 memory dumps performed.\n");
printf("Press ENTER to start continuous acquisition...\n");
getchar();
getchar();
for (i = 1; i < 10; i++)
{
{
total_bytes = total_bytes + read_bytes;
printf("Acquired %f bytes in %d readout operation\n", total_bytes, i);
SLEEP(1 * MILLIS);
}
else
break;
}
printf("Acquisition saved to contacq.Hermes.\n");
break;
case 'l':
printf("\n");
printf("Input the number of frames of 10.40us to be integrated (suggested > 10 to avoid data loss):\n");
scanf("%d", &integFrames);
printf("Total integration time: %.2fus\n", (float)(10.40*integFrames));
printf("Continuous acquisition will be started and 10 memory dumps performed.\n");
printf("Press ENTER to start continuous acquisition...\n");
getchar();
getchar();
i = 1;
start = clock();
leap = start;
for (i = 1; i<11; i++)
{
{
total_bytes = total_bytes + read_bytes;
stop = clock();
printf("Acquired %.2f MB in %d readout operation, last rate %.2fMB/s, average rate %.2fMB/s\n", total_bytes / 1000000.0, i, (read_bytes / 1000000.0 / ((stop - leap) / (float)CLOCKS_PER_SEC)), (total_bytes / 1000000.0 / ((stop - start) / (float)CLOCKS_PER_SEC)));
leap = clock();
SLEEP(1 * MILLIS);
}
else
{
printf("ERROR!");
break;
}
}
break;
case 'm':
break;
case 'q':
loop = 0;
break;
}
}
if(Hermes)
Hermes = NULL;
free(Img);
free(Imgd);
free(data);
free(y);
free(x);
free(z);
printf("Press ENTER to continue\n");
getchar();
return 0;
}
Hermes software development kit.
#define MAX_DEAD_TIME
Maximum allowed dead-time in nanoseconds.
Definition: Hermes_SDK.h:87
unsigned short UInt16
Unsigned short integer (16 bit)
Definition: Hermes_SDK.h:70
#define MIN_DEAD_TIME
Minimum allowed dead-time in nanoseconds.
Definition: Hermes_SDK.h:83
HermesReturn HermesContAcqToMemoryGetBuffer(Hermes_H Hermes, double *total_bytes, BUFFER_H *buffer)
Dump the camera memory to the PC and pass the pointer to the image buffer in which acquisition is sto...
HermesReturn HermesContAcqToMemoryStop(Hermes_H Hermes)
Stop the continuous acquisition of data.
HermesReturn HermesContAcqToFileGetMemory(Hermes_H Hermes, double *total_bytes)
Dump the camera memory to the PC and save data to the file specified with the HermesContAcqToFileStar...
HermesReturn HermesContAcqToFileStart(Hermes_H Hermes, char *filename)
Put the camera in "continuous acquisition" mode.
HermesReturn HermesLiveSetModeON(Hermes_H Hermes)
Turn on the Live mode.
HermesReturn HermesContAcqToMemoryStart(Hermes_H Hermes)
Put the camera in "continuous acquisition" mode.
HermesReturn HermesContAcqToFileStop(Hermes_H Hermes)
Stop the continuous acquisition of data and close the output file.
HermesReturn HermesLiveSetModeOFF(Hermes_H Hermes)
Turn off the Live mode.
HermesReturn HermesLiveGetImg(Hermes_H Hermes, UInt16 *Img)
Get a Live image.
HermesReturn HermesSnapPrepare(Hermes_H Hermes)
Prepare the camera to the acquisition of a snap.
HermesReturn HermesSnapAcquire(Hermes_H Hermes)
Get a selected number of images.
HermesReturn HermesAverageImg(Hermes_H Hermes, double *Img, UInt16 counter)
Calculate the average image.
HermesReturn HermesSaveImgDisk(Hermes_H Hermes, UInt32 Start_Img, UInt32 End_Img, char *filename, OutFileFormat mode)
Save the selected images on the hard disk.
HermesReturn HermesSaveAveragedImgDisk(Hermes_H Hermes, UInt16 counter, char *filename, OutFileFormat mode, short isDouble)
Save the selected images on the hard disk.
HermesReturn HermesReadHermesFileFormatImage(char *filename, UInt32 ImgIdx, UInt16 counter, UInt16 *Img, char header[1024])
Read an integer (8 - 16 bit) Hermes image from file.
HermesReturn HermesResetOverilluminationProtection(Hermes_H Hermes)
Reset the internal overillumination protection circuit.
HermesReturn HermesConstr(Hermes_H *Hermes_in, CameraMode m, char *Device_ID)
Constructor.
HermesReturn HermesDestr(Hermes_H Hermes)
Destructor.
struct _Hermes_H * Hermes_H
Handle to the Hermes structure.
Definition: Hermes_SDK.h:192
HermesReturn
Error table.
Definition: Hermes_SDK.h:113
unsigned char * BUFFER_H
Handle to the Hermes buffer.
Definition: Hermes_SDK.h:195
@ Enabled
The function is enabled.
Definition: Hermes_SDK.h:177
@ Disabled
The function is disabled.
Definition: Hermes_SDK.h:176
@ HERMES_FILEFORMAT
Hermes custom file format.
Definition: Hermes_SDK.h:140
@ TIFF_NO_COMPRESSION
Multipage TIFF without compression.
Definition: Hermes_SDK.h:141
@ Continuous
The gate signal is always "ON".
Definition: Hermes_SDK.h:150
@ Pulsed
The gate signal is a square wave at 50MHz.
Definition: Hermes_SDK.h:151
@ OK
The function returned successfully.
Definition: Hermes_SDK.h:114
@ Frame
A 60 ns pulse every time a new frame is acquired.
Definition: Hermes_SDK.h:171
@ Gate_Clk
A square wave of 50 MHz and 50% duty cycle synchronized with the software gate signal and the camera ...
Definition: Hermes_SDK.h:170
@ None
No output signal.
Definition: Hermes_SDK.h:169
@ Normal
The camera settings are tuned by the software to avoid the overflow of the counters.
Definition: Hermes_SDK.h:161
HermesReturn HermesIsTriggered(Hermes_H Hermes, short *isTriggered)
Poll the camera for external trigger status.
HermesReturn HermesGetDeadTime(Hermes_H Hermes, UInt16 Val, UInt16 *ReturnVal)
Get the calibrated dead-time value.
HermesReturn HermesSetGateMode(Hermes_H Hermes, UInt16 counter, GateMode Mode)
Set the gate mode to continuous, coarse or pulsed (only counter 1)
HermesReturn HermesSetTripleGate(Hermes_H Hermes, State TripleGate_State, int StartShift, int FirstGateWidth, int SecondGateWidth, int ThirdGateWidth, int Gap1, int Gap2)
Set parameters for TripleGate mode.
HermesReturn HermesApplySettings(Hermes_H Hermes)
Apply settings to the camera.
HermesReturn HermesSetBackgroundSubtraction(Hermes_H Hermes, State s)
Enable or disable the hardware background subtraction.
HermesReturn HermesSetGateValues(Hermes_H Hermes, Int16 Shift, Int16 Length)
Change the fast Gate settings for counter 1.
HermesReturn HermesSetSyncInState(Hermes_H Hermes, State s, int frames)
Set the sync-in state.
HermesReturn HermesSetCameraPar(Hermes_H Hermes, UInt16 Exposure, UInt32 NFrames, UInt16 NIntegFrames, UInt16 NCounters, State Force8bit, State Half_array, State Signed_data)
Set the acquisition parameters for the camera.
HermesReturn HermesSetTriggerOutState(Hermes_H Hermes, TriggerMode Mode)
Select the output signal.
HermesReturn HermesSetBackgroundImg(Hermes_H Hermes, UInt16 *Img)
Load a background image to perform hardware background subtraction.
HermesReturn HermesSetAdvancedMode(Hermes_H Hermes, State s)
Change the operating mode.
HermesReturn HermesSetDeadTime(Hermes_H Hermes, UInt16 Val)
Update the dead-time setting.
HermesReturn HermesSetDeadTimeCorrection(Hermes_H Hermes, State s)
Enable or disable the dead-time correction.