示例代码:
var processdb = require("processDB");
processdb.connect(8301, 'localhost');
processdb.login('root', 'root',function(result_code){
if(result_code !== 0){
console.log('login failed. error_code: ', result_code);
return;
}
var pointNameList= ['PUBLIC.SYS.PDB_OS_CPU_USAGE', 'PUBLIC.SAMPLE.SAMPLE_DIGITAL', 'PUBLIC.SAMPLE.SAMPLE_BOOL', 'PUBLIC.SAMPLE.SAMPLE_UINT8',
'PUBLIC.SAMPLE.SAMPLE_INT8', 'PUBLIC.SAMPLE.SAMPLE_UINT16', 'PUBLIC.SAMPLE.SAMPLE_INT16', 'PUBLIC.SAMPLE.SAMPLE_UINT32','PUBLIC.SAMPLE.SAMPLE_INT32',
'PUBLIC.SAMPLE.SAMPLE_UINT64', 'PUBLIC.SAMPLE.SAMPLE_INT64','PUBLIC.SAMPLE.SAMPLE_FLOAT64','PUBLIC.SAMPLE.SAMPLE_TIME'];
//请求查询实时数据(点名)
processdb.request_realtime_data_by_name(pointNameList, function(result_code, count){
if(result_code !== 0)
{
console.log('request_realtime_data_by_name failed. error_code: ', result_code);
return;
}
//获取点的实时数据
for(var i = 0; i < count; i++)
{
var realtime_data = processdb.get_realtime_data(i);
console.log('pointId: ' + realtime_data.pointId + ', nSecond: ' + realtime_data.nSecond + ', nMilliSecond: ' + realtime_data.nMilliSecond + ', nQuality: ' + realtime_data.nQuality + ', nTagType: ' + realtime_data.nTagType + ', realtime_value: ' + realtime_data.realtime_value);
}
});
//请求查询实时数据(点id)
var pointIdList = ['1001000100', '1001000101','1001000102', '1001000103', '1001000104', '1001000105', '1001000106', '1001000107', '1001000108', '1001000109','1001000110', '1001000111','1001000112'];
processdb.request_realtime_data_by_id(pointIdList, function(result_code, count){
if(result_code !== 0)
{
console.log('request_realtime_data_by_id failed. error_code: ', result_code);
return;
}
//获取点的实时数据
for(var k = 0; k < count; k++)
{
var realtime_data = processdb.get_realtime_data(k);
if(Object.keys(realtime_data).length === 0)
{
console.log('No realtime data.');
return;
}
console.log('pointId: ' + realtime_data.pointId + ', nSecond: ' + realtime_data.nSecond + ', nMilliSecond: ' + realtime_data.nMilliSecond + ', nQuality: ' + realtime_data.nQuality + ', nTagType: ' + realtime_data.nTagType + ', realtime_value: ' + realtime_data.realtime_value);
}
});
//插入实时数据(点id)
var nSecond = 100;
var nMilliSecond = 1000;
var nQuality = 0;
pointIdList = [['1002000002', 0, 0], ['1002000003', 1, 1], ['1002000004', 2, 2], ['1002000005', 3, 3], ['1002000006', 4, 4], ['1002000007', 5, 5],
['1002000008', 6, 6], ['1002000009', 7, 7], ['1002000010', 8, 8], ['1002000011', 9, 9], ['1002000012', 10, 10], ['1002000013', 11, 11], ['1002000014', 12, 12]];
processdb.cmd_insert_realtime_data_by_id(pointIdList, nSecond, nMilliSecond, nQuality, function(result_code){
if(result_code !== 0)
{
console.log('cmd_insert_realtime_data_by_id failed. error_code: ', result_code);
return;
}
console.log('insert realtime data succeed.');
return;
});
});