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

目录

前言

一、数据点字段介绍

二、新增数据点

三、删除数据点

四、修改数据点

1.全量修改数据点

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

五、查询数据点


前言

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


一、数据点字段介绍

字段注释
id数据点id
name数据点名
desc数据点描述

unit

单位

point_type

数据点类型  0是采样点 1是统计点 2是计算点

priority

优先级 低是2 中是1 高是0

data_type

数据类型

archived

是否保存历史数据(默认不填写,则不保存)0是未存档,1是存档

io_type

IO类型(采样点专属属性) 0为输入 1为输出 2为中间变量 3为网关

space_compress

空间维度 1是差值压缩,2是数据块压缩,3是两者全选

time_unit

分辨率 0是秒 1是毫秒 2是微秒

format

小数精度 例如数据类型为int,则没有小数精度

init_value

初始值

bottomscale

量程低限

topscale

量程高限

alarm_low

告警低限

alarm_high

告警高限

deviation

量程数值,默认是百分之0.05

dev_type

按量程百分比是PERCENT或者0,按量程物理值是PHYSIC或者1

time_compress

存历史超时时间

period

计算周期 计算点专属属性

alarm_switch

是否告警(必填) 0是告警 1是告警
alarm_type告警类别 NO ALARM无告警; DEAD ZONE ALARM 死区告警 ;TIMEOUT ALARM 超时告警; ON ALARM  开启告警 ;OFF ALARM 关闭告警 CHANGE ALARM 变化; LOW HIGH 低高限; LL HH 低低高高限,

alarm_ack_type

响应方式  0是MANUAL ;1是AUTO

alarm_level

告警级别 none是ZERO 一级是ONE 二级是TWO 三级是THREE 四级是FOUR

alarm_hh

告警高高限

alarm_ll

告警低低限

alarm_group_id

告警分组ID

time_compress

时间维度 0是deadband死区压缩, 1是linuar线性压缩,2是None无压缩

二、新增数据点

// 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";
	//引用点id
	OBJECT_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,定位到要修改的id
	filterItemArray[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=""



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值