106 lines
3.7 KiB
C++
106 lines
3.7 KiB
C++
|
|
#pragma one
|
|||
|
|
#include <TestProject/ihd_test/ihdb_inc/data_types.h>
|
|||
|
|
#include <TestProject/ihd_test/ihdb_inc/error_code.h>
|
|||
|
|
#include <TestProject/ihd_test/ihdb_inc/hd3Enum.h>
|
|||
|
|
#include <TestProject/ihd_test/ihdb_inc/hd3MaskDefine.h>
|
|||
|
|
#include <TestProject/ihd_test/ihdb_inc/hd3Struct.h>
|
|||
|
|
#include <TestProject/ihd_test/ihdb_inc/hdKingAPI.h>
|
|||
|
|
#include <TestProject/ihd_test/ihdb_inc/ihyperdb.h>
|
|||
|
|
// #include <TestProject/ihd_test/ihdb_inc/IhyperDBcommon.hh>
|
|||
|
|
#include <chrono>
|
|||
|
|
#include <cstring>
|
|||
|
|
#include <iostream>
|
|||
|
|
#include <string>
|
|||
|
|
using std::cout;
|
|||
|
|
using std::endl;
|
|||
|
|
using std::string;
|
|||
|
|
HD3Time convert_to_hd_tp(std::chrono::system_clock::time_point time_point);
|
|||
|
|
int main() {
|
|||
|
|
HD3Connection conn;
|
|||
|
|
strcpy(conn.szAddress, "100.10.10.101");
|
|||
|
|
conn.nPort = 5673;
|
|||
|
|
conn.nTimeout = 3;
|
|||
|
|
bool m_isconn = false;
|
|||
|
|
|
|||
|
|
HD3TimeRegion hd3time1;
|
|||
|
|
|
|||
|
|
hd3time1.left = convert_to_hd_tp(std::chrono::system_clock::now() -
|
|||
|
|
std::chrono::hours(1));
|
|||
|
|
hd3time1.right = convert_to_hd_tp(std::chrono::system_clock::now() -
|
|||
|
|
std::chrono::minutes(1));
|
|||
|
|
int32 recode_num =
|
|||
|
|
(std::chrono::hours(1) - std::chrono::minutes(1)).count() / 50;
|
|||
|
|
|
|||
|
|
/*连接ihd*/
|
|||
|
|
auto nRet = nt3_connect(&conn);
|
|||
|
|
if (nRet != RD_SUCCESS) {
|
|||
|
|
cout << "连接失败!错误码:" << nRet << endl;
|
|||
|
|
return 0;
|
|||
|
|
} else {
|
|||
|
|
m_isconn = true;
|
|||
|
|
cout << "连接成功:" << nRet << endl;
|
|||
|
|
}
|
|||
|
|
/*查询 tagname的tagid*/
|
|||
|
|
string tag_name = "TCM1750_MNT-1-72-ACM-1";
|
|||
|
|
HD3TagBasicInfo basic_info[1];
|
|||
|
|
strcpy(basic_info[0].szTagName, tag_name.c_str());
|
|||
|
|
int32 error_codes[1];
|
|||
|
|
// 调用ihdb原生api查询
|
|||
|
|
tag3_query_tags_basic_info_by_name(
|
|||
|
|
HD3M_COMM_PROP_TAG_NAME | HD3M_COMM_PROP_TAG_TYPE, 1, basic_info,
|
|||
|
|
error_codes);
|
|||
|
|
if (error_codes[0] == RD_SUCCESS) {
|
|||
|
|
cout << tag_name << "的tagid:" << basic_info[0].nTagID << endl;
|
|||
|
|
} else {
|
|||
|
|
cout << tag_name << "tagid查询失败!错误码" << error_codes[0] << endl;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/*查询原始数据数量*/
|
|||
|
|
int32 records_num = 0;
|
|||
|
|
auto nRet3 = ar3_query_raw_records_number(basic_info[0].nTagID, &hd3time1,
|
|||
|
|
&records_num);
|
|||
|
|
if (nRet3 != RD_SUCCESS) {
|
|||
|
|
cout << tag_name << ",查询数量失败失败!错误码:" << nRet3 << endl;
|
|||
|
|
} else {
|
|||
|
|
cout << tag_name << ",查询成功,数量:" << records_num << endl;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/*查询原始数据*/
|
|||
|
|
const size_t once_query_size = 72000;
|
|||
|
|
HD3Record* records_queried = nullptr;
|
|||
|
|
records_queried = new HD3Record[once_query_size];
|
|||
|
|
memset(records_queried, 0x00, sizeof(HD3Record) * once_query_size);
|
|||
|
|
auto nRet2 = ar3_query_raw_records(basic_info[0].nTagID, &hd3time1,
|
|||
|
|
&recode_num, records_queried);
|
|||
|
|
if (nRet2 != RD_SUCCESS) {
|
|||
|
|
cout << tag_name << ",查询失败失败!错误码:" << nRet2 << endl;
|
|||
|
|
} else {
|
|||
|
|
cout << tag_name << ",查询成功,类型:" << (*records_queried).nTagType
|
|||
|
|
<< ",最新值:" << (*records_queried).NumberValue() << endl;
|
|||
|
|
}
|
|||
|
|
delete[] records_queried;
|
|||
|
|
records_queried = nullptr;
|
|||
|
|
|
|||
|
|
/*断开ihd连接*/
|
|||
|
|
if (m_isconn) {
|
|||
|
|
auto nRet = nt3_disconnect();
|
|||
|
|
if (nRet != RD_SUCCESS) {
|
|||
|
|
cout << "断开连接失败!错误码:" << nRet << endl;
|
|||
|
|
} else {
|
|||
|
|
cout << "断开连接成功:" << nRet << endl;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
HD3Time convert_to_hd_tp(std::chrono::system_clock::time_point time_point) {
|
|||
|
|
HD3Time hd_tp;
|
|||
|
|
hd_tp.nSec = std::chrono::duration_cast<std::chrono::seconds>(
|
|||
|
|
time_point.time_since_epoch())
|
|||
|
|
.count();
|
|||
|
|
hd_tp.nMsec =
|
|||
|
|
std::chrono::duration_cast<std::chrono::milliseconds>(
|
|||
|
|
(time_point - std::chrono::seconds(hd_tp.nSec)).time_since_epoch())
|
|||
|
|
.count();
|
|||
|
|
return hd_tp;
|
|||
|
|
}
|