Commit b96147a9 authored by locatelli's avatar locatelli
Browse files

Sane Nanokin device integration

parent a7df5e16
<module name="remotenanokin">
<controller class="nanokin::RemoteNanokin"/>
<include path="$(NOMAD_HOME)/../NomadModules/src"/>
</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 <iostream>
#include <common/base/ServerProperties.h>
#include "controllers/common/family/Families.h"
#include "RemoteNanokin.h"
namespace nanokin {
using namespace std;
using namespace common;
using namespace boost;
using namespace cameo;
const std::string RemoteNanokin::TYPE = "remote_nanokin";
const std::string RemoteNanokin::NANOKIN_CMD = "vascokin";
/*
* Constructor
*/
RemoteNanokin::RemoteNanokin(const std::string& name) :
ExperimentController(name), controller::Stoppable(this) {
setFamily(family::SAMPLE_ENVIRONMENT);
serverEndpoint.init(this, SAVE, "cameo_server");
m_driver.init(this, "driver");
m_initialized = false;
}
RemoteNanokin::RemoteNanokin(const RemoteNanokin& controller) : ExperimentController(controller), controller::Stoppable(this) {
m_initialized = false;
}
/*
* Destructor
*/
RemoteNanokin::~RemoteNanokin() {
}
void RemoteNanokin::postConfiguration() {
if (m_server.get() == 0) {
// Create a new server if it is not already created.
// In case of a simulated server, avoid the real remote endpoint.
if (serverEndpoint() == "" || m_driver->state() != REAL_DEVICE_CONTAINER) {
m_server.reset(new Server(application::This::getServer().getEndpoint()));
} else {
m_server.reset(new Server(serverEndpoint()));
}
}
}
/*
* start
*/
void RemoteNanokin::start() {
commandProgression = 0;
commandStatus.setRunning();
try {
if (!m_server->isAvailable(10000)) {
cout << "Nanokin cameo server is not available" << endl;
commandStatus.setError();
return;
}
cout << "Nanokin cameo server is connected to " << getName() << endl;
m_StartApplication = m_server->connect(NANOKIN_CMD);
cout << "connected application" << endl;
if (m_StartApplication->exists()) {
// The application exists from a previous server session
m_StartApplication->kill();
application::State state = m_StartApplication->waitFor();
cout << "Terminated start application " << state << endl;
}
//start args="START DefaultSOP.sopx c:\\temp save.dat"
vector<string> args;
args.push_back("START");
args.push_back("DefaultSOP.sopx");
args.push_back("c:\\temp");
args.push_back("save.dat");
m_StartApplication = m_server->start(NANOKIN_CMD, args);
// if (m_StartApplication->exists()) {
// cout << "No matlab application" << endl;
// return false;
// }
m_StartApplication->waitFor(application::STOPPED);
} catch (const std::exception & e) {
// Currently an exception can occur during isAvailable.
cout << "Unexpected exception during nanokin cameo connection: " << e.what() << endl;
}
}
/*
* stop
*/
void RemoteNanokin::stop() {
try {
if (!m_server->isAvailable(10000)) {
cout << "Nanokin cameo server is not available" << endl;
return;
}
cout << "Nanokin cameo server is connected to " << getName() << endl;
m_StopApplication = m_server->connect(NANOKIN_CMD);
cout << "connected application" << endl;
if (m_StopApplication->exists()) {
// The application exists from a previous server session
m_StopApplication->kill();
application::State state = m_StopApplication->waitFor();
cout << "Terminated stop application " << state << endl;
}
vector<string> args;
args.push_back("STOP");
m_StopApplication = m_server->start(NANOKIN_CMD, args);
// if (m_StartApplication->exists()) {
// cout << "No matlab application" << endl;
// return false;
// }
m_StopApplication->waitFor(application::STOPPED);
} catch (const std::exception & e) {
// Currently an exception can occur during isAvailable.
cout << "Unexpected exception during nanokin cameo connection: " << e.what() << endl;
}
commandProgression = 100;
commandStatus.setIdle();
}
}
/*
* 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 REMOTENANOKIN_H
#define REMOTENANOKIN_H
#include <Controller.h>
#include <cameo/cameo.h>
#include "drivers/utilities/null/NullDriver.h"
namespace nanokin {
class RemoteNanokin: public ExperimentController, public controller::Stoppable {
public:
//! Type of controller
static const std::string TYPE;
RemoteNanokin(const std::string& name);
RemoteNanokin(const RemoteNanokin& nano);
virtual ~RemoteNanokin();
virtual void postConfiguration();
Property<std::string> serverEndpoint;
private:
virtual void start();
virtual void stop();
std::unique_ptr<cameo::Server> m_server;
std::unique_ptr<cameo::application::Instance> m_StartApplication;
std::unique_ptr<cameo::application::Instance> m_StopApplication;
DriverPtr<driver::NullDriver> m_driver;
bool m_initialized;
static const std::string NANOKIN_CMD;
};
}
#endif
<plugin>
<controller type="remote_nanokin" role="remote_nanokin1"/>
<number_of_lines nb_lines="1"/>
</plugin>
<controller_plugin_config type="remote_nanokin">
<image key="FUN_GENERATOR"/>
<settings view="remote_nanokinView.xml"/>
<command view="remote_nanokinCommandView.xml"/>
</controller_plugin_config>
<?xml version="1.0" encoding="ISO-8859-1" ?>
<controller type="remote_nanokin">
<property name="commandStatus" type="int32">
</property>
</controller>
<plugin>
<status role="remote_nanokin1" property="commandStatus" prefix="remote_nanokin.statusPrefix" valuesImagesAndLabels="commandStatusUnknown,commandStatusIdle,commandStatusRunning,commandStatusWarning,commandStatusError"/>
<newLine/>
<button role="remote_nanokin1" command="start" prefix="Start"/>
<button role="remote_nanokin1" command="stop" prefix="Stop"/>
</plugin>
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