目录
前言
ProcessDB实时/时序数据库支持C#语言开发,本文将针对C#操作ProcessDB库的实时数据的相关操作进行介绍
一、实时数据字段介绍
字段 | 注释 |
id | 数据点id |
name | 数据点名 |
nTagType | 数据类型 |
nQuality | 数据质量 |
nMilliSecond | 数据时间(毫秒) |
nSecond | 数据时间(秒) |
nDigital | 数字量 |
bBool | bool类型的值 |
nuInt8 | uint8类型的值 |
nInt8 | in8类型的值 |
nuInt16 | uint16类型的值 |
nInt16 | int16类型的值 |
nuInt32 | uint32类型的值 |
nInt32 | int32类型的值 |
nuInt64 | uint64类型的值 |
nInt64 | Int64类型的值 |
nTime | time时间类型的值 |
fFloat32 | float32类型的值 |
fFloat64 | float64类型的值 |
二、根据点名插入实时数据
ProcessDB支持根据点名列表,批量插入实时数据
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProcessDB;
namespace Data_RealTime
{
class Program
{
static void Main(string[] args)
{
TestRealTime testRealTime = new TestRealTime();
int res = testRealTime.RealTimeTest();
}
}
public class TestRealTime
{
public class pointlist
{
public string pointname { get; set; }
public int pointid { get; set; }
public DATA_TYPE datatype { get; set; }
}
static int add_realtime_data_by_name(string pointname, DATA_TYPE datatype)
{
/* 根据点名称添加实时数据到容器 */
int i = 1;
float val = i * 2.3f;
byte val1 = 0;
byte val2 = 2;
short val3 = 3;
int val4 = 4;
long val5 = 5;
float val6 = i * 3.4f;
MemSampleRecord memSampleRecord = new MemSampleRecord();
memSampleRecord.nTagType = (byte)datatype;
switch (memSampleRecord.nTagType)
{
case (byte)DATA_TYPE.TAG_TYPE_FLOAT32:
memSampleRecord.fFloat32 = val;
break;
case (byte)DATA_TYPE.TAG_TYPE_DIGITAL:
memSampleRecord.nDigital = val1;
break;
case (byte)DATA_TYPE.TAG_TYPE_UINT8:
memSampleRecord.nUInt8 = val2;
break;
case (byte)DATA_TYPE.TAG_TYPE_INT8:
memSampleRecord.nInt8 = val2;
break;
case (byte)DATA_TYPE.TAG_TYPE_UINT16:
memSampleRecord.nUInt16 = val3;
break;
case (byte)DATA_TYPE.TAG_TYPE_INT16:
memSampleRecord.nInt16 = val3;
break;
case (byte)DATA_TYPE.TAG_TYPE_UINT32:
memSampleRecord.nUInt32 = val4;
break;
case (byte)DATA_TYPE.TAG_TYPE_INT32:
memSampleRecord.nInt32 = val4;
break;
case (byte)DATA_TYPE.TAG_TYPE_UINT64:
memSampleRecord.nUInt64 = val5;
break;
case (byte)DATA_TYPE.TAG_TYPE_INT64:
memSampleRecord.nInt64 = val5;
break;
case (byte)DATA_TYPE.TAG_TYPE_FLOAT64:
memSampleRecord.fFloat64 = val6;
break;
}
int res = ProcessDBDao.getInstance().add_realtime_data_to_update_builder_by_name(pointname, ref memSampleRecord);
if (0 != res)
{
Console.WriteLine("add {0} realtime_data to builder by name failed!error code: {1}", pointname, res);
return res;
}
else
{
switch (memSampleRecord.nTagType)
{
case (byte)DATA_TYPE.TAG_TYPE_FLOAT32:
Console.WriteLine("Using pointname add realtime data to update builder succeed! pointname: {0} seconds: {1}, status: {2}, value: {3}", pointname, memSampleRecord.nSecond, memSampleRecord.nQuality, memSampleRecord.fFloat32);
break;
case (byte)DATA_TYPE.TAG_TYPE_DIGITAL:
Console.WriteLine("Using pointname add realtime data to update builder succeed! pointname: {0} seconds: {1}, status: {2}, value: {3}", pointname, memSampleRecord.nSecond, memSampleRecord.nQuality, memSampleRecord.nDigital);
break;
case (byte)DATA_TYPE.TAG_TYPE_UINT8:
Console.WriteLine("Using pointname add realtime data to update builder succeed! pointname: {0} seconds: {1}, status: {2}, value: {3}", pointname, memSampleRecord.nSecond, memSampleRecord.nQuality, memSampleRecord.nUInt8);
break;
case (byte)DATA_TYPE.TAG_TYPE_INT8:
Console.WriteLine("Using pointname add realtime data to update builder succeed! pointname: {0} seconds: {1}, status: {2}, value: {3}", pointname, memSampleRecord.nSecond, memSampleRecord.nQuality, memSampleRecord.nInt8);
break;
case (byte)DATA_TYPE.TAG_TYPE_UINT16:
Console.WriteLine("Using pointname add realtime data to update builder succeed! pointname: {0} seconds: {1}, status: {2}, value: {3}", pointname, memSampleRecord.nSecond, memSampleRecord.nQuality, memSampleRecord.nUInt16);
break;
case (byte)DATA_TYPE.TAG_TYPE_INT16:
Console.WriteLine("Using pointname add realtime data to update builder succeed! pointname: {0} seconds: {1}, status: {2}, value: {3}", pointname, memSampleRecord.nSecond, memSampleRecord.nQuality, memSampleRecord.nInt16);
break;
case (byte)DATA_TYPE.TAG_TYPE_UINT32:
Console.WriteLine("Using pointname add realtime data to update builder succeed! pointname: {0} seconds: {1}, status: {2}, value: {3}", pointname, memSampleRecord.nSecond, memSampleRecord.nQuality, memSampleRecord.nUInt32);
break;
case (byte)DATA_TYPE.TAG_TYPE_INT32:
Console.WriteLine("Using pointname add realtime data to update builder succeed! pointname: {0} seconds: {1}, status: {2}, value: {3}", pointname, memSampleRecord.nSecond, memSampleRecord.nQuality, memSampleRecord.nInt32);
break;
case (byte)DATA_TYPE.TAG_TYPE_UINT64:
Console.WriteLine("Using pointname add realtime data to update builder succeed! pointname: {0} seconds: {1}, status: {2}, value: {3}", pointname, memSampleRecord.nSecond, memSampleRecord.nQuality, memSampleRecord.nUInt64);
break;
case (byte)DATA_TYPE.TAG_TYPE_INT64:
Console.WriteLine("Using pointname add realtime data to update builder succeed! pointname: {0} seconds: {1}, status: {2}, value: {3}", pointname, memSampleRecord.nSecond, memSampleRecord.nQuality, memSampleRecord.nInt64);
break;
case (byte)DATA_TYPE.TAG_TYPE_FLOAT64:
Console.WriteLine("Using pointname add realtime data to update builder succeed! pointname: {0} seconds: {1}, status: {2}, value: {3}", pointname, memSampleRecord.nSecond, memSampleRecord.nQuality, memSampleRecord.fFloat64);
break;
}
}
/* 将容器中的数据提交到实时数据库里 */
res = ProcessDBDao.getInstance().exec_update_realtime();
if (0 != res)
{
Console.WriteLine("execute update realtime failed!error code: {0}", res);
return res;
}
else {
Console.WriteLine("execute update realtime succeed!");
}
return 0;
}
public int RealTimeTest() {
int res = 0;
/* 初始化连接控制块 */
res = ProcessDBDao.getInstance().init();
if (0 != res)
{
Console.WriteLine("ProcessDBDao init failed! error code: {0}", res);
return res;
}
/* 建立连接 */
res = ProcessDBDao.getInstance().connect("127.0.0.1", 8301, "root", "root");
//res = ProcessDBDao.getInstance().connect("192.168.0.186", 8301, "root", "root");
if (0 != res)
{
Console.WriteLine("login failed! error code: {0}", res);
return res;
}
/* 采样点 */
var pointlist = new List<pointlist>
{
new pointlist{ pointname = "D99.T99.P99", pointid = 1003000009, datatype = DATA_TYPE.TAG_TYPE_FLOAT32},
};
/* 通过点名更新实时数据、查询实时数据*/
for (int i = 0; i < pointlist.Count; i++)
{
/* 根据点名更新实时数据 */
add_realtime_data_by_name(pointlist[i].pointname, pointlist[i].datatype);
}
/* 关闭连接 */
res = ProcessDBDao.getInstance().close();
return res;
}
}
}
三、根据点ID插入实时数据
ProcessDB支持根据点ID列表,批量插入实时数据
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProcessDB;
namespace Data_RealTime
{
class Program
{
static void Main(string[] args)
{
TestRealTime testRealTime = new TestRealTime();
int res = testRealTime.RealTimeTest();
}
}
public class TestRealTime
{
public class pointlist
{
public string pointname { get; set; }
public int pointid { get; set; }
public DATA_TYPE datatype { get; set; }
}
static int add_realtime_data_by_id(int pointid, DATA_TYPE datatype)
{
/* 根据点id添加实时数据到容器 */
int i = 1;
float val = i * 8.9f;
byte val1 = 1;
byte val2 = 3;
short val3 = 4;
int val4 = 5;
long val5 = 6;
float val6 = i * 6.4f;
MemSampleRecord memSampleRecord = new MemSampleRecord();
memSampleRecord.nTagType = (byte)datatype;
switch (memSampleRecord.nTagType)
{
case (byte)DATA_TYPE.TAG_TYPE_FLOAT32:
memSampleRecord.fFloat32 = val;
break;
case (byte)DATA_TYPE.TAG_TYPE_DIGITAL:
memSampleRecord.nDigital = val1;
break;
case (byte)DATA_TYPE.TAG_TYPE_UINT8:
memSampleRecord.nUInt8 = val2;
break;
case (byte)DATA_TYPE.TAG_TYPE_INT8:
memSampleRecord.nInt8 = val2;
break;
case (byte)DATA_TYPE.TAG_TYPE_UINT16:
memSampleRecord.nUInt16 = val3;
break;
case (byte)DATA_TYPE.TAG_TYPE_INT16:
memSampleRecord.nInt16 = val3;
break;
case (byte)DATA_TYPE.TAG_TYPE_UINT32:
memSampleRecord.nUInt32 = val4;
break;
case (byte)DATA_TYPE.TAG_TYPE_INT32:
memSampleRecord.nInt32 = val4;
break;
case (byte)DATA_TYPE.TAG_TYPE_UINT64:
memSampleRecord.nUInt64 = val5;
break;
case (byte)DATA_TYPE.TAG_TYPE_INT64:
memSampleRecord.nInt64 = val5;
break;
case (byte)DATA_TYPE.TAG_TYPE_FLOAT64:
memSampleRecord.fFloat64 = val6;
break;
}
int res = ProcessDBDao.getInstance().add_realtime_data_to_update_builder_by_id(pointid, ref memSampleRecord);
if (0 != res)
{
Console.WriteLine("add {0} realtime_data to builder by id failed!error code: {1}", pointid, res);
return res;
}
else
{
switch (memSampleRecord.nTagType)
{
case (byte)DATA_TYPE.TAG_TYPE_FLOAT32:
Console.WriteLine("Using pointid add realtime data to update builder succeed! pointid: {0} seconds: {1}, status: {2}, value: {3}", pointid, memSampleRecord.nSecond, memSampleRecord.nQuality, memSampleRecord.fFloat32);
break;
case (byte)DATA_TYPE.TAG_TYPE_DIGITAL:
Console.WriteLine("Using pointid add realtime data to update builder succeed! pointid: {0} seconds: {1}, status: {2}, value: {3}", pointid, memSampleRecord.nSecond, memSampleRecord.nQuality, memSampleRecord.nDigital);
break;
case (byte)DATA_TYPE.TAG_TYPE_UINT8:
Console.WriteLine("Using pointid add realtime data to update builder succeed! pointid: {0} seconds: {1}, status: {2}, value: {3}", pointid, memSampleRecord.nSecond, memSampleRecord.nQuality, memSampleRecord.nUInt8);
break;
case (byte)DATA_TYPE.TAG_TYPE_INT8:
Console.WriteLine("Using pointid add realtime data to update builder succeed! pointid: {0} seconds: {1}, status: {2}, value: {3}", pointid, memSampleRecord.nSecond, memSampleRecord.nQuality, memSampleRecord.nInt8);
break;
case (byte)DATA_TYPE.TAG_TYPE_UINT16:
Console.WriteLine("Using pointid add realtime data to update builder succeed! pointid: {0} seconds: {1}, status: {2}, value: {3}", pointid, memSampleRecord.nSecond, memSampleRecord.nQuality, memSampleRecord.nUInt16);
break;
case (byte)DATA_TYPE.TAG_TYPE_INT16:
Console.WriteLine("Using pointid add realtime data to update builder succeed! pointid: {0} seconds: {1}, status: {2}, value: {3}", pointid, memSampleRecord.nSecond, memSampleRecord.nQuality, memSampleRecord.nInt16);
break;
case (byte)DATA_TYPE.TAG_TYPE_UINT32:
Console.WriteLine("Using pointid add realtime data to update builder succeed! pointid: {0} seconds: {1}, status: {2}, value: {3}", pointid, memSampleRecord.nSecond, memSampleRecord.nQuality, memSampleRecord.nUInt32);
break;
case (byte)DATA_TYPE.TAG_TYPE_INT32:
Console.WriteLine("Using pointid add realtime data to update builder succeed! pointid: {0} seconds: {1}, status: {2}, value: {3}", pointid, memSampleRecord.nSecond, memSampleRecord.nQuality, memSampleRecord.nInt32);
break;
case (byte)DATA_TYPE.TAG_TYPE_UINT64:
Console.WriteLine("Using pointid add realtime data to update builder succeed! pointid: {0} seconds: {1}, status: {2}, value: {3}", pointid, memSampleRecord.nSecond, memSampleRecord.nQuality, memSampleRecord.nUInt64);
break;
case (byte)DATA_TYPE.TAG_TYPE_INT64:
Console.WriteLine("Using pointid add realtime data to update builder succeed! pointid: {0} seconds: {1}, status: {2}, value: {3}", pointid, memSampleRecord.nSecond, memSampleRecord.nQuality, memSampleRecord.nInt64);
break;
case (byte)DATA_TYPE.TAG_TYPE_FLOAT64:
Console.WriteLine("Using pointid add realtime data to update builder succeed! pointid: {0} seconds: {1}, status: {2}, value: {3}", pointid, memSampleRecord.nSecond, memSampleRecord.nQuality, memSampleRecord.fFloat64);
break;
}
}
/* 将容器中的数据提交到实时数据库里 */
res = ProcessDBDao.getInstance().exec_update_realtime();
if (0 != res)
{
Console.WriteLine("execute update realtime failed!error code: {0}", res);
return res;
}
else {
Console.WriteLine("execute update realtime succeed!");
}
return 0;
}
public int RealTimeTest() {
int res = 0;
/* 初始化连接控制块 */
res = ProcessDBDao.getInstance().init();
if (0 != res)
{
Console.WriteLine("ProcessDBDao init failed! error code: {0}", res);
return res;
}
/* 建立连接 */
res = ProcessDBDao.getInstance().connect("127.0.0.1", 8301, "root", "root");
if (0 != res)
{
Console.WriteLine("login failed! error code: {0}", res);
return res;
}
/* 采样点 */
var pointlist = new List<pointlist>
{
new pointlist{ pointname = "D99.T99.P99", pointid = 1003000009, datatype = DATA_TYPE.TAG_TYPE_FLOAT32}
};
/* 通过点id更新实时数据*/
for (int j = 0; j < pointlist.Count; j++)
{
/* 根据点id更新实时数据 */
add_realtime_data_by_id(pointlist[j].pointid, pointlist[j].datatype);
}
/* 关闭连接 */
res = ProcessDBDao.getInstance().close();
return res;
}
}
}
四、根据点名查询实时数据
根据数据点名的集合,批量查询实时数据
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProcessDB;
namespace Data_RealTime
{
class Program
{
static void Main(string[] args)
{
TestRealTime testRealTime = new TestRealTime();
int res = testRealTime.RealTimeTest();
}
}
public class TestRealTime
{
public class pointlist
{
public string pointname { get; set; }
public int pointid { get; set; }
public DATA_TYPE datatype { get; set; }
}
static void get_realtime_data_by_name(string pointname)
{
int res = ProcessDBDao.getInstance().add_name_to_query_builder(pointname);
ProcessDBDao.getInstance().exec_query_realtime();
/* 根据点名查出实时数据 */
MemSampleRecord memSampleRecord = new MemSampleRecord();
res = ProcessDBDao.getInstance().get_realtime_data_by_name(pointname, ref memSampleRecord);
if (0 != res)
{
Console.WriteLine("Using pointName get realTime-data failed! pointname : {0}, error code: {1}", pointname, res);
return;
}
else
{
switch (memSampleRecord.nTagType)
{
case (byte)DATA_TYPE.TAG_TYPE_FLOAT32:
Console.WriteLine("Using pointName get realTime-data succeed!,pointname: {0}, value: {1}, status: {2}", pointname, memSampleRecord.fFloat32, memSampleRecord.nQuality);
break;
case (byte)DATA_TYPE.TAG_TYPE_DIGITAL:
Console.WriteLine("Using pointName get realTime-data succeed!,pointname: {0}, value: {1}, status:{2}", pointname, memSampleRecord.nDigital, memSampleRecord.nQuality);
break;
case (byte)DATA_TYPE.TAG_TYPE_UINT8:
Console.WriteLine("Using pointName get realTime-data succeed!,pointname: {0}, value:{1}, status:{2}", pointname, memSampleRecord.nUInt8, memSampleRecord.nQuality);
break;
case (byte)DATA_TYPE.TAG_TYPE_INT8:
Console.WriteLine("Using pointName get realTime-data succeed!,pointname: {0}, value:{1}, status:{2}", pointname, memSampleRecord.nInt8, memSampleRecord.nQuality);
break;
case (byte)DATA_TYPE.TAG_TYPE_UINT16:
Console.WriteLine("Using pointName get realTime-data succeed!,pointname: {0}, value:{1}, status:{2}", pointname, memSampleRecord.nUInt16, memSampleRecord.nQuality);
break;
case (byte)DATA_TYPE.TAG_TYPE_INT16:
Console.WriteLine("Using pointName get realTime-data succeed!,pointname: {0}, value:{1}, status:{2}", pointname, memSampleRecord.nInt16, memSampleRecord.nQuality);
break;
case (byte)DATA_TYPE.TAG_TYPE_UINT32:
Console.WriteLine("Using use pointName get realTime-data succeed!,pointname: {0}, value:{1}, status:{2}", pointname, memSampleRecord.nUInt32, memSampleRecord.nQuality);
break;
case (byte)DATA_TYPE.TAG_TYPE_INT32:
Console.WriteLine("Using use pointName get realTime-data succeed!,pointname: {0}, value:{1}, status:{2}", pointname, memSampleRecord.nInt32, memSampleRecord.nQuality);
break;
case (byte)DATA_TYPE.TAG_TYPE_UINT64:
Console.WriteLine("Using use pointName get realTime-data succeed!,pointname: {0}, value:{1}, status:{2}", pointname, memSampleRecord.nUInt64, memSampleRecord.nQuality);
break;
case (byte)DATA_TYPE.TAG_TYPE_INT64:
Console.WriteLine("Using use pointName get realTime-data succeed!,pointname: {0}, value:{1}, status:{2}", pointname, memSampleRecord.nInt64, memSampleRecord.nQuality);
break;
case (byte)DATA_TYPE.TAG_TYPE_FLOAT64:
Console.WriteLine("Using use pointName get realTime-data succeed!,pointname: {0}, value:{1}, status:{2}", pointname, memSampleRecord.fFloat64, memSampleRecord.nQuality);
break;
}
}
}
public int RealTimeTest() {
int res = 0;
/* 初始化连接控制块 */
res = ProcessDBDao.getInstance().init();
if (0 != res)
{
Console.WriteLine("ProcessDBDao init failed! error code: {0}", res);
return res;
}
/* 建立连接 */
res = ProcessDBDao.getInstance().connect("127.0.0.1", 8301, "root", "root");
//res = ProcessDBDao.getInstance().connect("192.168.0.186", 8301, "root", "root");
if (0 != res)
{
Console.WriteLine("login failed! error code: {0}", res);
return res;
}
/* 采样点 */
var pointlist = new List<pointlist>
{
new pointlist{ pointname = "D99.T99.P99", pointid = 1003000009, datatype = DATA_TYPE.TAG_TYPE_FLOAT32} ,
new pointlist{ pointname = "D99.T99.P98", pointid = 1003000010, datatype = DATA_TYPE.TAG_TYPE_FLOAT32}
};
/* 通过点名查询实时数据*/
for (int i = 0; i < pointlist.Count; i++)
{
/* 根据点名查询实时数据 */
get_realtime_data_by_name(pointlist[i].pointname);
}
/* 关闭连接 */
res = ProcessDBDao.getInstance().close();
return res;
}
}
}
示例运行结果:
Using pointName get realTime-data succeed!,pointname: D99.T99.P99, value: 8.9, status: 0
Using pointName get realTime-data succeed!,pointname: D99.T99.P98, value: 999, status: 0
五、根据点ID查询实时数据
根据数据点ID的集合,批量查询实时数据
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProcessDB;
namespace Data_RealTime
{
class Program
{
static void Main(string[] args)
{
TestRealTime testRealTime = new TestRealTime();
int res = testRealTime.RealTimeTest();
}
}
public class TestRealTime
{
public class pointlist
{
public string pointname { get; set; }
public int pointid { get; set; }
public DATA_TYPE datatype { get; set; }
}
static void get_realtime_data_by_id(int pointid)
{
int res = ProcessDBDao.getInstance().add_id_to_query_builder(pointid);
ProcessDBDao.getInstance().exec_query_realtime();
/* 根据点id查出实时数据 */
MemSampleRecord memSampleRecord = new MemSampleRecord();
res = ProcessDBDao.getInstance().get_realtime_data_by_id(pointid, ref memSampleRecord);
if (0 != res)
{
Console.WriteLine("Using pointID get realTime-data failed! pointid : {0}, error code : {1}", pointid, res);
return;
}
else
{
switch (memSampleRecord.nTagType)
{
case (byte)DATA_TYPE.TAG_TYPE_FLOAT32:
Console.WriteLine("Using pointID get realTime-data succeed! pointid:{0}, value:{1}, status:{2}", pointid, memSampleRecord.fFloat32, memSampleRecord.nQuality);
break;
case (byte)DATA_TYPE.TAG_TYPE_DIGITAL:
Console.WriteLine("Using pointID get realTime-data succeed! pointid:{0}, value:{1}, status:{2}", pointid, memSampleRecord.nDigital, memSampleRecord.nQuality);
break;
case (byte)DATA_TYPE.TAG_TYPE_UINT8:
Console.WriteLine("Using pointID get realTime-data succeed! pointid:{0}, value:{1}, status:{2}", pointid, memSampleRecord.nUInt8, memSampleRecord.nQuality);
break;
case (byte)DATA_TYPE.TAG_TYPE_INT8:
Console.WriteLine("Using pointID get realTime-data succeed! pointid:{0}, value:{1}, status:{2}", pointid, memSampleRecord.nInt8, memSampleRecord.nQuality);
break;
case (byte)DATA_TYPE.TAG_TYPE_UINT16:
Console.WriteLine("Using pointID get realTime-data succeed! pointid:{0}, value:{1}, status:{2}", pointid, memSampleRecord.nUInt16, memSampleRecord.nQuality);
break;
case (byte)DATA_TYPE.TAG_TYPE_INT16:
Console.WriteLine("Using pointID get realTime-data succeed! pointid:{0}, value:{1}, status:{2}", pointid, memSampleRecord.nInt16, memSampleRecord.nQuality);
break;
case (byte)DATA_TYPE.TAG_TYPE_UINT32:
Console.WriteLine("Using pointID get realTime-data succeed! pointid:{0}, value:{1}, status:{2}", pointid, memSampleRecord.nUInt32, memSampleRecord.nQuality);
break;
case (byte)DATA_TYPE.TAG_TYPE_INT32:
Console.WriteLine("Using pointID get realTime-data succeed! pointid:{0}, value:{1}, status:{2}", pointid, memSampleRecord.nInt32, memSampleRecord.nQuality);
break;
case (byte)DATA_TYPE.TAG_TYPE_UINT64:
Console.WriteLine("Using pointID get realTime-data succeed! pointid:{0}, value:{1}, status:{2}", pointid, memSampleRecord.nUInt64, memSampleRecord.nQuality);
break;
case (byte)DATA_TYPE.TAG_TYPE_INT64:
Console.WriteLine("Using pointID get realTime-data succeed! pointid:{0}, value:{1}, status:{2}", pointid, memSampleRecord.nInt64, memSampleRecord.nQuality);
break;
case (byte)DATA_TYPE.TAG_TYPE_FLOAT64:
Console.WriteLine("Using pointID get realTime-data succeed! pointid:{0}, value:{1}, status:{2}", pointid, memSampleRecord.fFloat64, memSampleRecord.nQuality);
break;
}
}
}
public int RealTimeTest() {
int res = 0;
/* 初始化连接控制块 */
res = ProcessDBDao.getInstance().init();
if (0 != res)
{
Console.WriteLine("ProcessDBDao init failed! error code: {0}", res);
return res;
}
/* 建立连接 */
res = ProcessDBDao.getInstance().connect("127.0.0.1", 8301, "root", "root");
//res = ProcessDBDao.getInstance().connect("192.168.0.186", 8301, "root", "root");
if (0 != res)
{
Console.WriteLine("login failed! error code: {0}", res);
return res;
}
/*数据点 */
var pointlist = new List<pointlist>
{
new pointlist{ pointname = "D99.T99.P99", pointid = 1003000009, datatype = DATA_TYPE.TAG_TYPE_FLOAT32} ,
new pointlist{ pointname = "D99.T99.P98", pointid = 1003000010, datatype = DATA_TYPE.TAG_TYPE_FLOAT32}
};
/* 通过点id查询实时数据*/
for (int j = 0; j < pointlist.Count; j++)
{
/* 根据点id获取实时数据 */
get_realtime_data_by_id(pointlist[j].pointid);
}
/* 关闭连接 */
res = ProcessDBDao.getInstance().close();
return res;
}
}
}
示例运行结果:
Using pointID get realTime-data succeed! pointid:1003000009, value:8.9, status:0
Using pointID get realTime-data succeed! pointid:1003000010, value:999, status:0