ProcessDB实时/时序数据库——JavaScript_API读写实时数据

示例代码:

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;
    });
});
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值