Commit 540143ec authored by Franck Cecillon's avatar Franck Cecillon

new pump drivers

parent ff47d52e
/*
* 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 MKS946PUMPDEF_H
#define MKS946PUMPDEF_H
namespace mks946 {
/*
* Commands
*/
static const char REMOTE_COMMAND[] = "CONTROL REMOTE";
static const char LOCAL_COMMAND[] = "CONTROL STANDALONE";
static const char START_COMMAND[] = "ST ";
static const char STOP_COMMAND[] = "SP";
static const char ADD_PREFIX[] = "@253";
static const char SETFLOWRATE_COMMAND[] = "QSP";
static const char CHECKFLOWRATE_COMMAND[] = "FR";
static const char SETMODECHANNEL_COMMAND[] = "QMD";
static const char OPENCHANNEL_COMMAND[] = "QMD";
static const char CMD_STATUS_OPEN[] = "Open";
static const char CMD_STATUS_CLOSE[] = "Close";
static const char TERM_COMMAND[] = ";FF";
static const char TERMINATOR[] = "\r";
}
#endif //MKS946PUMPDEF_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/mks/mks946/Mks946PumpDriver.h>
#include <drivers/mks/mks946/PerfectMks946PumpDriver.h>
#include <drivers/mks/mks946/RealMks946PumpDriver.h>
#include "drivers/global/DriversCommands.h"
using namespace std;
namespace mks946 {
const string Mks946PumpDriver::TYPE = "Mks946Pump";
/*
* Constructor
*/
Mks946PumpDriver::Mks946PumpDriver(const std::string& name) : pump::PumpCommon(name) {
driver::RS232::init(name);
m_startActivated = false;
registerStates(new RealMks946PumpDriver(this), new PerfectMks946PumpDriver(this), new PerfectMks946PumpDriver(this));
// Init command list
initCommand(COMMAND_INIT_DEVICE_CONTAINER);
initCommand(COMMAND_START_DEVICE_CONTAINER);
initCommand(COMMAND_STOP_DEVICE_CONTAINER);
initCommand(COMMAND_STATUS_DEVICE_CONTAINER);
// Init functions
registerFunction(NONE_FUNCTION);
// Set the type of device
deviceType = LEAF_DEVICE_TYPE_DEVICE_CONTAINER;
/*
* Register the Spy and Observer commands necessary to do the updates.
*/
registerObserverCommand(COMMAND_STATUS_DEVICE_CONTAINER, 5);
}
/*
* Destructor
*/
Mks946PumpDriver::~Mks946PumpDriver() {
}
/*
* execute
*/
void Mks946PumpDriver::execute(const std::string& aCommand) {
if ((aCommand != driver::STOP_COMMAND) && (aCommand != driver::STATUS_COMMAND) && (aCommand != driver::READ_COMMAND)) {
commandProgression = PROGRESSION_UNKNOWNSTATE_DEVICE_CONTAINER;
}
Mks946PumpState * currentState = static_cast<Mks946PumpState *>(getCurrentState());
// Check command
if (aCommand == driver::START_COMMAND) {
m_startActivated = true;
currentState->start();
} else if (aCommand == driver::INIT_COMMAND) {
currentState->init();
} else if (aCommand == driver::STOP_COMMAND) {
currentState->stop();
m_startActivated = false;
} else if (aCommand == driver::STATUS_COMMAND) {
currentState->readStatus();
} else {
//Error bad command
//Todo , normaly it will be detect it device action driver
}
}
}
/*
* 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 MKS946PUMPDRIVER_H
#define MKS946PUMPDRIVER_H
#include <Driver.h>
#include "drivers/global/RS232.h"
#include "controllers/common/pump/PumpCommon.h"
namespace mks946 {
/**
* Global implementation of Mks946PumpDriver.
*/
class Mks946PumpDriver : public driver::RS232, public pump::PumpCommon {
friend class RealMks946PumpDriver;
friend class PerfectMks946PumpDriver;
public:
static const std::string TYPE;
/**
* Constructor.
* @param the type of device driver
* @param the name of device driver
* @param the category list of device
* @param the running mode of ICS software
*/
Mks946PumpDriver(const std::string& name);
/**
* Destructor.
* Empty.
*/
virtual ~Mks946PumpDriver();
/**
* Execute the command on the device.
* The DeviceActionDriver class gives the command to the DeviceDriver.
* Each type of device have to interpret its command and call
* the write method.
*
* @param the command to apply on the device
*/
virtual void execute(const std::string& aCommand);
private:
/**
* true for instant command
*/
bool m_startActivated;
};
}
#endif //MKS946PUMPDRIVER_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 MKS946PUMPSTATE_H
#define MKS946PUMPSTATE_H
#include <drivers/mks/mks946/Mks946PumpDriver.h>
#include <Driver.h>
namespace mks946 {
/**
* The class is the interface class describes in the pattern state .
*/
class Mks946PumpState : public DriverState<Mks946PumpDriver> {
public:
/**
* Constructor.
*
* @param Link to the class which used the state
*/
Mks946PumpState(Mks946PumpDriver* owner) : DriverState<Mks946PumpDriver>(owner) {}
/**
* Destructor.
*/
virtual ~Mks946PumpState() {}
/**
* Perform a init.
*/
virtual void init() = 0;
/**
* Perform a start.
*/
virtual void start() = 0;
/**
* Stop
*/
virtual void stop() = 0;
/**
* Read the status on the card.
*/
virtual void readStatus() = 0;
};
}
#endif //MKS946PUMPSTATE_H
<module name="mks946">
<driver class="mks946::Mks946PumpDriver"/>
</module>
\ No newline at end of file
/*
* 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/mks/mks946/Mks946PumpDef.h>
#include <drivers/mks/mks946/Mks946PumpDriver.h>
#include <drivers/mks/mks946/PerfectMks946PumpDriver.h>
using namespace std;
namespace mks946 {
/*
* Constructor
*/
PerfectMks946PumpDriver::PerfectMks946PumpDriver(
Mks946PumpDriver* owner) : Mks946PumpState(owner) {
}
/*
* Destructor
*/
PerfectMks946PumpDriver::~PerfectMks946PumpDriver() {
}
/*
* init
*/
void PerfectMks946PumpDriver::init() {
owner()->commandProgression = PROGRESSION_END_DEVICE_CONTAINER;
}
/*
* readStatus
*/
void PerfectMks946PumpDriver::readStatus() {
int32 localStatus = pump::PumpCommon::NO_STATUS;
if (owner()->m_startActivated == true) {
localStatus = pump::PumpCommon::CHANGING;
} else {
owner()->commandProgression = PROGRESSION_END_DEVICE_CONTAINER;
}
owner()->status = localStatus;
}
/*
* stop
*/
void PerfectMks946PumpDriver::stop() {
}
/*
* start
*/
void PerfectMks946PumpDriver::start() {
owner()->m_startActivated = true;
setflowCha(1,owner()->pump::PumpCommon::flow1.setpoint() );
setflowCha(2,owner()->pump::PumpCommon::flow2.setpoint() );
setflowCha(3,owner()->pump::PumpCommon::flow3.setpoint() );
setflowCha(4,owner()->pump::PumpCommon::flow4.setpoint() );
setflowCha(5,owner()->pump::PumpCommon::flow5.setpoint() );
setflowCha(6,owner()->pump::PumpCommon::flow6.setpoint() );
setChannelMode(1,owner()->pump::PumpCommon::channelStatus1.setpoint() );
setChannelMode(2,owner()->pump::PumpCommon::channelStatus2.setpoint() );
setChannelMode(3,owner()->pump::PumpCommon::channelStatus3.setpoint() );
setChannelMode(4,owner()->pump::PumpCommon::channelStatus4.setpoint() );
setChannelMode(5,owner()->pump::PumpCommon::channelStatus5.setpoint() );
setChannelMode(6,owner()->pump::PumpCommon::channelStatus6.setpoint() );
// Set to remote
ostringstream com1;
/* com1 << REMOTE_COMMAND << TERMINATOR;
writePump(com1.str());*/
sleep(1);
owner()->m_startActivated = false;
}
void PerfectMks946PumpDriver::setflowCha(int32 channel , float64 flow){
// Write values
ostringstream com2;
// Set Flow Rate
com2 << ADD_PREFIX << SETFLOWRATE_COMMAND << (boost::format("%d!%4.2f")
% channel % flow) <<TERM_COMMAND << TERMINATOR;
cout << "com2 " << com2.str() << endl;
//writePump(com2.str());
}
void PerfectMks946PumpDriver::setChannelMode(int32 channel, bool mode) {
//s = '@253QMD{}!{};FF'.format(str(channel),mode)
ostringstream com2;
if (mode == true) {
com2 << ADD_PREFIX << OPENCHANNEL_COMMAND << (boost::format("%d") % channel) << CMD_STATUS_OPEN << TERM_COMMAND
<< TERMINATOR;
} else {
com2 << ADD_PREFIX << OPENCHANNEL_COMMAND << (boost::format("%d") % channel) << CMD_STATUS_CLOSE << TERM_COMMAND
<< TERMINATOR;
}
cout << "com2 " << com2.str() << endl;
//writePump(com2.str());
}
}
/*
* 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 PERFECTMKS946PUMPDRIVER_H
#define PERFECTMKS946PUMPDRIVER_H
#include <drivers/mks/mks946/Mks946PumpState.h>
namespace mks946 {
/**
* Perfect implementation of the Mks946Pump.
*/
class PerfectMks946PumpDriver : public Mks946PumpState {
public:
/**
* Constructor.
*
* @param Link to the class which used the state
*/
PerfectMks946PumpDriver(Mks946PumpDriver* owner);
/**
* Destructor.
* Empty.
*/
virtual ~PerfectMks946PumpDriver();
/**
* Perform a init.
*/
virtual void init();
/**
* Perform a start.
*/
virtual void start();
/**
* Stop
*/
virtual void stop();
/**
* Read the status on the card.
*/
virtual void readStatus();
private:
void setflowCha(int32 channel , float64 flow);
void setChannelMode(int32 channel , bool mode);
};
}
#endif //PERFECTMKS946PUMPDRIVER_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/mks/mks946/Mks946PumpDef.h>
#include <drivers/mks/mks946/Mks946PumpDriver.h>
#include <drivers/mks/mks946/RealMks946PumpDriver.h>
using namespace std;
namespace mks946 {
/*
* Constructor
*/
RealMks946PumpDriver::RealMks946PumpDriver(
Mks946PumpDriver* owner) : Mks946PumpState(owner) {
}
/*
* Destructor
*/
RealMks946PumpDriver::~RealMks946PumpDriver() {
}
/*
* init
*/
void RealMks946PumpDriver::init() {
}
/*
* readStatus
*/
void RealMks946PumpDriver::readStatus() {
int32 localStatus = pump::PumpCommon::NO_STATUS;
if (owner()->m_startActivated == true) {
localStatus = pump::PumpCommon::CHANGING;
} else {
owner()->commandProgression = PROGRESSION_END_DEVICE_CONTAINER;
}
owner()->status = localStatus;
}
/*
* start
*/
void RealMks946PumpDriver::start() {
owner()->m_startActivated = true;
setflowCha(1,owner()->pump::PumpCommon::flow1.setpoint() );
setflowCha(2,owner()->pump::PumpCommon::flow2.setpoint() );
setflowCha(3,owner()->pump::PumpCommon::flow3.setpoint() );
setflowCha(4,owner()->pump::PumpCommon::flow4.setpoint() );
setflowCha(5,owner()->pump::PumpCommon::flow5.setpoint() );
setflowCha(6,owner()->pump::PumpCommon::flow6.setpoint() );
setChannelMode(1,owner()->pump::PumpCommon::channelStatus1.setpoint() );
setChannelMode(2,owner()->pump::PumpCommon::channelStatus2.setpoint() );
setChannelMode(3,owner()->pump::PumpCommon::channelStatus3.setpoint() );
setChannelMode(4,owner()->pump::PumpCommon::channelStatus4.setpoint() );
setChannelMode(5,owner()->pump::PumpCommon::channelStatus5.setpoint() );
setChannelMode(6,owner()->pump::PumpCommon::channelStatus6.setpoint() );
sleep(1);
owner()->m_startActivated = false;
}
/*
* stop
*/
void RealMks946PumpDriver::stop() {
// To be decided ??
}
void RealMks946PumpDriver::setflowCha(int32 channel , float64 flow){
// Write values
ostringstream com2;
// Set Flow Rate
com2 << ADD_PREFIX << SETFLOWRATE_COMMAND << (boost::format("%d!%4.2f")
% channel % flow) <<TERM_COMMAND << TERMINATOR;
cout << "com2 " << com2.str() << endl;
writePump(com2.str());
}
void RealMks946PumpDriver::setChannelMode(int32 channel, bool mode) {
ostringstream com2;
if (mode == true) {
com2 << ADD_PREFIX << OPENCHANNEL_COMMAND << (boost::format("%d") % channel) << CMD_STATUS_OPEN << TERM_COMMAND
<< TERMINATOR;
} else {
com2 << ADD_PREFIX << OPENCHANNEL_COMMAND << (boost::format("%d") % channel) << CMD_STATUS_CLOSE << TERM_COMMAND
<< TERMINATOR;
}
cout << "com2 " << com2.str() << endl;
writePump(com2.str());
}
/*
* writePump
*/
void RealMks946PumpDriver::writePump(const std::string& command) {
owner()->write(command);
// read answer
string buf;
owner()->read(buf, TERMINATOR);
}
}
/*
* 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 REALMKS946PUMPDRIVER_H
#define REALMKS946PUMPDRIVER_H
#include <drivers/mks/mks946/Mks946PumpState.h>
namespace mks946 {
/**
* Real implementation of the Mks946Pump.
*/
class RealMks946PumpDriver : public Mks946PumpState {
public:
/**
* Constructor.
*
* @param Link to the class which used the state
*/
RealMks946PumpDriver(Mks946PumpDriver* owner);
/**
* Destructor.
*/
virtual ~RealMks946PumpDriver();
/**
* Perform a init.
*/
virtual void init();
/**
* Perform a start.
*/
virtual void start();
/**
* Stop
*/
virtual void stop();
/**
* Read the status on the card.
*/
virtual void readStatus();
private:
void setflowCha(int32 channel , float64 flow);
void setChannelMode(int32 channel , bool mode);
void writePump(const std::string& command);
};
}
#endif //REALMKS946PUMPDRIVER_H
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