1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > ProcessDB实时/时序数据库——C/C++操作数据点对象

ProcessDB实时/时序数据库——C/C++操作数据点对象

时间:2020-12-17 23:47:32

相关推荐

ProcessDB实时/时序数据库——C/C++操作数据点对象

目录

前言

一、数据点字段介绍

二、新增数据点

三、删除数据点

四、修改数据点

1.全量修改数据点

2.根据字段名修改数据点信息

五、查询数据点

前言

上文已经介绍C/C++使用ProcessDB的基本操作,本文将针对数据点的相关操作进行介绍

一、数据点字段介绍

二、新增数据点

// ProcessDB_API_TEST.cpp : ProcessDB数据库示例//#include <iostream>#include <string>#include <stdio.h>#include <time.h>#include <conio.h>#include "processdb_v2.h"using namespace std;int main(int argc, char* argv[]){EBASE_RES result = NULL;int res = 0;EBASE ebase = { 0 };/* 初始化连接控制块 */res = ebase2_init(&ebase);if (0 != res){cout << "ebase2_init failed !" << endl;getchar();exit(1);}/*设置超时时间*/int timeout = 30;ebase2_set_options(&ebase, EBASE_CONNECTION_TIMEOUT, &timeout);/* 建立连接 */res = ebase2_connect(&ebase, "127.0.0.1", 8301, "root", "root");if (0 != res){cout << "login failed, \n";getchar();exit(1);}/* 新建数据点*/PointProperty pointproerty = { 0 };pointproerty.point_type = PHY_PT;pointproerty.data_type = TAG_TYPE_FLOAT32;pointproerty.time_unit = TU_SECOND;pointproerty.bottomscale = 0;pointproerty.topscale = 1;pointproerty.dev_type = 0;pointproerty.deviation = 0.05;pointproerty.alarm_low = 0;pointproerty.alarm_high = 1;pointproerty.alarm_ll = 0;pointproerty.alarm_hh = 1;//数据库名+.+数据表名+.+新建数据点名const char* fullPointName = "D99.T99.P99";//引用点idOBJECT_ID pointId = 1003000005;res = ebase2_add_point_ex4(&ebase, fullPointName, &pointproerty, "N/A", "", "Description", &pointId);if (res != 0){cout << "ebase2_add_point_ex4 failed, error code:" << res << endl;getchar();exit(1);}else{//新建数据点成功cout << "ebase2_add_point_ex4 sucess!!" << endl;}/* 关闭连接 */ebase2_close(&ebase);return 0;}

三、删除数据点

// ProcessDB_API_TEST.cpp : ProcessDB数据库示例//#include <iostream>#include <string>#include <stdio.h>#include <time.h>#include <conio.h>#include "processdb_v2.h"using namespace std;int main(int argc, char* argv[]){EBASE_RES result = NULL;int res = 0;EBASE ebase = { 0 };/* 初始化连接控制块 */res = ebase2_init(&ebase);if (0 != res){cout << "ebase2_init failed !" << endl;getchar();exit(1);}/*设置超时时间*/int timeout = 30;ebase2_set_options(&ebase, EBASE_CONNECTION_TIMEOUT, &timeout);/* 建立连接 */res = ebase2_connect(&ebase, "127.0.0.1", 8301, "root", "root");if (0 != res){cout << "login failed, \n";getchar();exit(1);}//数据库名+.+数据表名+.+数据点名const char* fullPointName = "D99.T99.P99";res = ebase2_delete_point(&ebase,fullPointName);if (res != 0){cout << "ebase2_delete_point failed, error code:" << res << endl;getchar();exit(1);}else{//新建数据点成功cout << "ebase2_delete_point sucess!!" << endl;}/* 关闭连接 */ebase2_close(&ebase);return 0;}

四、修改数据点

1.全量修改数据点

// ProcessDB_API_TEST.cpp : ProcessDB数据库示例//#include <iostream>#include <string>#include <stdio.h>#include <time.h>#include <conio.h>#include "processdb_v2.h"using namespace std;int main(int argc, char* argv[]){EBASE_RES result = NULL;int res = 0;EBASE ebase = { 0 };/* 初始化连接控制块 */res = ebase2_init(&ebase);if (0 != res){cout << "ebase2_init failed !" << endl;getchar();exit(1);}/*设置超时时间*/int timeout = 30;ebase2_set_options(&ebase, EBASE_CONNECTION_TIMEOUT, &timeout);/* 建立连接 */res = ebase2_connect(&ebase, "127.0.0.1", 8301, "root", "root");if (0 != res){cout << "login failed, \n";getchar();exit(1);}/* 修改数据点*/PointProperty pointproerty = { 0 };pointproerty.bottomscale = 0;pointproerty.topscale = 1000;//数据库名+.+数据表名+.+数据点名const char* fullPointName = "D99.T99.P99";res = ebase2_modify_point(&ebase, fullPointName, &pointproerty, "A", "", "modifyPointDescription");if (res != 0){cout << "ebase2_delete_point failed, error code:" << res << endl;getchar();exit(1);}else{//新建数据点成功cout << "ebase2_delete_point sucess!!" << endl;}/* 关闭连接 */ebase2_close(&ebase);return 0;}

2.根据字段名修改数据点信息

// ProcessDB_API_TEST.cpp : ProcessDB数据库示例//#include <iostream>#include <string>#include <stdio.h>#include <time.h>#include <conio.h>#include "processdb_v2.h"using namespace std;int main(int argc, char* argv[]){EBASE_RES result = NULL;int res = 0;EBASE ebase = { 0 };/* 初始化连接控制块 */res = ebase2_init(&ebase);if (0 != res){cout << "ebase2_init failed !" << endl;getchar();exit(1);}/*设置超时时间*/int timeout = 30;ebase2_set_options(&ebase, EBASE_CONNECTION_TIMEOUT, &timeout);/* 建立连接 */res = ebase2_connect(&ebase, "127.0.0.1", 8301, "root", "root");if (0 != res){cout << "login failed, \n";getchar();exit(1);}//设置过滤条件FilterItemSet filter_item_set = { 0 };filter_item_set.nSize = 1;FilterItem filterItemArray[1] = { 0 };filterItemArray[0].nRelation = RELATION_EQUAL;//根据数据点id,定位到要修改的idfilterItemArray[0].nItemID = FILTER_POINT_ID;sprintf(filterItemArray[0].szValue, "1003000009");filter_item_set.pItem = filterItemArray;/* 字段列表IV 初始值BV 量程低限TV 量程高限FM 小数精度EU 单位PE 计算周期FSI 强制存历史数据时间.TI 存历史超时时间AR 是否保存历史数据TC 时间维度DE 量程类型是百分比还是物理值DV 量程数值AS 报警开关AAT 报警响应方式AT 报警类型AL 报警级别ALV 报警低限AHV 报警高限AHH 报警高高限ALL 报警低低限AGI 报警分组id*///设置要修改的内容,这里以量程低限举例char field_name[12] = { 0 };sprintf(field_name, "BV");char pv[64] = "8";int effect_count = 1;res = ebase2_update_points(&ebase, &filter_item_set, field_name, strlen(pv), pv, &effect_count);if (res < 0){cout << "ebase2_update_points failed, error code:" << res << endl;getchar();exit(1);}else{cout << "ebase2_update_points sucess" << endl;}/* 关闭连接 */ebase2_close(&ebase);return 0;}

五、查询数据点

// ProcessDB_API_TEST.cpp : ProcessDB数据库示例//#include <iostream>#include <string>#include <stdio.h>#include <time.h>#include <conio.h>#include "processdb_v2.h"using namespace std;int main(int argc, char* argv[]){EBASE_RES result = NULL;int res = 0;EBASE ebase = { 0 };/* 初始化连接控制块 */res = ebase2_init(&ebase);if (0 != res){cout << "ebase2_init failed !" << endl;getchar();exit(1);}/*设置超时时间*/int timeout = 30;ebase2_set_options(&ebase, EBASE_CONNECTION_TIMEOUT, &timeout);/* 建立连接 */res = ebase2_connect(&ebase, "127.0.0.1", 8301, "root", "root");if (0 != res){cout << "login failed, \n";getchar();exit(1);}EBASE_RES res_set = NULL;/*根据数据点名,查询数据点信息,两种查询方法*/res = ebase2_query_point(&ebase,"D99.T99.P99",&res_set);if (0 > res){printf("ebase2_query_point failed, error code: %d.\n", res);getchar();exit(1);}else{printf("ebase2_query_point success %d.\n");}/*根据筛选条件,查询数据点列表,两种查询方法*/FilterItemSet filter_item_set = { 0 };filter_item_set.nSize = 1;FilterItem filterItemArray[8] = { 0 };filterItemArray[0].nItemID = FILTER_POINT_NAME;filterItemArray[0].nRelation = RELATION_EQUAL;sprintf(filterItemArray[0].szValue, "P99");filter_item_set.pItem = filterItemArray;res = ebase2_query_points(&ebase, &filter_item_set, 30, 0, &res_set);if (0 > res){printf("ebase2_query_points failed, error code: %d.\n", res);getchar();exit(1);}int resultCount = 0;res = ebase2_get_result_count(res_set, &resultCount);if (0 != res){printf("ebase2_get_result_count failed, error code: %d\n", res);}for (int pointLoop = 0; pointLoop < resultCount; pointLoop++){OBJECT_ID pointid = 0;char* point_name = NULL;char* point_parent_name = NULL;res = ebase2_get_point_id(res_set, pointLoop, &pointid);res = ebase2_get_point_name(res_set, pointLoop, &point_name);res = ebase2_get_point_parent_name(res_set, pointLoop, &point_parent_name);char express[256] = { 0 };memset(express, 0, sizeof(express));char pointtype = 0;res = ebase2_get_point_type(res_set, pointLoop, &pointtype);if (pointtype == 2){if (ebase2_query_point_express_by_id(&ebase, pointid, express) != 0){printf("get point express failed.");return false;}}char datatype = 0;char* unit = NULL;float bottomscale = 0;float scale = 0;float low = 0;float high = 0;char* point_desc = NULL;char achived = 0;char ioType = 0;char time_compress = 0;char devType = 0;float deviation = 0;res = ebase2_get_point_archived(res_set, pointLoop, &achived);res = ebase2_get_point_io_type(res_set, pointLoop, &ioType);res = ebase2_get_point_time_compress(res_set, pointLoop, &time_compress);res = ebase2_get_point_dev_type(res_set, pointLoop, &devType);res = ebase2_get_point_deviation(res_set, pointLoop, &deviation);res = ebase2_get_point_data_type(res_set, pointLoop, &datatype);res = ebase2_get_point_unit(res_set, pointLoop, &unit);res = ebase2_get_point_scale_bottom(res_set, pointLoop, &bottomscale);res = ebase2_get_point_scale_top(res_set, pointLoop, &scale);res = ebase2_get_point_alarm_low(res_set, pointLoop, &low);res = ebase2_get_point_alarm_high(res_set, pointLoop, &high);res = ebase2_get_point_desc(res_set, pointLoop, &point_desc);printf("id=\"%d\" name=\"%s.%s\" pointType=\"%d\" dataType=\"%d\" unit=\"%s\" bottomScale=\"%.4f\" topScale=\"%.4f\" lowLimit=\"%.4f\" highLimit=\"%.4f\" achived=\"%d\" ioType=\"%d\" compress=\"%d\" devType=\"%d\" deviation=\"%f\" express=\"%s\" desc=\"%s\"\n", pointid, point_parent_name, point_name, pointtype, datatype, unit, bottomscale, scale, low, high, achived, ioType, time_compress, devType, deviation, express == NULL ? "" : express, point_desc);}/* 关闭连接 */ebase2_close(&ebase);return 0;}

运行示例如下:

ebase2_query_point success 1431210144.id="1003000009" name="D99.T99.P99" pointType="0" dataType="0" unit="A" bottomScale="0.0000" topScale="1000.0000" lowLimit="0.0000" highLimit="0.0000" achived="0" ioType="0" compress="0" devType="0" deviation="0.000000" express="" desc="modifyPointDescription"id="1006000046" name="D30.T31.P99" pointType="0" dataType="0" unit="N/A" bottomScale="1.0000" topScale="100.0000" lowLimit="0.0000" highLimit="100.0000" achived="1" ioType="0" compress="0" devType="1" deviation="0.050000" express="" desc=""

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。