mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-21 03:10:02 +02:00
Added examples for client and receiver main
git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorsPackage@52 08cae9ef-cb74-4d14-b03a-d7ea46f178d7
This commit is contained in:
parent
c004e72fbb
commit
ef3afe8b0f
91
manual/manual-api/mainClient.cpp
Normal file
91
manual/manual-api/mainClient.cpp
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
/**
|
||||||
|
\file mainClient.cpp
|
||||||
|
|
||||||
|
This file is an example of how to implement the slsDetectorUsers class
|
||||||
|
You can compile it linking it to the slsDetector library
|
||||||
|
|
||||||
|
gcc mainClient.cpp -L lib -l SlsDetector -lm -lpthread
|
||||||
|
|
||||||
|
where lib is the location of libSlsDetector.so
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include "slsDetectorUsers.h"
|
||||||
|
#include "detectorData.h"
|
||||||
|
|
||||||
|
/** Definition of the data callback which simply prints out the number of points received and teh frame number */
|
||||||
|
int dataCallback(detectorData *pData, int iframe, void *pArg)
|
||||||
|
{
|
||||||
|
std::cout << "dataCallback: " << pData->npoints << " " << pData->npy << "Frame number: " << iframe << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**example of a main program using the slsDetectorUsers class */
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
int id=0;
|
||||||
|
/** if specified, argv[2] is used as detector ID (default is 0)*/
|
||||||
|
if (argc>=3)
|
||||||
|
id=atoi(argv[2]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** slsDetectorUsers is instantiated */
|
||||||
|
slsDetectorUsers *pDetector = new slsDetectorUsers (id);
|
||||||
|
|
||||||
|
|
||||||
|
/** if specified, argv[1] is used as detector config file (necessary at least the first time it is called to properly configure advanced settings in the shared memory)*/
|
||||||
|
if (argc>=2)
|
||||||
|
pDetector->readConfigurationFile(argv[1]);
|
||||||
|
|
||||||
|
/** Setting the detector online (should be by default */
|
||||||
|
pDetector->setOnline(1);
|
||||||
|
/** defining the detector size */
|
||||||
|
int minX, minY=0, sizeX, sizeY=1;
|
||||||
|
pDetector->getDetectorSize(minX, minY, sizeX, sizeY);
|
||||||
|
std::cout << "X: Start=" << minX << ", Size= " << sizeX << std::endl;
|
||||||
|
std::cout << "Y: Start=" << minY << ", Size= " << sizeY << std::endl;
|
||||||
|
pDetector->setDetectorSize(0,0,7680,1);
|
||||||
|
std::cout << pDetector->getDetectorDeveloper() << std::endl;
|
||||||
|
|
||||||
|
/** registering data callback */
|
||||||
|
pDetector->registerDataCallback(&dataCallback, NULL);
|
||||||
|
|
||||||
|
/** checking detector status and exiting if not idle */
|
||||||
|
int status = pDetector->getDetectorStatus();
|
||||||
|
if (status != 0){
|
||||||
|
std::cout << "Detector not ready: " << slsDetectorUsers::runStatusType(status) << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** checking and setting detector settings */
|
||||||
|
std::cout << "settings: " << slsDetectorUsers::getDetectorSettings(pDetector->setSettings()) << std::endl;
|
||||||
|
pDetector->setSettings(slsDetectorUsers::getDetectorSettings("standard"));
|
||||||
|
std::cout << "settings: " << slsDetectorUsers::getDetectorSettings(pDetector->setSettings()) << std::endl;
|
||||||
|
|
||||||
|
/** Settings exposure time to 10ms */
|
||||||
|
pDetector->setExposureTime(10000000);
|
||||||
|
|
||||||
|
/** Settings exposure time to 100ms */
|
||||||
|
pDetector->setExposurePeriod(100000000);
|
||||||
|
|
||||||
|
/** Settingsnumber of frames to 30 */
|
||||||
|
pDetector->setNumberOfFrames(30);
|
||||||
|
|
||||||
|
/** start measurement */
|
||||||
|
pDetector->startMeasurement();
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
usleep(100000);
|
||||||
|
status = pDetector->getDetectorStatus();
|
||||||
|
if (status == 0 || status == 1|| status == 3)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/** returning when acquisition is finished or data are avilable */
|
||||||
|
|
||||||
|
|
||||||
|
delete pDetector;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
114
manual/manual-api/mainReceiver.cpp
Normal file
114
manual/manual-api/mainReceiver.cpp
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
/* A simple server in the internet domain using TCP
|
||||||
|
The port number is passed as an argument
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
\file mainReceiver.cpp
|
||||||
|
|
||||||
|
|
||||||
|
This file is an example of how to implement the slsDetectorUsers class
|
||||||
|
You can compile it linking it to the slsDetector library
|
||||||
|
|
||||||
|
gcc mainReceiver.cpp -L lib -l SlsDetector -lm -lpthread
|
||||||
|
|
||||||
|
where lib is the location of libSlsDetector.so
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "slsReceiverUsers.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include <signal.h> //SIGINT
|
||||||
|
#include <cstdlib> //EXIT
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
/**
|
||||||
|
close file if receiver process is interrupted
|
||||||
|
*/
|
||||||
|
|
||||||
|
void closeFile(int p){
|
||||||
|
cout<<"close file in receiver"<<endl;
|
||||||
|
slsReceiverUsers::closeFile(p);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Instantiate the slsReceieverUsers class
|
||||||
|
The port number is passed as an argument
|
||||||
|
*/
|
||||||
|
slsReceiverUsers *receiver = new slsReceiverUsers(argc, argv, ret);
|
||||||
|
|
||||||
|
/*
|
||||||
|
return if could not open TCP socket for interfacing to client
|
||||||
|
*/
|
||||||
|
if(ret==1)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
|
||||||
|
/* Catch signal SIGINT to close files properly */
|
||||||
|
signal(SIGINT,closeFile);
|
||||||
|
|
||||||
|
/*register callbacks */
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
callback arguments are
|
||||||
|
filepath
|
||||||
|
filename
|
||||||
|
fileindex
|
||||||
|
datasize
|
||||||
|
|
||||||
|
return value is
|
||||||
|
0 raw data ready callback takes care of open,close,write file
|
||||||
|
1 callback writes file, we have to open, close it
|
||||||
|
2 we open, close, write file, callback does not do anything
|
||||||
|
|
||||||
|
|
||||||
|
registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg);
|
||||||
|
*/
|
||||||
|
|
||||||
|
//receiver->registerCallBackStartAcquisition(func,arg);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
callback argument is
|
||||||
|
total farmes caught
|
||||||
|
registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg);
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
//receiver->registerCallBackAcquisitionFinished(func,arg);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
args to raw data ready callback are
|
||||||
|
framenum
|
||||||
|
datapointer
|
||||||
|
file descriptor
|
||||||
|
guidatapointer (NULL, no data required)
|
||||||
|
|
||||||
|
NEVER DELETE THE DATA POINTER
|
||||||
|
REMEMBER THAT THE CALLBACK IS BLOCKING
|
||||||
|
|
||||||
|
registerCallBackRawDataReady(void (*func)(int, char*, FILE*, char*, void*),void *arg);
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
//receiver->registerCallBackRawDataReady(func,arg);
|
||||||
|
|
||||||
|
|
||||||
|
/* start receiver to listen for commands from the client (and data from detectors when expected */
|
||||||
|
|
||||||
|
receiver->start();
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
@ -62,9 +62,9 @@ HIDE_FRIEND_COMPOUNDS = NO
|
|||||||
|
|
||||||
INTERNAL_DOCS = NO
|
INTERNAL_DOCS = NO
|
||||||
|
|
||||||
SHOW_INCLUDE_FILES = NO
|
SHOW_INCLUDE_FILES = YES
|
||||||
|
|
||||||
SHOW_FILES = NO
|
SHOW_FILES = YES
|
||||||
|
|
||||||
SHOW_NAMESPACES = NO
|
SHOW_NAMESPACES = NO
|
||||||
|
|
||||||
@ -78,9 +78,10 @@ USE_PDFLATEX = YES
|
|||||||
|
|
||||||
LATEX_HIDE_INDICES = YES
|
LATEX_HIDE_INDICES = YES
|
||||||
|
|
||||||
|
SOURCE_BROWSER = YES
|
||||||
|
|
||||||
PREDEFINED = __cplusplus
|
PREDEFINED = __cplusplus
|
||||||
|
|
||||||
INPUT = slsDetectorUsers.h detectorData.h slsReceiverUsers.h
|
INPUT = slsDetectorUsers.h detectorData.h slsReceiverUsers.h mainClient.cpp mainReceiver.cpp
|
||||||
|
|
||||||
OUTPUT_DIRECTORY = slsDetectorUsersDocs
|
OUTPUT_DIRECTORY = slsDetectorUsersDocs
|
||||||
|
Loading…
x
Reference in New Issue
Block a user