Commit 423eb2f0 authored by cyclops's avatar cyclops

perform stabilisation for acquisition

parent 7235413a
......@@ -119,7 +119,7 @@ static const int32 COUNT_IGNORE = 3; // frame count for initilize camera
#define DEFAULT_TIME 0.1
#define DEFAULT_HEIGHT 2048
#define DEFAULT_WIDTH 2048
static const std::string TERMINATOR = "\r";
static const std::string TERMINATOR = "\r\n";
static const int32 COUNTING = 1;
......
......@@ -23,6 +23,9 @@
#include "Utilities/Counter.h"
#include <cstdio>
#include "CImg.h"
using namespace cimg_library;
using namespace std;
using namespace boost;
......@@ -46,7 +49,7 @@ RealPslDriver::~RealPslDriver() {
* init
*/
void RealPslDriver::init() {
//readInfos();
readInfos();
}
/*
......@@ -61,7 +64,7 @@ void RealPslDriver::clear() {
void RealPslDriver::writeParam() {
ostringstream buf_conf;
std::size_t found ;
string err;
......@@ -70,14 +73,18 @@ void RealPslDriver::writeParam() {
err = writeAndRead(buf_conf.str(), TERMINATOR);
buf_conf.str("");
buf_conf.clear();
if (err != "True") {
found = err.find("True");
if (found==std::string::npos)
{
cerr << "error SetAcquisitionMode " << endl;
}
buf_conf << "SetAutoSave;1";
err = writeAndRead(buf_conf.str(), TERMINATOR);
buf_conf.str("");
buf_conf.clear();
if (err != "True") {
found = err.find("True");
if (found==std::string::npos)
{
cerr << "error SetAutoSave " << endl;
}
......@@ -85,7 +92,9 @@ void RealPslDriver::writeParam() {
err = writeAndRead(buf_conf.str(), TERMINATOR);
buf_conf.str("");
buf_conf.clear();
if (err != "True") {
found = err.find("True");
if (found==std::string::npos)
{
cerr << "error SetShowAverage " << endl;
}
......@@ -93,25 +102,35 @@ void RealPslDriver::writeParam() {
err = writeAndRead(buf_conf.str(), TERMINATOR);
buf_conf.str("");
buf_conf.clear();
if (err != "True") {
found = err.find("True");
if (found==std::string::npos)
{
cerr << "error SetBrightPixel " << endl;
}
buf_conf << "SetIntensifierGain;"<< boost::format("%03d") % owner()->gain();
buf_conf << "SetIntensifierGain;"<< boost::format("%02d") % owner()->gain();
err = writeAndRead(buf_conf.str(), TERMINATOR);
buf_conf.str("");
buf_conf.clear();
if (err != "True") {
found = err.find("True");
if (found==std::string::npos)
{
cerr << "error SetIntensifierGain " << endl;
}
if (owner()->acqmode()==0){
owner()->nbSlicesAcq=1;
}
owner()->nbFrame=owner()->nbSlicesAcq();
// buf_conf << "SetFrameNumber;"<< boost::format("%02d") % owner()->nbSlicesAcq();
buf_conf << "SetFrameNumber;"<< owner()->nbSlicesAcq();
err = writeAndRead(buf_conf.str(), TERMINATOR);
buf_conf.str("");
buf_conf.clear();
found = err.find("True");
if (found==std::string::npos)
{
cerr << "error SetIntensifierGain " << endl;
}
// owner()->nbFrame=1;
// buf_conf << "SetFrameNumber;"<< boost::format("%03d") % owner()->nbFrame();
// err = writeAndRead(buf_conf.str(), TERMINATOR);
// buf_conf.str("");
// buf_conf.clear();
// if (err != "True") {
// cerr << "error SetFrameNumber " << endl;
// }
}
......@@ -121,23 +140,35 @@ void RealPslDriver::writeParam() {
void RealPslDriver::synchroniseRead() {
string err;
int32 i;
std::size_t found ;
cout << "m_TimeCounter" <<m_TimeCounter.getTime()<< endl;
//sleep(5);
// owner()->setTimeoutValue( owner()->time.setpoint());
do {
// do {
err = writeAndRead("WaitForImage", TERMINATOR);
cout << "Waiting For Image" << endl;
} while ((err == "False") && (i++ <10 ));
// if (err != "True") {
// cerr << "error acquisition " << endl;
// } else {
// stop();
// sleep(1);
// } while ((err != "True") && (i++ <10 ));
// if (err != "True") {
// cerr << "error acquisition " << endl;
// } else {
// stop();
//sleep(2);
string buf;
owner()->connect();
Counter c1;
cout << "<-- GetImage" << endl;
owner()->write("GetImage", TERMINATOR);
buf = owner()->read(16);
if (owner()->acqmode()==1){
buf = owner()->read(23);
}else{
buf = owner()->read(21);
}
// owner()->disconnect();
cout << "--> buf " << buf << endl;
typedef tokenizer<char_separator<char> > tokenizer;
......@@ -146,6 +177,7 @@ void RealPslDriver::synchroniseRead() {
tokenizer::iterator iter = tok1.begin();
if (iter != tok1.end()) {
cout << " iter 1 : " << *iter << endl;
string format = lexical_cast<string>(*iter);
++iter;
if (iter != tok1.end()) {
cout << " iter 2 : " << *iter << endl;
......@@ -159,27 +191,54 @@ void RealPslDriver::synchroniseRead() {
cout << " iter 4 : " << *iter << endl;
int32 size = xsize * ysize;//lexical_cast<int32>(*iter);
//sleep(5);
found = format.find("I16");
if (found != std::string::npos)
{
cerr << "datas type I16" << endl;
string datas = owner()->read(size * 2);
uint16* tmp = (uint16*) (datas.c_str());
cout << "datas size = " << datas.size() << endl;
int32* data = owner()->data();
int32 dataSize = owner()->dataSize();
//memset(data, 0, dataSize * sizeof(int32));
float64 sum = 0;
if ((data != NULL) && (size == dataSize)) {
CImg<uint16> img(tmp, xsize, ysize);
img.permute_axes("yxzc");
img.mirror("x");
memcpy(tmp, img.data(), xsize * ysize * sizeof(uint16));
for (int32 x = 0; x < xsize; ++x) {
for (int32 y = 0; y < ysize; ++y) {
data[x + y * xsize] = tmp[x + y * xsize];
sum += (float64) data[y + x * ysize];
}
}
owner()->data.sendEvent();
} else {
cerr << "error mask " << endl;
}
}else{
cerr << "datas type F" << endl;
owner()->setTimeoutValue(10);
string datas = owner()->read(size * 4);
uint32* tmp = (uint32*) (datas.c_str());
cout << "datas size = " << datas.size() << endl;
int32* data = owner()->data();
int32 dataSize = owner()->dataSize();
float64 sum = 0;
if ((data != NULL) && (size == dataSize)) {
CImg<uint32> img(tmp, xsize, ysize);
img.permute_axes("yxzc");
img.mirror("x");
memcpy(tmp, img.data(), xsize * ysize * sizeof(uint32));
for (int32 x = 0; x < xsize; ++x) {
for (int32 y = 0; y < ysize; ++y) {
// data[y + (xsize - x - 1) * ysize] = tmp[x + y * xsize];
data[y + x * ysize] = tmp[y + x * ysize];
data[x + y * xsize] = tmp[x + y * xsize];
sum += (float64) data[y + x * ysize];
}
}
owner()->sum = sum;
owner()->data.sendEvent();
// for (int32 i = 0; i < dataSize; ++i) {
// data[i] = (int32) datas[i];
// sum += (float64) data[i];
// }
} else {
cerr << "error mask " << endl;
......@@ -188,6 +247,7 @@ void RealPslDriver::synchroniseRead() {
}
}
}
}
owner()->disconnect();
cout << "read time:" << c1.getTime() << endl;
......@@ -207,28 +267,38 @@ void RealPslDriver::read() {
void RealPslDriver::start() {
ostringstream buf_conf;
float64 exp_time = owner()->time.setpoint();
std::size_t found;
string err;
if (owner()->acqmode()==3){
owner()->time.setpoint=exp_time*owner()->nbSlicesAcq();
}
buf_conf << "SetRecordPath;"<< "z:"<<owner()->fileDirectory();
err = writeAndRead(buf_conf.str(), TERMINATOR);
buf_conf.str("");
buf_conf.clear();
if (err != "True") {
found = err.find("True");
if (found==std::string::npos)
{
cerr << "error SetRecordPath; " << endl;
}
buf_conf << "SetRecordName;"<< owner()->fileName();
err = writeAndRead(buf_conf.str(), TERMINATOR);
buf_conf.str("");
buf_conf.clear();
if (err != "True") {
found = err.find("True");
if (found==std::string::npos)
{
cerr << "error SetRecordName; " << endl;
}
buf_conf << "SetRecordNumber;"<< owner()->numor();
err = writeAndRead(buf_conf.str(), TERMINATOR);
buf_conf.str("");
buf_conf.clear();
if (err != "True") {
found = err.find("True");
if (found==std::string::npos)
{
cerr << "error SetRecordNumber;; " << endl;
}
......@@ -236,7 +306,9 @@ void RealPslDriver::start() {
err = writeAndRead(buf_conf.str(), TERMINATOR);
buf_conf.str("");
buf_conf.clear();
if (err != "True") {
found = err.find("True");
if (found==std::string::npos)
{
cerr << "error SetRecordTag; " << endl;
}
......@@ -247,7 +319,23 @@ void RealPslDriver::start() {
err = writeAndRead(buf_conf.str(), TERMINATOR);
err = writeAndRead("Snap", TERMINATOR);
if (err != "True") {
const char* home = getenv("HOME");
string homePath;
if (home != 0) {
homePath = string(home)+"/lastfile.txt";
}
ofstream file(homePath, ios::out);
file << owner()->fileName() << owner()->numor()<< endl;
file.close();
found = err.find("True");
cout << "found Snap " <<found<< " " << std::string::npos<<endl;
if (found==std::string::npos)
{
cerr << "error acquisition " << endl;
owner()->startActivated = false;
owner()->commandProgression = PROGRESSION_END_DEVICE_CONTAINER;
......@@ -274,6 +362,11 @@ void RealPslDriver::pause() {
void RealPslDriver::stop() {
ostringstream buf_cmd2;
writeAndRead("Stop", TERMINATOR);
int32 status = 0;
status |= END;
owner()->computeGateStatus(status);
owner()->computeAcquisitionStatus(0);
owner()->computeDetectorStatus(0);
owner()->startActivated = false;
owner()->commandProgression = PROGRESSION_END_DEVICE_CONTAINER;
}
......@@ -327,14 +420,30 @@ std::string RealPslDriver::writeAndRead(const std::string& command,
const std::string& terminator) {
string buf;
owner()->connect();
owner()->setTimeoutValue(6000);
cout << "<-- " << command << endl;
owner()->write(command, terminator);
cout << "<-- OK " << command << endl;
buf = owner()->read();
cout << "--> " << buf << endl;
owner()->disconnect();
usleep(100000);
return buf;
}
std::string RealPslDriver::writeAndRead(const std::string& command,
const std::string& terminator,const uint32 nbchar) {
string buf;
owner()->connect();
// owner()->setTimeoutValue(5);
cout << "<-- " << command << endl;
owner()->write(command, terminator);
cout << "<-- OK nb char " << command << endl;
buf = owner()->read(nbchar);
cout << "--> " << buf << endl;
owner()->disconnect();
return buf;
}
}
......@@ -106,6 +106,7 @@ public:
private:
std::string writeAndRead(const std::string& command, const std::string& terminator);
std::string writeAndRead(const std::string& command, const std::string& terminator,const uint32 nbchar);
int16 m_Handle;
int16 lNumCameras;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment