文章目录
- 环境
- create a device class
- compile the device class
- register the device
- start the device
- explore the device
- 故障问题解决
- 参考
继续上一篇:
https://blog.csdn.net/woshigaowei5146/article/details/128443892?spm=1001.2014.3001.5501
环境
虚拟机:VMware
Ubuntu:20.04LTS
Tango:9.3.5
create a device class
启动Tango,jive,pogo,astor
sudo /usr/local/tango/bin/tango start
/usr/local/tango/bin/jive &
/usr/local/tango/bin/pogo &
/usr/local/tango/bin/astor &
后来发现pogo经常出现加载不出来的情况。但是偶尔会有一次可以打开,暂未找到规律,随机事件。
https://github.com/tango-controls/pogo/issues/83
在Pogo中定义类及变量
File-Export package,检查所有的headers。该工具将创建一个包含packages的新文件夹。
File -> Generate 点击 OK。
compile the device class
cd packaging
./autogen.sh
./configure --prefix=$HOME/packaging
make
make install
如果报错:./autogen.sh: 3: autoreconf: not found
sudo apt-get install autoconf
sudo apt-get install automake
sudo apt-get install libtool
https://www.iteye.com/blog/shangxun-1938687
如果提示:Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.,在bashrc添加:并重新configure
export PKG_CONFIG_PATH=/usr/local/tango/lib/pkgconfig
如果一切正常,您将在src目录中看到这些文件:
register the device
打开 Jive - Edit -> Create Server
填写如下表格:
TangoQuickStart/test
TangoQuickStart
training-laboratory/quick-start/0
点击 Register server.
start the device
为了启动设备,使用命令行,转到编译c++类的文件夹
cd packaging/src/
使用下面的命令:
<TangoClassName> <instance>
TangoClassName是Pogo和Jive创建的类名称,instance 是TANGO数据库的实例名称(在Jive创建)
输入:
./TangoQuickStart test
explore the device
修改 TangoQuickStart.cpp:主要是增加:set_state(Tango::RUNNING);
/*----- PROTECTED REGION ID(TangoQuickStart.cpp) ENABLED START -----*/
//=============================================================================
//
// file : TangoQuickStart.cpp
//
// description : C++ source for the TangoQuickStart class and its commands.
// The class is derived from Device. It represents the
// CORBA servant object which will be accessed from the
// network. All commands which can be executed on the
// TangoQuickStart are implemented in this file.
//
// project : test
//
// This file is part of Tango device class.
//
// Tango is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Tango is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Tango. If not, see <http://www.gnu.org/licenses/>.
//
//
//
//=============================================================================
// This file is generated by POGO
// (Program Obviously used to Generate tango Object)
//=============================================================================
#include <TangoQuickStart.h>
#include <TangoQuickStartClass.h>
/*----- PROTECTED REGION END -----*/ // TangoQuickStart.cpp
/**
* TangoQuickStart class description:
* test description
*/
//================================================================
// The following table gives the correspondence
// between command and method names.
//
// Command name | Method name
//================================================================
// State | Inherited (no method)
// Status | Inherited (no method)
//================================================================
//================================================================
// Attributes managed is:
//================================================================
// boolTest | Tango::DevBoolean Scalar
//================================================================
namespace TangoQuickStart_ns
{
/*----- PROTECTED REGION ID(TangoQuickStart::namespace_starting) ENABLED START -----*/
// static initializations
/*----- PROTECTED REGION END -----*/ // TangoQuickStart::namespace_starting
//--------------------------------------------------------
/**
* Method : TangoQuickStart::TangoQuickStart()
* Description : Constructors for a Tango device
* implementing the classTangoQuickStart
*/
//--------------------------------------------------------
TangoQuickStart::TangoQuickStart(Tango::DeviceClass *cl, string &s)
: TANGO_BASE_CLASS(cl, s.c_str())
{
/*----- PROTECTED REGION ID(TangoQuickStart::constructor_1) ENABLED START -----*/
init_device();
/*----- PROTECTED REGION END -----*/ // TangoQuickStart::constructor_1
}
//--------------------------------------------------------
TangoQuickStart::TangoQuickStart(Tango::DeviceClass *cl, const char *s)
: TANGO_BASE_CLASS(cl, s)
{
/*----- PROTECTED REGION ID(TangoQuickStart::constructor_2) ENABLED START -----*/
init_device();
/*----- PROTECTED REGION END -----*/ // TangoQuickStart::constructor_2
}
//--------------------------------------------------------
TangoQuickStart::TangoQuickStart(Tango::DeviceClass *cl, const char *s, const char *d)
: TANGO_BASE_CLASS(cl, s, d)
{
/*----- PROTECTED REGION ID(TangoQuickStart::constructor_3) ENABLED START -----*/
init_device();
/*----- PROTECTED REGION END -----*/ // TangoQuickStart::constructor_3
}
//--------------------------------------------------------
/**
* Method : TangoQuickStart::delete_device()
* Description : will be called at device destruction or at init command
*/
//--------------------------------------------------------
void TangoQuickStart::delete_device()
{
DEBUG_STREAM << "TangoQuickStart::delete_device() " << device_name << endl;
/*----- PROTECTED REGION ID(TangoQuickStart::delete_device) ENABLED START -----*/
// Delete device allocated objects
if (attr_boolTest_read) {
delete attr_boolTest_read;
attr_boolTest_read = 0;
}
/*----- PROTECTED REGION END -----*/ // TangoQuickStart::delete_device
delete[] attr_boolTest_read;
}
//--------------------------------------------------------
/**
* Method : TangoQuickStart::init_device()
* Description : will be called at device initialization.
*/
//--------------------------------------------------------
void TangoQuickStart::init_device()
{
DEBUG_STREAM << "TangoQuickStart::init_device() create device " << device_name << endl;
/*----- PROTECTED REGION ID(TangoQuickStart::init_device_before) ENABLED START -----*/
// Initialization before get_device_property() call
/*----- PROTECTED REGION END -----*/ // TangoQuickStart::init_device_before
// No device property to be read from database
attr_boolTest_read = new Tango::DevBoolean;
*attr_boolTest_read = true;
attr_boolTest_write = false;
/*----- PROTECTED REGION ID(TangoQuickStart::init_device) ENABLED START -----*/
// Initialize device
set_state(Tango::RUNNING);
/*----- PROTECTED REGION END -----*/ // TangoQuickStart::init_device
}
//--------------------------------------------------------
/**
* Method : TangoQuickStart::always_executed_hook()
* Description : method always executed before any command is executed
*/
//--------------------------------------------------------
void TangoQuickStart::always_executed_hook()
{
DEBUG_STREAM << "TangoQuickStart::always_executed_hook() " << device_name << endl;
/*----- PROTECTED REGION ID(TangoQuickStart::always_executed_hook) ENABLED START -----*/
// code always executed before all requests
/*----- PROTECTED REGION END -----*/ // TangoQuickStart::always_executed_hook
}
//--------------------------------------------------------
/**
* Method : TangoQuickStart::read_attr_hardware()
* Description : Hardware acquisition for attributes
*/
//--------------------------------------------------------
void TangoQuickStart::read_attr_hardware(TANGO_UNUSED(vector<long> &attr_list))
{
DEBUG_STREAM << "TangoQuickStart::read_attr_hardware(vector<long> &attr_list) entering... " << endl;
/*----- PROTECTED REGION ID(TangoQuickStart::read_attr_hardware) ENABLED START -----*/
// Add your own code
/*----- PROTECTED REGION END -----*/ // TangoQuickStart::read_attr_hardware
}
//--------------------------------------------------------
/**
* Method : TangoQuickStart::write_attr_hardware()
* Description : Hardware writing for attributes
*/
//--------------------------------------------------------
void TangoQuickStart::write_attr_hardware(TANGO_UNUSED(vector<long> &attr_list))
{
DEBUG_STREAM << "TangoQuickStart::write_attr_hardware(vector<long> &attr_list) entering... " << endl;
/*----- PROTECTED REGION ID(TangoQuickStart::write_attr_hardware) ENABLED START -----*/
// Add your own code
/*----- PROTECTED REGION END -----*/ // TangoQuickStart::write_attr_hardware
}
//--------------------------------------------------------
/**
* Read attribute boolTest related method
* Description:
*
* Data type: Tango::DevBoolean
* Attr type: Scalar
*/
//--------------------------------------------------------
void TangoQuickStart::read_boolTest(Tango::Attribute &attr)
{
DEBUG_STREAM << "TangoQuickStart::read_boolTest(Tango::Attribute &attr) entering... " << endl;
/*----- PROTECTED REGION ID(TangoQuickStart::read_boolTest) ENABLED START -----*/
// Set the attribute value
attr.set_value(attr_boolTest_read);
/*----- PROTECTED REGION END -----*/ // TangoQuickStart::read_boolTest
}
//--------------------------------------------------------
/**
* Write attribute boolTest related method
* Description:
*
* Data type: Tango::DevBoolean
* Attr type: Scalar
*/
//--------------------------------------------------------
void TangoQuickStart::write_boolTest(Tango::WAttribute &attr)
{
DEBUG_STREAM << "TangoQuickStart::write_boolTest(Tango::WAttribute &attr) entering... " << endl;
// Retrieve write value
Tango::DevBoolean w_val;
attr.get_write_value(w_val);
/*----- PROTECTED REGION ID(TangoQuickStart::write_boolTest) ENABLED START -----*/
*attr_boolTest_read = w_val;
attr_boolTest_write = w_val;
DEBUG_STREAM << "Read and write attributes were set to the same value" << std::endl;
DEBUG_STREAM << "w_val = " << w_val << std::endl;
DEBUG_STREAM << "attr_boolTest_read = " << *attr_boolTest_read << std::endl;
/*----- PROTECTED REGION END -----*/ // TangoQuickStart::write_boolTest
}
//--------------------------------------------------------
/**
* Method : TangoQuickStart::add_dynamic_attributes()
* Description : Create the dynamic attributes if any
* for specified device.
*/
//--------------------------------------------------------
void TangoQuickStart::add_dynamic_attributes()
{
/*----- PROTECTED REGION ID(TangoQuickStart::add_dynamic_attributes) ENABLED START -----*/
// Add your own code to create and add dynamic attributes if any
/*----- PROTECTED REGION END -----*/ // TangoQuickStart::add_dynamic_attributes
}
//--------------------------------------------------------
/**
* Method : TangoQuickStart::add_dynamic_commands()
* Description : Create the dynamic commands if any
* for specified device.
*/
//--------------------------------------------------------
void TangoQuickStart::add_dynamic_commands()
{
/*----- PROTECTED REGION ID(TangoQuickStart::add_dynamic_commands) ENABLED START -----*/
// Add your own code to create and add dynamic commands if any
/*----- PROTECTED REGION END -----*/ // TangoQuickStart::add_dynamic_commands
}
/*----- PROTECTED REGION ID(TangoQuickStart::namespace_ending) ENABLED START -----*/
// Additional Methods
/*----- PROTECTED REGION END -----*/ // TangoQuickStart::namespace_ending
} // namespace
修改TangoQuickStart.h:
/*----- PROTECTED REGION ID(TangoQuickStart.h) ENABLED START -----*/
//=============================================================================
//
// file : TangoQuickStart.h
//
// description : Include file for the TangoQuickStart class
//
// project : test
//
// This file is part of Tango device class.
//
// Tango is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Tango is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Tango. If not, see <http://www.gnu.org/licenses/>.
//
//
//
//=============================================================================
// This file is generated by POGO
// (Program Obviously used to Generate tango Object)
//=============================================================================
#ifndef TangoQuickStart_H
#define TangoQuickStart_H
#include <tango.h>
/*----- PROTECTED REGION END -----*/ // TangoQuickStart.h
/**
* TangoQuickStart class description:
* test description
*/
namespace TangoQuickStart_ns
{
/*----- PROTECTED REGION ID(TangoQuickStart::Additional Class Declarations) ENABLED START -----*/
// Additional Class Declarations
/*----- PROTECTED REGION END -----*/ // TangoQuickStart::Additional Class Declarations
class TangoQuickStart : public TANGO_BASE_CLASS
{
/*----- PROTECTED REGION ID(TangoQuickStart::Data Members) ENABLED START -----*/
// Add your own data members
/*----- PROTECTED REGION END -----*/ // TangoQuickStart::Data Members
// Attribute data members
public:
Tango::DevBoolean *attr_boolTest_read;
Tango::DevBoolean attr_boolTest_write;
// Constructors and destructors
public:
/**
* Constructs a newly device object.
*
* @param cl Class.
* @param s Device Name
*/
TangoQuickStart(Tango::DeviceClass *cl,string &s);
/**
* Constructs a newly device object.
*
* @param cl Class.
* @param s Device Name
*/
TangoQuickStart(Tango::DeviceClass *cl,const char *s);
/**
* Constructs a newly device object.
*
* @param cl Class.
* @param s Device name
* @param d Device description.
*/
TangoQuickStart(Tango::DeviceClass *cl,const char *s,const char *d);
/**
* The device object destructor.
*/
~TangoQuickStart() {delete_device();};
// Miscellaneous methods
public:
/*
* will be called at device destruction or at init command.
*/
void delete_device();
/*
* Initialize the device
*/
virtual void init_device();
/*
* Always executed method before execution command method.
*/
virtual void always_executed_hook();
// Attribute methods
public:
//--------------------------------------------------------
/*
* Method : TangoQuickStart::read_attr_hardware()
* Description : Hardware acquisition for attributes.
*/
//--------------------------------------------------------
virtual void read_attr_hardware(vector<long> &attr_list);
//--------------------------------------------------------
/*
* Method : TangoQuickStart::write_attr_hardware()
* Description : Hardware writing for attributes.
*/
//--------------------------------------------------------
virtual void write_attr_hardware(vector<long> &attr_list);
/**
* Attribute boolTest related methods
* Description:
*
* Data type: Tango::DevBoolean
* Attr type: Scalar
*/
virtual void read_boolTest(Tango::Attribute &attr);
virtual void write_boolTest(Tango::WAttribute &attr);
virtual bool is_boolTest_allowed(Tango::AttReqType type);
//--------------------------------------------------------
/**
* Method : TangoQuickStart::add_dynamic_attributes()
* Description : Add dynamic attributes if any.
*/
//--------------------------------------------------------
void add_dynamic_attributes();
// Command related methods
public:
//--------------------------------------------------------
/**
* Method : TangoQuickStart::add_dynamic_commands()
* Description : Add dynamic commands if any.
*/
//--------------------------------------------------------
void add_dynamic_commands();
/*----- PROTECTED REGION ID(TangoQuickStart::Additional Method prototypes) ENABLED START -----*/
// Additional Method prototypes
/*----- PROTECTED REGION END -----*/ // TangoQuickStart::Additional Method prototypes
};
/*----- PROTECTED REGION ID(TangoQuickStart::Additional Classes Definitions) ENABLED START -----*/
// Additional Classes Definitions
/*----- PROTECTED REGION END -----*/ // TangoQuickStart::Additional Classes Definitions
} // End of namespace
#endif // TangoQuickStart_H
重新编译
make
make install
./TangoQuickStart test
在./TangoQuickStart test运行后,可以在Jive中打开AtkPanel并控制定义的变量。
自带例程:在/usr/local/tango/bin运行./TangoTest test 进行测试。
故障问题解决
- ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: NO)
- sudo /usr/local/tango/bin/tango start时出现报错:
Stop MySQL using
sudo service mysql stop
or
sudo /usr/local/mysql/support-files/mysql.server stop
Start it in safe mode:
sudo mysqld_safe --skip-grant-tables --skip-networking
(the above line is the whole command)
This will be an ongoing command until the process is finished, so open another shell/terminal window, log in without a password:
mysql -u root
UPDATE mysql.user SET Password=PASSWORD('mypassword') WHERE User='root';
实测有效。
https://stackoverflow.com/questions/21944936/error-1045-28000-access-denied-for-user-rootlocalhost-using-password-y
参考
https://tango-controls.readthedocs.io/en/latest/getting-started/development/cpp/cpp-quick-start.html