...
 
Commits (2)
/*
* 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 LMDOE423DEF_H
#define LMDOE423DEF_H
namespace lmdoe423 {
static const int32 MAX_AMPLITUDE_REGISTER = 20;
static const int32 MIN_AMPLITUDE_REGISTER = 21;
static const int32 WANTED_SPEED_REGISTER = 22;
static const int32 WANTED_ACCEL_REGISTER = 23;
static const int32 WANTED_PLAGE_REGISTER = 24;
//Parameter Commands
static const char SET_DERIVATIVE[] = "SD";
static const char SET_INTEGRALE[] = "SI";
static const char SET_PRPORTIONAL[] = "SG";
static const char SET_TORQUE[] = "SQ";
static const char SET_VELOCITY[] = "SV";
static const char SET_ACCELERATION[] = "SA";
static const char SET_LIMIT_MODE[] = "LM";
static const char SET_LIMIT_ON[] = "LN";
static const char SET_LIMIT_OFF[] = "LF";
static const char SET_DERIVE_FREQ[] = "FR";
static const char SET_INTEG_LIMIT[] = "IL";
static const char SET_INTEG_RATE[] = "RI";
static const char SET_CURRENT_GAIN[] = "SC";
static const char SET_ECHO_OFF[] = "EF";
static const char SET_ECHO_ON[] = "EN";
static const char SET_ACCUMULATOR[] = "AL";
static const char WRITE_ACCUMULATOR[] = "AR";
// Motion Commands
static const char POSITION_MODE[] = "PM";
static const char VELOCITY_MODE[] = "VM";
static const char TORQUE_MODE[] = "QM";
static const char POWER_ON[] = "MN";
static const char POWER_OFF[] = "MF";
static const char MOVE_RELATIVE[] = "MR";
static const char MOVE_ABSOLUTE[] = "MA";
static const char STOP_MOTOR[] = "ST";
static const char DEFINE_HOME[] = "DH";
static const char CAPTURE_INDEX[] = "CI";
static const char DEFINE_DIRECTION[] = "DI";
static const char GO_HOME[] = "GH";
static const char START_MOTION[] = "GO";
static const char FIND_EDGE_HOME[] = "FE";
static const char FIND_EDGE_INDEX[] = "FI";
static const char WAIT_FOR_STOP[] = "WS";
static const char RESET_MACRO[] = "RM";
static const char RESET_CONTROLLER[] = "RT";
static const char RESET_STACK[] = "UM1";
// Reporting Commands
static const char READ_AXIS[] = "TP";
static const char READ_STATUS[] = "TS";
static const char READ_VERSION[] = "VE";
static const char READ_DERIVATIVE[] = "TD";
static const char READ_INTEGRALE[] = "TI";
static const char READ_PRPORTIONAL[] = "TG";
static const char READ_TORQUE[] = "TQ";
static const char READ_VELOCITY[] = "TV";
static const char ACK_TERMINATOR[] = ">";
static const char SEPARATOR[] = ",";
static const char CR_TERMINATOR[] = "\r";
static const char ESC_TERMINATOR = 27;
static const char LF_TERMINATOR[] = "\n";
static const char TERMINATOR[] = "\r\n";
static const uint32 TERMINATOR_SIZE = 3;
static const int32 NB_AXIS_DEFAULT = 1;
static const int32 TIME_MAX = 30;
static const int32 NOT_MOVING_MAX = 2;
// Values for the status bits
static const int32 MOTOR_ON = 0x00000001;
static const int32 MOTOR_ERROR = 0x00000002;
static const int32 OVER_TEMP = 0x00000004;
static const int32 AXIS_READY = 0x00000010;
static const int32 DOWN_DIRECTION = 0x00000040;
static const int32 IS_HOMING = 0x00000400;
static const int32 MECHANICAL_ZERO = 0x00002000;
static const int32 MECHANICAL_ZERO1 = 0x00004000;
static const int32 LOW_HARDSTOP = 0x10000000;
static const int32 HIGH_HARDSTOP = 0x80000000;
static const int32 IN_TOLERANCE = 0x00010000;
static const int32 RUNNING = 0x00020000;
// Values for the timer
static const int32 TIMER_SECONDE = 2;
static const int32 TIMER_USECONDE = 2;
// Values for the offsets for the line
static const int32 INFOS_START = 1;
static const int32 POSITION_START = 1;
static const int32 STATUS = 3;
static const uint32 STATUS_ANSWER = 4;
static const int32 ERROR_CODE_POSITION = 2;
static const int32 ERROR_MESSAGE_POSITION = 3;
/*
* Properties name for simulated mode
*/
static const std::string SPEED_SIMULATED_AXIS = "sim_speed";
static const std::string UPHARDSTOP_SIMULATED_AXIS = "sim_uphardstop";
static const std::string DOWNHARDSTOP_SIMULATED_AXIS = "sim_downhardstop";
//static const std::string EMERGENCYSTOP_SIMULATED_AXIS = "sim_emergencystop";
//static const std::string MANUAL_SIMULATED_AXIS = "sim_manual";
static const std::string BRAKE_SIMULATED_AXIS = "sim_brake";
static const std::string ECHECMODE_SIMULATED_AXIS = "sim_echecmode";
}
#endif //LMDOE423DEF_H
/*
* 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.
*/
#include <drivers/schneider/lmdoe423/Lmdoe423Def.h>
#include <drivers/schneider/lmdoe423/Lmdoe423Driver.h>
#include <drivers/schneider/lmdoe423/Lmdoe423State.h>
#include <drivers/schneider/lmdoe423/PerfectLmdoe423Driver.h>
#include <drivers/schneider/lmdoe423/RealLmdoe423Driver.h>
#include <drivers/schneider/lmdoe423/SimulatedLmdoe423Driver.h>
#include <math.h>
using namespace std;
namespace psl {
const std::string PslDriver::TYPE = "psl";
const std::string PslDriver:: MODE[4] = {"Standard", "Average","Summation","Accumulation"};
/*
* Constructor
*/
PslDriver::PslDriver(const string& name):
acquisition::NoTofAcquisitionCommon(name),acquisition::KineticAcquisitionCommon(name),
acquisition::TimeGateCommon(name),
acquisition::DetectorCommon(name)
{
registerStates(new RealPslDriver(this), new PerfectPslDriver(this), new SimulatedPslDriver(this));
driver::SocketTcp::init(name);
/*
* Init the device command list
*/
address.init(this, SAVE, "address");
height.init(this, SAVE, "height");
width.init(this, SAVE, "width");
acqmode.init(this, SAVE, "acqmode");
gain.init(this, SAVE, "gain");
nbFrame.init(this, SAVE, "nbFrame");
bpixel.init(this, SAVE, "bpixel");
fileSimu.init(this, SAVE, "file_simu");
indexSimu.init(this, SAVE, "index_simu");
fileDirectory.init(this, SAVE, "fileDirectory");
fileName.init(this, SAVE, "fileName");
numor.init(this, SAVE, "numor");
header.init(this, NOSAVE, "header");
initCommand(driver::INIT_COMMAND);
initCommand(driver::READ_COMMAND);
initCommand(driver::SYNCHRONIZE_READ_COMMAND);
initCommand(driver::START_COMMAND);
initCommand(driver::RESUME_COMMAND);
initCommand(driver::PAUSE_COMMAND);
initCommand(driver::STOP_COMMAND);
initCommand(driver::STATUS_COMMAND);
initCommand(driver::READ_INFOS_COMMAND);
initCommand(DetectorCommon::CLEAR_COMMAND);
initCommand(DetectorCommon::REGROUP_COMMAND);
initCommand(AcquisitionCommon::WRITE_PARAMETERS_COMMAND);
initCommand(driver::INIT_COMMAND);
// Init functions
registerFunction(NONE_FUNCTION);
deviceType = LEAF_DEVICE_TYPE_DEVICE_CONTAINER;
m_DoSynchroniseRead = false;
m_SynchroniseReadActivated = false;
m_SynchroniseReadTerminated = false;
m_DataShort = NULL;
registerObserverCommand(COMMAND_STATUS_DEVICE_CONTAINER, 50);
registerObserverCommand(COMMAND_READ_DEVICE_CONTAINER, 50);
}
/*
* Destructor
*/
PslDriver::~PslDriver() {
}
/*
* refreshDataSizeProperty
*/
void PslDriver::refreshDataSizeProperty(int32 value) throw (CannotSetValue) {
if (m_DataShort != NULL) {
delete[] m_DataShort;
}
m_DataShort = new uint16[value];
if (m_DataShort == NULL) {
sendErrorEvent(NOTENOUGH_MEMORY_ERROR, "Can't create data table");
throw CannotSetValue();
}
DetectorCommon::refreshDataSizeProperty(value);
}
/*
* refreshModeProperty
*/
void PslDriver::refreshModeProperty(int32 value) throw (CannotSetValue) {
if (value != acquisition::GateCommon::TIME_MODE) {
throw CannotSetValue();
}
}
/*
* execute
*/
void PslDriver::execute(const std::string& aCommand) {
if ((aCommand != driver::PAUSE_COMMAND) && (aCommand != driver::STOP_COMMAND) && (aCommand != driver::STATUS_COMMAND)
&& (aCommand != driver::READ_COMMAND)) {
commandProgression = PROGRESSION_UNKNOWNSTATE_DEVICE_CONTAINER;
}
PslState* currentState = dynamic_cast<PslState*>(getCurrentState());
// Check command
if (aCommand == driver::INIT_COMMAND) {
// Init command
currentState->init();
} else if (aCommand == driver::READ_COMMAND) {
// Read command
currentState->read();
} else if (aCommand == driver::SYNCHRONIZE_READ_COMMAND) {
// Read command
if (m_DoSynchroniseRead == true) {
m_SynchroniseReadActivated = true;
m_SynchroniseReadTerminated = false;
currentState->synchroniseRead();
m_DoSynchroniseRead = false;
}
else {
m_SynchroniseReadActivated = false;
m_SynchroniseReadTerminated = false;
}
} else if (aCommand == driver::START_COMMAND) {
// Start command
startActivated = true;
m_DoSynchroniseRead = true;
currentState->start();
} else if (aCommand == driver::RESUME_COMMAND) {
// Continue command
currentState->resume();
} else if (aCommand == driver::PAUSE_COMMAND) {
// Stop command
currentState->pause();
} else if (aCommand == driver::STOP_COMMAND) {
// Stop command
currentState->stop();
startActivated = false;
} else if (aCommand == driver::STATUS_COMMAND) {
// Status command
currentState->readStatus();
} else if (aCommand == driver::READ_INFOS_COMMAND) {
// Info command
currentState->readInfos();
} else if (aCommand == DetectorCommon::CLEAR_COMMAND) {
// Move command
sum = 0;
currentState->clear();
} else if (aCommand == AcquisitionCommon::WRITE_PARAMETERS_COMMAND) {
// Write command
currentState->writeParam();
} else {
//Error bad command
//Todo , normaly it will be detect it device action driver
}
}
/*
* calculateProgression
*/
void PslDriver::calculateProgression() {
int32 progression = 0;
float64 setpoint = 0.0;
float64 actual = 0.0;
setpoint = time.setpoint();
actual = time();
if (setpoint == 0.0) {
commandProgression = PROGRESSION_END_DEVICE_CONTAINER;
} else {
progression = (int32) (actual / setpoint * PROGRESSION_RATIO_DEVICE_CONTAINER);
// Be sure that progression > 0%
if (progression < PROGRESSION_UNKNOWNSTATE_DEVICE_CONTAINER)
progression = 0;
// Be sure that only Phased status put 100%
if (progression >= PROGRESSION_END_DEVICE_CONTAINER)
progression = PROGRESSION_END_DEVICE_CONTAINER - 1;
commandProgression = progression;
}
}
/*
* PslDriver
*/
void PslDriver::computeGateStatus(int32 value) {
int32 valueout = 0;
if (value == COUNTING) {
valueout |= GateCommon::RUNNING_STATUS;
} else if (value == END) {
valueout |= GateCommon::END_STATUS;
}
status.update(value);
gateStatus.update(valueout);
}
/*
* PslDriver
*/
void PslDriver::computeDetectorStatus(int32 value) {
int32 valueout = 0;
detectorStatus.update(valueout);
}
/*
* PslDriver
*/
void PslDriver::computeAcquisitionStatus(int32 value) {
int32 valueout = 0;
acquisitionStatus.update(valueout);
}
}
/*
* 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 PSLDRIVER_H
#define PSLDRIVER_H
#include <Driver.h>
#include "controllers/common/acquisition/gate/TimeGateCommon.h"
#include "controllers/common/acquisition/mode/NoTofAcquisitionCommon.h"
#include "controllers/common/acquisition/mode/TofAcquisitionCommon.h"
#include "controllers/common/acquisition/mode/KineticAcquisitionCommon.h"
#include "controllers/common/acquisition/detector/DetectorCommon.h"
#include "drivers/global/sockettcp/SocketTcp.h"
#include "drivers/legacy/def/DriverErrorDef.h"
namespace psl {
/**
* Global Implementation of the vme card called Psl made in Ill. It needs a board called Men A201.
*/
class PslDriver: public acquisition::NoTofAcquisitionCommon,
public acquisition::TimeGateCommon,
public acquisition::KineticAcquisitionCommon,
public acquisition::DetectorCommon,
public driver::SocketTcp
{
friend class RealPslDriver;
friend class PerfectPslDriver;
friend class SimulatedPslDriver;
public:
static const string MODE[4];
//! Driver type value
static const std::string TYPE;
static const std::string ON_COMMAND ;
static const std::string OFF_COMMAND;
/*!
* \brief Constructor
* \param[in] name the name of the device driver
*/
PslDriver(const std::string& name);
/*!
* \brief Destructor
*/
virtual ~PslDriver();
/*!
* \brief Method called for executing a command
*
* \param[in] command the command to apply on the controller
*/
virtual void execute(const std::string& aCommand);
/*!
* \brief Calculate the progression state.
*/
void calculateProgression();
Property<int32> address;
Property<int32> port;
Property<int32> height;
Property<int32> width;
Property<int32> acqmode;
Property<int32> nbFrame;
Property<bool> bpixel;
Property<int32> gain;
Property<std::string> fileSimu;
Property<int32> indexSimu;
Property<string> fileDirectory;
Property<string> fileName;
Property<int32> numor;
Property<std::string> header;
private:
/*!
* \brief Method called before changing the data size property value
* \param[in] value the property value
* \throws CannotSetValue the value isn't corrected, or property couldn't be changed
*/
virtual void refreshDataSizeProperty(int32 value) throw (CannotSetValue);
virtual void refreshModeProperty(int32 value) throw (CannotSetValue);
/*!
* \brief compute global gate status
* \param[in] value the driver status
*/
virtual void computeGateStatus(int32 value);
/*!
* \brief compute global acquisition status
* \param[in] value the driver status
*/
virtual void computeAcquisitionStatus(int32 value);
/*!
* \brief compute global detector status
* \param[in] value the driver status
*/
virtual void computeDetectorStatus(int32 value);
uint16* m_DataShort;
/**
* flag for synchronise read
*/
bool m_DoSynchroniseRead;
bool m_SynchroniseReadActivated;
bool m_SynchroniseReadTerminated;
};
}
#endif //PSLDRIVER_H
/*
* 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 PSLSTATE_H
#define PSLSTATE_H
#include <drivers/schneider/lmdoe423/Lmdoe423Driver.h>
#include <Driver.h>
namespace psl {
/*!
* \class PslState
* \brief Virtual class for implement State pattern
*
* Define all methods that perfect, simulated and real classes have to implement
*/
class PslState: public DriverState<PslDriver> {
public:
/*!
* \brief Constructor
* \param[in] owner The device driver main class link
*/
PslState(PslDriver* owner) :
DriverState<PslDriver>(owner) {
}
/*!
* \brief Destructor
*/
virtual ~PslState() {
}
/*!
* \brief Clear command implementation
*/
virtual void clear() = 0;
/*!
* \brief Write Param command implementation
*/
virtual void writeParam() = 0;
/*!
* \brief Read command implementation
*/
virtual void read() = 0;
/*!
* \brief Synchronize Read command implementation
*/
virtual void synchroniseRead() = 0;
/*!
* \brief Start command implementation
*/
virtual void start() = 0;
/*!
* \brief Resume command implementation
*/
virtual void resume() = 0;
/*!
* \brief Pause command implementation
*/
virtual void pause() = 0;
/*!
* \brief Stop command implementation
*/
virtual void stop() = 0;
/*!
* \brief Read Infos command implementation
*/
virtual void readStatus() = 0;
/*!
* \brief Read Infos command implementation
*/
virtual void readInfos() = 0;
};
}
#endif //PSLSTATE_H
<module name="lmdoe423">
<driver class="lmdoe423::Lmdoe423Driver"/>
</module>
/*
* 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.
*/
#include <drivers/schneider/lmdoe423/Lmdoe423Def.h>
#include <drivers/schneider/lmdoe423/Lmdoe423Driver.h>
#include <drivers/schneider/lmdoe423/PerfectLmdoe423Driver.h>
#include <stdlib.h>
namespace psl {
/*
* Constructor
*/
PerfectPslDriver::PerfectPslDriver(PslDriver* owner) :
PslState(owner) {
/* Empty */
}
/*
* Destructor
*/
PerfectPslDriver::~PerfectPslDriver() {
/* Empty */
}
void PerfectPslDriver::init() {
}
/*
* clearvme/daugther/Psl
*/
void PerfectPslDriver::clear() {
// Read command
owner()->time = 0;
owner()->counts = 0;
owner()->counts2 = 0;
owner()->counts3 = 0;
}
/*
* writeParam
*/
void PerfectPslDriver::writeParam() {
}
/*
* synchroniseRead
*/
void PerfectPslDriver::synchroniseRead() {
read();
owner()->m_SynchroniseReadTerminated = true;
}
/*
* read
*/
void PerfectPslDriver::read() {
// Read command
int32 size = owner()->dataSize();
int32 *tab = owner()->data();
int32 sum = 0;
// if (m_FirstRead) {
// for (uint32 i=0;i<size;i++) {
// tab[i] = i + 1;
// sum = sum + tab[i];
// }
// m_FirstRead = false;
// } else {
// for (uint32 i=0;i<size;i++) {
// tab[i] = tab[i] + 1;
// sum = sum + tab[i];
// }
// }
for (int32 i = 0; i < size; i++) {
tab[i] = i;
sum = sum + tab[i];
}
owner()->sum = sum;
owner()->data.sendEvent();
}
/*
* pause
*/
void PerfectPslDriver::pause() {
}
/*
* continue
*/
void PerfectPslDriver::resume() {
}
/*
* start
*/
void PerfectPslDriver::start() {
owner()->time = owner()->time.setpoint();
}
/*
* stop
*/
void PerfectPslDriver::stop() {
}
/*
* readStatus
*/
void PerfectPslDriver::readStatus() {
owner()->startActivated = false;
// Status command
owner()->computeGateStatus(psl::READOUT_COMPLETE);
owner()->computeAcquisitionStatus(0);
owner()->computeDetectorStatus(0);
if (owner()->m_SynchroniseReadActivated == true) {
if (owner()->m_SynchroniseReadTerminated == true) {
owner()->m_SynchroniseReadActivated = false;
owner()->m_SynchroniseReadTerminated = false;
owner()->commandProgression = PROGRESSION_END_DEVICE_CONTAINER;
}
} else {
owner()->commandProgression = PROGRESSION_END_DEVICE_CONTAINER;
}
}
/*
* readInfos
*/
void PerfectPslDriver::readInfos() {
}
}
/*
* 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 PERFECTPSLDRIVER_H
#define PERFECTPSLDRIVER_H
#include <drivers/schneider/lmdoe423/Lmdoe423State.h>
namespace psl {
/*!
* \class PerfectPslDriver
* \brief Perfect implementation class for the Psl device driver
*
* This class is a perfect implementation of Psl device driver.
* On start command, all actual values become target's ones.
*/
class PerfectPslDriver: public PslState {
public:
/*!
* \brief Constructor
* \param[in] owner The device driver main class link
*/
PerfectPslDriver(PslDriver* owner);
/*!
* \brief Destructor
*/
virtual ~PerfectPslDriver();
/*!
* \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
*/
virtual void start();
/*!
* \brief Resume command implementation
*/
virtual void resume();
/*!
* \brief Pause command implementation
*/
virtual void pause();
/*!
* \brief Stop command implementation
*/
virtual void stop();
/*!
* \brief Read Infos command implementation
*/
virtual void readStatus();
/*!
* \brief Read Infos command implementation
*/
virtual void readInfos();
};
}
#endif //PERFECTPSLDRIVER_H
/*
* 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.
*/
#include <boost/format.hpp>
#include <drivers/schneider/lmdoe423/Lmdoe423Def.h>
#include <drivers/schneider/lmdoe423/Lmdoe423Driver.h>
#include <drivers/schneider/lmdoe423/RealLmdoe423Driver.h>
#include "Utilities/Counter.h"
#include <cstdio>
namespace psl {
/*
* Constructor
*/
RealPslDriver::RealPslDriver(PslDriver* owner) :
PslState(owner) {
/* Empty */
}
/*
* Destructor
*/
RealPslDriver::~RealPslDriver() {
}
/*
* init
*/
void RealPslDriver::init() {
readInfos();
}
/*
* clear
*/
void RealPslDriver::clear() {
}
/*
* writeParam
*/
void RealPslDriver::writeParam() {
}
/*
* synchroniseRead
*/
void RealPslDriver::synchroniseRead() {
string err;
int32 i;
cout << "m_TimeCounter" <<m_TimeCounter.getTime()<< endl;
do {
err = writeAndRead("WaitForImage", TERMINATOR);
cout << "Waiting For Image" << endl;
} while ((err == "False") && (i++ <10 ));
// if (err != "True") {
// cerr << "error acquisition " << endl;
// } else {
// stop();
string buf;
owner()->connect();
Counter c1;
cout << "<-- GetImage" << endl;
owner()->write("GetImage", TERMINATOR);
buf = owner()->read(16);
// owner()->disconnect();
cout << "--> buf " << buf << endl;
typedef tokenizer<char_separator<char> > tokenizer;
char_separator<char> sep(";");
tokenizer tok1(buf, sep);
tokenizer::iterator iter = tok1.begin();
if (iter != tok1.end()) {
cout << " iter 1 : " << *iter << endl;
++iter;
if (iter != tok1.end()) {
cout << " iter 2 : " << *iter << endl;
int32 xsize = lexical_cast<int32>(*iter);
++iter;
if (iter != tok1.end()) {
cout << " iter 3 : " << *iter << endl;
int32 ysize = lexical_cast<int32>(*iter);;
++iter;
if (iter != tok1.end()) {
cout << " iter 4 : " << *iter << endl;
int32 size = xsize * ysize;//lexical_cast<int32>(*iter);
//sleep(5);
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)) {
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];
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;
}
}
}
}
}
owner()->disconnect();
cout << "read time:" << c1.getTime() << endl;
cout << "owner()->m_SynchroniseReadTerminated = true" << endl;
owner()->m_SynchroniseReadTerminated = true;
}
/*
* read
*/
void RealPslDriver::read() {
}
/*
* start
*/
void RealPslDriver::start() {
ostringstream buf_conf;
float64 exp_time = owner()->time.setpoint();
string err;
buf_conf << "SetRecordPath;"<< "z:"<<owner()->fileDirectory();
err = writeAndRead(buf_conf.str(), TERMINATOR);
buf_conf.str("");
buf_conf.clear();
if (err != "True") {
cerr << "error SetRecordPath; " << endl;
}
buf_conf << "SetRecordName;"<< owner()->fileName();
err = writeAndRead(buf_conf.str(), TERMINATOR);
buf_conf.str("");
buf_conf.clear();
if (err != "True") {
cerr << "error SetRecordName; " << endl;
}
buf_conf << "SetRecordNumber;"<< owner()->numor();
err = writeAndRead(buf_conf.str(), TERMINATOR);
buf_conf.str("");
buf_conf.clear();
if (err != "True") {
cerr << "error SetRecordNumber;; " << endl;
}
buf_conf << "SetRecordTag;"<< owner()->header();
err = writeAndRead(buf_conf.str(), TERMINATOR);
buf_conf.str("");
buf_conf.clear();
if (err != "True") {
cerr << "error SetRecordTag; " << endl;
}
cout << "start" << endl;
cout << "exp_time:" << exp_time << endl;
buf_conf << "SetExposure;[" << exp_time << ",\"Second\"]";
err = writeAndRead(buf_conf.str(), TERMINATOR);
err = writeAndRead("Snap", TERMINATOR);
if (err != "True") {
cerr << "error acquisition " << endl;
owner()->startActivated = false;
owner()->commandProgression = PROGRESSION_END_DEVICE_CONTAINER;
}
m_TimeCounter.clear();
}
/*
* resume
*/
void RealPslDriver::resume() {
}
/*
* pause
*/
void RealPslDriver::pause() {
}
/*
* stop
*/
void RealPslDriver::stop() {
ostringstream buf_cmd2;
writeAndRead("Stop", TERMINATOR);
owner()->startActivated = false;
owner()->commandProgression = PROGRESSION_END_DEVICE_CONTAINER;
}
/*
* readStatus
*/
void RealPslDriver::readStatus() {
float64 actualtime = m_TimeCounter.getTime();
owner()->time = actualtime;
int32 status = 0;
if (owner()->startActivated() == true) {
if (actualtime > owner()->time.setpoint()) {
status |= END;
owner()->startActivated = false;
owner()->commandProgression = PROGRESSION_END_DEVICE_CONTAINER;
} else {
status |= COUNTING;
owner()->calculateProgression();
}
} else {
if (owner()->m_SynchroniseReadActivated == true) {
if (owner()->m_SynchroniseReadTerminated == true) {
owner()->m_SynchroniseReadActivated = false;
owner()->m_SynchroniseReadTerminated = false;
owner()->commandProgression = PROGRESSION_END_DEVICE_CONTAINER;
}
} else {
owner()->commandProgression = PROGRESSION_END_DEVICE_CONTAINER;
}
}
owner()->computeGateStatus(status);
owner()->computeAcquisitionStatus(0);
owner()->computeDetectorStatus(0);
}
/*
* readInfos
*/
void RealPslDriver::readInfos() {
string info = writeAndRead("GetVersion", TERMINATOR);
owner()->version = info;
}
/*
* writeAndRead
*/
std::string RealPslDriver::writeAndRead(const std::string& command,
const std::string& terminator) {
string buf;
owner()->connect();
cout << "<-- " << command << endl;
owner()->write(command, terminator);
cout << "<-- OK " << command << endl;
buf = owner()->read();
cout << "--> " << buf << endl;
owner()->disconnect();
return buf;
}
}
/*
* 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 REALPSLDRIVER_H
#define REALPSLDRIVER_H
#include <drivers/schneider/lmdoe423/Lmdoe423Def.h>
#include <drivers/schneider/lmdoe423/Lmdoe423State.h>
#include "Utilities/Counter.h"
namespace psl {
class PslDriver;
/*!
* \class RealPslDriver
* \brief Real implementation class for the Psl device driver
*
* This class is a real implementation of Psl device driver.
*/
class RealPslDriver: public PslState {
public:
/*!
* \brief Constructor
* \param[in] owner The device driver main class link
*/
RealPslDriver(PslDriver* owner);
/*!
* \brief Destructor
*/
virtual ~RealPslDriver();
/*!
* \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
*/
virtual void start();
/*!
* \brief Resume command implementation
*/
virtual void resume();
/*!
* \brief Pause command implementation
*/
virtual void pause();
/*!
* \brief Stop command implementation
*/
virtual void stop();
/*!
* \brief Read Infos command implementation
*/
virtual void readStatus();
/*!
* \brief Read Infos command implementation
*/
virtual void readInfos();
int32 GetAvailableCameras();
private:
std::string writeAndRead(const std::string& command, const std::string& terminator);
int16 m_Handle;
int16 lNumCameras;
Counter m_TimeCounter;
};
}
#endif //REALPSLDRIVER_H
/*
* 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.
*/
#include <drivers/schneider/lmdoe423/Lmdoe423Def.h>
#include <drivers/schneider/lmdoe423/Lmdoe423Driver.h>
#include <drivers/schneider/lmdoe423/SimulatedLmdoe423Driver.h>
#include <stdlib.h>
#include "tiffio.h"
namespace psl {
/*
* Constructor
*/
SimulatedPslDriver::SimulatedPslDriver(PslDriver* owner) :
PslState(owner) {
/* Empty */
}
/*
* Destructor
*/
SimulatedPslDriver::~SimulatedPslDriver() {
/* Empty */
}
void SimulatedPslDriver::init() {
}
/*
* clearvme/daugther/Psl
*/
void SimulatedPslDriver::clear() {
// Read command
owner()->time = 0;
owner()->counts = 0;
owner()->counts2 = 0;
owner()->counts3 = 0;
}
/*
* writeParam
*/
void SimulatedPslDriver::writeParam() {
}
/*
* synchroniseRead
*/
void SimulatedPslDriver::synchroniseRead() {
read();
owner()->m_SynchroniseReadTerminated = true;
}
/*
* read
*/
void SimulatedPslDriver::read() {
int32 size = owner()->dataSize();
int32 *tab = owner()->data();
float64 sum = 0;
boost::filesystem::path file = owner()->fileSimu();
TIFF* tif = TIFFOpen(file.string().c_str(), "r");
if (tif) {
int32 dircount = 0;
while (dircount < owner()->indexSimu()) {
if (TIFFReadDirectory(tif) <= 0) break;
++dircount;
};
uint32 w, h;
int32 npixels;
tdata_t buf;
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w);
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h);
npixels = w * h;
if (npixels == size) {
tmsize_t scanlinesize = TIFFScanlineSize(tif);
buf = _TIFFmalloc(scanlinesize);
if (buf != NULL) {
uint16* data;
for (uint32 row = 0; row < h; row++) {
TIFFReadScanline(tif, buf, row, 0);
data = (uint16*) buf;
for(uint32 i = 0; i < w;++i) {
tab[row + i * h] = data[i];
sum = sum + data[i];
}
}
owner()->sum = sum;
owner()->data.sendEvent();
_TIFFfree(buf);
}
}
TIFFClose(tif);
}
// Read command
// for (int32 i = 0; i < size; i++) {
// tab[i] = i;
// sum = sum + tab[i];
// }
}
/*
* pause
*/
void SimulatedPslDriver::pause() {
}
/*
* continue
*/
void SimulatedPslDriver::resume() {
}
/*
* start
*/
void SimulatedPslDriver::start() {
owner()->time = owner()->time.setpoint();
}
/*
* stop
*/
void SimulatedPslDriver::stop() {
}
/*
* readStatus
*/
void SimulatedPslDriver::readStatus() {
owner()->startActivated = false;
// Status command
owner()->computeGateStatus(psl::READOUT_COMPLETE);
owner()->computeAcquisitionStatus(0);
owner()->computeDetectorStatus(0);
if (owner()->m_SynchroniseReadActivated == true) {
if (owner()->m_SynchroniseReadTerminated == true) {
owner()->m_SynchroniseReadActivated = false;
owner()->m_SynchroniseReadTerminated = false;
owner()->commandProgression = PROGRESSION_END_DEVICE_CONTAINER;
}
} else {
owner()->commandProgression = PROGRESSION_END_DEVICE_CONTAINER;
}
}
/*
* readInfos
*/
void SimulatedPslDriver::readInfos() {
}
}
/*
* 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 SIMULATEDPSLDRIVER_H
#define SIMULATEDPSLDRIVER_H
#include <drivers/schneider/lmdoe423/Lmdoe423State.h>
namespace psl {
/*!
* \class SimulatedPslDriver
* \brief Simulated implementation class for the Psl device driver
*
* This class is a perfect implementation of Psl device driver.
* On start command, all actual values become target's ones.
*/
class SimulatedPslDriver: public PslState {
public:
/*!
* \brief Constructor
* \param[in] owner The device driver main class link
*/
SimulatedPslDriver(PslDriver* owner);
/*!
* \brief Destructor
*/
virtual ~SimulatedPslDriver();
/*!
* \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
*/
virtual void start();
/*!
* \brief Resume command implementation
*/
virtual void resume();
/*!
* \brief Pause command implementation
*/
virtual void pause();
/*!
* \brief Stop command implementation
*/
virtual void stop();
/*!
* \brief Read Infos command implementation
*/
virtual void readStatus();
/*!
* \brief Read Infos command implementation
*/
virtual void readInfos();
};
}
#endif //SIMULATEDPSLDRIVER_H
psl.setup=Setup
psl.actual=Actual
psl.divisors=Divisors
psl.wanted_time=Time
psl.actual_time=Time
psl.mode=Master
psl.modeTimeCheckedValue=1
psl.modeTimeUncheckedValue=0
psl.bindPrefix=Binning
psl.nbFramePrefix=NB Frame
psl.bPixelPrefix=BitPixel
# Mode combo
psl.2048Label=2048*2048
psl.2048Value=1
psl.1024Label=1024*1024
psl.1024Value=2
psl.512Label=512*512
psl.512Value=4
psl.hsspeedPrefix=HSSpeed
# Mode combo
psl.5mLabel=5MHz
psl.5mValue=0
psl.3mLabel=3MHz
psl.3mValue=1
psl.1mLabel=1MHz
psl.1mValue=2
psl.005mLabel=0.05MHz
psl.005mValue=3
psl.gainPrefix=Pre-Amp Gain
# Mode combo
psl.x1Label=X1
psl.x1Value=0
psl.x2Label=X2
psl.x2Value=1
psl.x4Label=X4
psl.x4Value=2
#Labels Commands
psl.on=ON
psl.off=OFF
psl.cooler=Cooler
psl.readoutPrefix=Read Out
# Mode combo
psl.fvbLabel=FVB
psl.fvbValue=0
psl.mtrackLabel=MTrack
psl.mtrackValue=1
psl.rtrackLabel=RTrack
psl.rtrackValue=2
psl.strackLabel=STrack
psl.strackValue=3
psl.imageLabel=Image
psl.imageValue=4
psl.shutter=Shutter
psl.shutmode=Mode
psl.shutopentime=Open Time
psl.shutclosetime=Close Time
# Mode combo
psl.FALabel=Auto
psl.FAValue=0
psl.POLabel=Open
psl.POValue=1
psl.PCLabel=Close
psl.PCValue=2
psl.bclamp=Baseline Clamp
# Mode combo
psl.enableLabel=Enable
psl.enableValue=1
psl.disableLabel=Disable
psl.disableValue=0
psl.wanted_temperature=Wanted Temp
psl.actual_temperature=Actual Temp
psl.modeMonitor1CheckedValue=2
psl.modeMonitor1UncheckedValue=0
psl.writeParamButton=Write Param.
psl.initButton=Init Camera.
psl.wanted_monitor2=Monitor2
psl.actual_monitor2=Monitor2
psl.modeMonitor2CheckedValue=4
psl.modeMonitor2UncheckedValue=0
psl.wanted_detector=Detector
psl.actual_detector=Detector
psl.modeDetectorCheckedValue=8
psl.modeDetectorUncheckedValue=0
psl.inhibit_time=Inhibit
#status
psl.status=Status
startstop.extinhibitValue=4
startstop.nomasterValue=8
startstop.waitforstartValue=16
startstop.runningValue=32
startstop.endValue=64
startstop.pauseValue=128
startstop.extinhibitLabel=External Inhibit