Commit bf15aa20 authored by ics's avatar ics
Browse files

Merge branch 'V3.2_191' of...

Merge branch 'V3.2_191' of https://code.ill.fr/instrument-control/nomad-special-modules into V3.2_191
parents 6bb776df 71c5f5e3
......@@ -170,6 +170,7 @@ void RemoteLSSSimulation::postConfiguration() {
if (m_CountSpy != nullptr) {
m_CountSpy->attach(this);
registerUpdater(m_CountSpy->statusMessage, &RemoteLSSSimulation::updateCountStatusMessage, this);
registerUpdater(m_CountSpy->detSum, &RemoteLSSSimulation::updateCountDetSum, this);
updateCountStatusMessage();
}
}
......@@ -895,147 +896,163 @@ void RemoteLSSSimulation::resizeAll(int32 size) {
* updateCountStatusMessage
*/
void RemoteLSSSimulation::updateCountStatusMessage() {
string statusmes = m_CountSpy->statusMessage();
//cout << "status " << statusmes << " " << m_CountSpy << endl;
if (useSimulatedData() == true) {
string statusmes = m_CountSpy->statusMessage();
if (statusmes == acquisition::Count::WRITING_DATA_MESSAGE) {
acquisition::ExperimentData* title =
dynamic_cast<acquisition::ExperimentData*>(InstrumentManager::getInstance()->getFirstExperimentControllerByType(
acquisition::ExperimentData::TYPE));
if (title == nullptr) {
log(Level::s_Error) << " missing controller Title in this instrument" << endlog;
updateDataFromSimulation();
}
}
}
void RemoteLSSSimulation::updateDataFromSimulation() {
acquisition::ExperimentData* title =
dynamic_cast<acquisition::ExperimentData*>(InstrumentManager::getInstance()->getFirstExperimentControllerByType(
acquisition::ExperimentData::TYPE));
if (title == nullptr) {
log(Level::s_Error) << " missing controller Title in this instrument" << endlog;
commandStatus.setError();
commandProgression = 100;
return;
}
// Re-write data to detector controller
acquisition::Count* count = nullptr;
try {
count = dynamic_cast<acquisition::Count*>(InstrumentManager::getInstance()->getExperimentController(
m_CountSpy->countControllerName()));
} catch (InstrumentManager::ControllerNotFound& e) {
log(Level::s_Error) << " missing controller " << m_CountSpy->countControllerName() << " in this instrument"
<< endlog;
commandStatus.setError();
commandProgression = 100;
return;
}
getData();
cout << "received monitor " << m_DataResponse.monitor() << endl;
cout << "received response " << m_DataResponse.datas_size() << endl;
if (count->nMonitors() > 0) {
if (count->monitors[0]->data.getSize() > 0) {
count->monitors[0]->data()[0] = m_DataResponse.monitor();
count->monitors[0]->detSum.update(m_DataResponse.monitor());
}
}
if (m_DataResponse.datas_size() >= 1) {
Data data = m_DataResponse.datas(0);
int32* detdata = count->masterDetector->data();
float64 sum = 0.;
if ((data.sizex() * data.sizey()) == count->masterDetector->data.getSize()) {
for (int32 j = 0; j < data.data_size(); ++j) {
detdata[j] = data.data(j);
sum += detdata[j];
}
}
count->masterDetector->detSum.update(sum);
}
if (title->instrumentName() == "D33") {
if (m_DataResponse.datas_size() >= 2) {
try {
acquisition::DetectorElement* det =
dynamic_cast<acquisition::DetectorElement*>(InstrumentManager::getInstance()->getExperimentController(
"MultiDetector2"));
Data data = m_DataResponse.datas(1);
int32* detdata = det->data();
float64 sum = 0.;
if ((data.sizex() * data.sizey()) == det->data.getSize()) {
for (int32 j = 0; j < data.data_size(); ++j) {
detdata[j] = data.data(j);
sum += detdata[j];
}
}
det->detSum.update(sum);
} catch (InstrumentManager::ControllerNotFound& e) {
log(Level::s_Error) << " missing controller MultiDetector2 in this instrument" << endlog;
commandStatus.setError();
commandProgression = 100;
return;
}
// Re-write data to detector controller
acquisition::Count* count = nullptr;
}
if (m_DataResponse.datas_size() >= 3) {
try {
count = dynamic_cast<acquisition::Count*>(InstrumentManager::getInstance()->getExperimentController(
m_CountSpy->countControllerName()));
acquisition::DetectorElement* det =
dynamic_cast<acquisition::DetectorElement*>(InstrumentManager::getInstance()->getExperimentController(
"MultiDetector3"));
Data data = m_DataResponse.datas(2);
int32* detdata = det->data();
float64 sum = 0.;
if ((data.sizex() * data.sizey()) == det->data.getSize()) {
for (int32 j = 0; j < data.data_size(); ++j) {
detdata[j] = data.data(j);
sum += detdata[j];
}
}
det->detSum.update(sum);
} catch (InstrumentManager::ControllerNotFound& e) {
log(Level::s_Error) << " missing controller " << m_CountSpy->countControllerName() << " in this instrument"
<< endlog;
log(Level::s_Error) << " missing controller MultiDetector3 in this instrument" << endlog;
commandStatus.setError();
commandProgression = 100;
return;
}
getData();
cout << "received monitor " << m_DataResponse.monitor() << endl;
cout << "received response " << m_DataResponse.datas_size() << endl;
if (count->nMonitors() > 0) {
if (count->monitors[0]->data.getSize() > 0) {
count->monitors[0]->data()[0] = m_DataResponse.monitor();
count->monitors[0]->detSum.update(m_DataResponse.monitor());
}
}
if (m_DataResponse.datas_size() >= 1) {
Data data = m_DataResponse.datas(0);
int32* detdata = count->masterDetector->data();
}
if (m_DataResponse.datas_size() >= 4) {
try {
acquisition::DetectorElement* det =
dynamic_cast<acquisition::DetectorElement*>(InstrumentManager::getInstance()->getExperimentController(
"MultiDetector4"));
Data data = m_DataResponse.datas(3);
int32* detdata = det->data();
float64 sum = 0.;
if ((data.sizex() * data.sizey()) == count->masterDetector->data.getSize()) {
if ((data.sizex() * data.sizey()) == det->data.getSize()) {
for (int32 j = 0; j < data.data_size(); ++j) {
detdata[j] = data.data(j);
sum += detdata[j];
}
}
count->masterDetector->detSum.update(sum);
det->detSum.update(sum);
} catch (InstrumentManager::ControllerNotFound& e) {
log(Level::s_Error) << " missing controller MultiDetector4 in this instrument" << endlog;
commandStatus.setError();
commandProgression = 100;
return;
}
if (title->instrumentName() == "D33") {
if (m_DataResponse.datas_size() >= 2) {
try {
acquisition::DetectorElement* det =
dynamic_cast<acquisition::DetectorElement*>(InstrumentManager::getInstance()->getExperimentController(
"MultiDetector2"));
Data data = m_DataResponse.datas(1);
int32* detdata = det->data();
float64 sum = 0.;
if ((data.sizex() * data.sizey()) == det->data.getSize()) {
for (int32 j = 0; j < data.data_size(); ++j) {
detdata[j] = data.data(j);
sum += detdata[j];
}
}
det->detSum.update(sum);
} catch (InstrumentManager::ControllerNotFound& e) {
log(Level::s_Error) << " missing controller MultiDetector2 in this instrument" << endlog;
commandStatus.setError();
commandProgression = 100;
return;
}
}
if (m_DataResponse.datas_size() >= 3) {
try {
acquisition::DetectorElement* det =
dynamic_cast<acquisition::DetectorElement*>(InstrumentManager::getInstance()->getExperimentController(
"MultiDetector3"));
Data data = m_DataResponse.datas(2);
int32* detdata = det->data();
float64 sum = 0.;
if ((data.sizex() * data.sizey()) == det->data.getSize()) {
for (int32 j = 0; j < data.data_size(); ++j) {
detdata[j] = data.data(j);
sum += detdata[j];
}
}
det->detSum.update(sum);
} catch (InstrumentManager::ControllerNotFound& e) {
log(Level::s_Error) << " missing controller MultiDetector3 in this instrument" << endlog;
commandStatus.setError();
commandProgression = 100;
return;
}
}
if (m_DataResponse.datas_size() >= 4) {
try {
acquisition::DetectorElement* det =
dynamic_cast<acquisition::DetectorElement*>(InstrumentManager::getInstance()->getExperimentController(
"MultiDetector4"));
Data data = m_DataResponse.datas(3);
int32* detdata = det->data();
float64 sum = 0.;
if ((data.sizex() * data.sizey()) == det->data.getSize()) {
for (int32 j = 0; j < data.data_size(); ++j) {
detdata[j] = data.data(j);
sum += detdata[j];
}
}
det->detSum.update(sum);
} catch (InstrumentManager::ControllerNotFound& e) {
log(Level::s_Error) << " missing controller MultiDetector4 in this instrument" << endlog;
commandStatus.setError();
commandProgression = 100;
return;
}
}
if (m_DataResponse.datas_size() >= 5) {
try {
acquisition::DetectorElement* det =
dynamic_cast<acquisition::DetectorElement*>(InstrumentManager::getInstance()->getExperimentController(
"MultiDetector5"));
Data data = m_DataResponse.datas(4);
int32* detdata = det->data();
float64 sum = 0.;
if ((data.sizex() * data.sizey()) == det->data.getSize()) {
for (int32 j = 0; j < data.data_size(); ++j) {
detdata[j] = data.data(j);
sum += detdata[j];
}
}
det->detSum.update(sum);
} catch (InstrumentManager::ControllerNotFound& e) {
log(Level::s_Error) << " missing controller MultiDetector5 in this instrument" << endlog;
commandStatus.setError();
commandProgression = 100;
return;
}
if (m_DataResponse.datas_size() >= 5) {
try {
acquisition::DetectorElement* det =
dynamic_cast<acquisition::DetectorElement*>(InstrumentManager::getInstance()->getExperimentController(
"MultiDetector5"));
Data data = m_DataResponse.datas(4);
int32* detdata = det->data();
float64 sum = 0.;
if ((data.sizex() * data.sizey()) == det->data.getSize()) {
for (int32 j = 0; j < data.data_size(); ++j) {
detdata[j] = data.data(j);
sum += detdata[j];
}
}
det->detSum.update(sum);
} catch (InstrumentManager::ControllerNotFound& e) {
log(Level::s_Error) << " missing controller MultiDetector5 in this instrument" << endlog;
commandStatus.setError();
commandProgression = 100;
return;
}
}
}
}
void RemoteLSSSimulation::updateCountDetSum() {
cout << "updateCountDetSum time " << m_CountSpy->time() << endl;
updateDataFromSimulation();
}
}
......@@ -102,6 +102,8 @@ private:
void refreshUseSimulatedDataProperty(bool value) throw(CannotSetValue);
void updateCountStatusMessage();
void updateDataFromSimulation();
void updateCountDetSum();
static const std::string MATLAB_APPLICATION;
static const std::string RESPONDER_NAME;
......
......@@ -551,6 +551,7 @@ std::string VEXPController::getSpyData() {
writer.Key("dTypeScan"); writer.String(scanController->deltaType.get(0).c_str());
writer.Key("runningScan"); writer.Bool(runningScan());
writer.Key("nameScan"); writer.Int(scanController->numor());
writer.Key("startingTime"); writer.String(scanController->startingTime().c_str());
writer.EndObject();
......
This diff is collapsed.
#pragma once
#include <thread>
#include <vector>
#include <mutex>
#include <list>
#define _GNULINUX
#include </usr/local/src/baumer/inc/bgapi2_genicam/bgapi2_genicam.hpp>
#include "drivers/gigecam/photonics/DoubleBufferHandler.h"
// the class represents a BGAPI camera object and additional camera specific information
class CCameraControl {
public:
// this function activates the feature command
// the feature command use the ExposureTime feature of the camera
// the parameter passes the new exposure time to be written to the camera
void StartFeatureCommandExposure(double exposure_time);
// this function activates the capture command
// the parameter passes the number of images to be captured
void StartCaptureCommand(unsigned int images);
// this function checks, if the capture command was activated
// in this case the capture command is automatically reset
bool IsCommandCaptureActivated();
// this function checks, if the feature command was activated
// in this case the feature command is automatically reset
bool IsCommandExposureActivated();
// this function writes the desired exposure time to the passed camera
bool ExposureFeatureBGAPI();
// this function makes all necessary preparations on the buffer management to be able to capture images with BGAPI
// it opens the data stream and creates the camera buffers
void InitializeBGAPIBufferManagement();
// this function clears the buffer management and
// deletes the camera buffers
void DeinitializeBGAPIBufferManagement();
// this function capture the desired number of images from the passed camera
// and store some additional information (BufferInformation struct)
bool CaptureBGAPIImages(const bool * abort_flag, unsigned int number_of_images);
// this function starts the streaming for the passed camera
bool StartStreamingBGAPI();
// this function stops the streaming for the passed camera
void StopStreamingBGAPI();
// this function fill the BufferInformation struct
void FillBufferInformation( BGAPI2::DataStream* datastream_pointer, BGAPI2::Buffer *buffer);
// function to add a string with logging information to the logging string list
void LoggingStringAdd(std::string logging_message);
// this function returns a logging string and remove this string from the logging string list
std::string LoggingString();
// function to check, if some logging information is available
bool LoggingListEmpty() { return (logging_list_.size() == 0); }
public:
// buffer exchange strategy (double buffer)
CDoubleBufferHandler buffer_handler_;
// BGAPI camera object
BGAPI2::Device* camera_pointer_;
// a list to transfer massages, generated by the feature command
std::list<std::string> feature_command_message_list_;
// a mutex to synchronize the access to feature_command_message_list_
std::mutex feature_command_message_list_lock_;
// a worker thread that captures images from BGAPI
std::thread capture_thread_;
// a worker thread that control camera features from BGAPI
std::thread feature_thread_;
// a flag which controls the capture command
bool command_capture_;
// a flag which shows if the capture command is active
bool capture_active_;
// number of images to capture
unsigned int number_of_images_;
// number of currently captured images
unsigned int number_of_captured_images_;
// number of incomplete images
unsigned int number_of_incomplete_images_;
// a flag which controls the feature command
bool command_feature_;
// exposure time to be set
double exposure_time_;
private:
// mutex to synchronize the access to capture command flag of all cameras
std::mutex capture_command_lock_;
// mutex to synchronize the access to feature command flag of all cameras
std::mutex feature_command_lock_;
// a list which holds logging strings
std::list<std::string> logging_list_;
// a mutex to synchronize the access to the logging list
std::mutex logging_list_lock_;
};
// the class encapsulate camera search, capture command and feature command
// it also implements the worker threads
class CCameraHandler
{
// ----
// public functions which are used in the context of the main thread and application threads
// to control the main settings from the user application
// ----
public:
// construction / destruction
CCameraHandler();
virtual ~CCameraHandler();
// this function starts the init thread to search for connected cameras
// it also passed the buffer handler
void Start(CDoubleBufferHandler buffer_handler);
// close all connected cameras and frees all BGAPI resources
// this function doesn't run in a separate thread
void Stop();
// this function initialize the buffer management of all connected cameras
// it also creates the struct BufferInformation for every camera buffer
// all cameras use 10 buffers to store the image data
// the memory for the camera buffers will be allocated inside BGAPI
// the size of the memory to allocated will determined from the maximum image size
// this function also starts the worker threads
void StartCameras();
// this function stops the worker threads
// and deinitialize the BGAPI
void StopCameras();
// function to check for an initialisation error
bool IsInitOK();
// returns the number of connected cameras
size_t NumberOfCameras();
// this function returns the number of images taken by the camera that took the least number of images
unsigned int CapturedImages();
// function to return the camera control vector
const std::vector<CCameraControl*>* GetCameraControlVector() { return &camera_control_; }
// this function returns a logging string and remove this string from the logging string list
std::string LoggingString();
// function to check, if some logging information is available
bool LoggingListEmpty() { return (logging_list_.size() == 0); }
// ----
// public functions which are partly used in the worker threads
// to handle and process the code regarding to main settings
// ----
public:
// this function initializes the Baumer GAPI SDK and
// searches for connected cameras
// all found cameras will be opened to work with
void InitializeBGAPI();
// this function deinitialises the Baumer GAPI SDK and
// close all connected cameras
void DeinitializeBGAPI();
// function to signal an initialisation error while start up
void SetInitError();
// function to add a string with logging information to the logging string list
void LoggingStringAdd(std::string logging_message);
// this function adds a camera object to the camera control vector
void AddCamera(BGAPI2::Device* camera_pointer);
// this function set a flag to signal the worker thread to exit
const bool* FinishWorkerThreads() { return &finish_worker_threads_; }
private:
// pointer to the buffer handler
CDoubleBufferHandler buffer_handler_;
// flag to signal the worker threads to exit themselves
bool finish_worker_threads_;
// initialisation thread
std::thread init_thread;
// camera control vector holds information regarding synchronisation and
// the BGAPI camera object
std::vector<CCameraControl*> camera_control_;
// flag is set for initialisation errors
bool init_ok_;
// a list which holds logging strings
std::list<std::string> logging_list_;
// a mutex to synchronize the access to the logging list
std::mutex logging_list_lock_;
};
This diff is collapsed.
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
#ifndef REALPHOTONICSDRIVER_H
#define REALPHOTONICSDRIVER_H
#include <string>
#include <vector>
#define _GNULINUX
#include "Utilities/Counter.h"
#include </usr/local/src/baumer/inc/bgapi2_genicam/bgapi2_genicam.hpp>
#include "drivers/gigecam/photonics/BufferInformation.h"
#include "drivers/gigecam/photonics/CameraHandler.h"
#include "drivers/gigecam/photonics/DoubleBufferHandler.h"
#include "drivers/gigecam/photonics/PhotonicsDef.h"
#include "drivers/gigecam/photonics/PhotonicsState.h"
namespace photonics {
/*!
* \class RealPhotonicsDriver
* \brief Real implementation class for the Psl device driver
*
* This class is a real implementation of Psl device driver.
*/
class RealPhotonicsDriver: public PhotonicsState{
public:
/*!
* \brief Constructor
* \param[in] owner The device driver main class link
*/
RealPhotonicsDriver(PhotonicsDriver* owner);
/*!
* \brief Destructor
*/
virtual ~RealPhotonicsDriver();
/*!
* \brief Init command implementation
*/
virtual void init();
/*!
* \brief Clear command implementation
*/
virtual void clear();
/*!
* \brief Write Param command implementation
*/
virtual void writeParam();
/*!
* \brief Read command implementation
*/
virtual void read();
/*!
* \brief Synchronize Read command implementation
*/
virtual void synchroniseRead();
/*!
* \brief Start command implementation
*/