Ejemplo n.º 1
0
        def refresh_service_status(self):
            if not self._task.task_is_running():
                self._bindData = False
                self._task.set_status(0)
            else:
                _good_status = False
                _status_value = None

                if not self._bindService:
                    ret = dsif.bindService(self._ip, self._port, self._task.name, 'get_status')
                    if int(ret) == 1:
                        self._bindService = True
                        log.info('获取[%s]状态bind service成功' % self._task.name)
                    else:
                        self._bindService = False
                        log.error('获取[%s]状态bind service异常,原因:%s' % (self._task.name, ret))

                if not self._bindData:
                    # 状态数据对象
                    bindData = pb_data_sensor_list.pb_data_sensor_list()
                    bindData.list_id = 1
                    status_tag = bindData.pb_data_sensors.add()

                    status_tag.name = '%s_status' % self._task.name
                    log.debug('准备[%s]状态数据bind data...' % self._task.name)
                    try:
                        ret = dsif.bindData('get_status', 'pb_data_sensor_list', bindData, 'get_status_list')
                        if int(ret) == 1:
                            self._bindData = True
                            log.info('获取[%s]状态[bind data]成功' % self._task.name)
                        else:
                            self._bindData = False
                            log.error('获取[%s]状态[bind data]失败,原因:%s' % (self._task.name, ret))
                    except Exception as e:
                        self._bindData = False
                        log.error('获取[%s]状态[bind data]异常,原因:%s' % (self._task.name, repr(e)))                

                if self._bindData:
                    self._getData = pb_data_sensor_list.pb_data_sensor_list()
                    try:
                        log.debug('准备[%s]状态数据get data...' % self._task.name)
                        ret = dsif.getData('get_status', 'get_status_list', 'pb_data_sensor_list', self._getData)
                        if ret == 1 and len(self._getData.pb_data_sensors) > 0:
                            _status_value = int(self._getData.pb_data_sensors[0].value)
                            _good_status = True
                            log.debug('[%s]当前运行状态为:%s' % (self._task.name, _status_value))
                        else:
                            log.error('获取[%s]状态[get data]失败,原因:%s' % (self._task.name, ret))
                    except Exception as e:
                        log.error('获取[%s]get data异常,原因:%s' % (self._task.name, repr(e)))

                if _good_status:
                    self._task.set_status(_status_value)
                    self._task.update_status_time(int(time.time()))
                else:
                    self._bindData = False
                    self._task.set_status(0)
Ejemplo n.º 2
0
        def refresh_service_status(self):
            _good_status = False
            _status_value = None
            if not self._bindService:
                ret = dsif.bindService(self._task.ip, self._task.port,
                                       self._task.name, 'get_status')
                if int(ret) == 1:
                    self._bindService = True
                    log.info('获取[%s]状态bind service成功' % self._task.name)
                else:
                    self._bindService = False
                    log.error('获取[%s]状态bind service异常,原因:%s' %
                              (self._task.name, ret))

            if self._task.handle is not None:
                # 状态数据对象
                bindData = pb_data_sensor_list.pb_data_sensor_list()
                bindData.list_id = 1
                status_tag = bindData.pb_data_sensors.add()
                status_tag.name = '%s_status' % self._task.name
                try:
                    ret = dsif.bindData('get_status', 'pb_data_sensor_list',
                                        bindData, 'get_status_list')
                    if int(ret) == 1:
                        self._bindData = True
                        log.info('获取[%s]状态[bind data]成功' % self._task.name)
                    else:
                        self._bindData = False
                        log.error('获取[%s]状态[bind data]异常,原因:%s' %
                                  (self._task.name, ret))
                except Exception as e:
                    self._bindData = False
                    log.error('获取[%s]状态[bind data]异常,原因:%s' %
                              (self._task.name, repr(e)))

                self._getData = pb_data_sensor_list.pb_data_sensor_list()
                try:
                    ret = dsif.getData('get_status', 'get_status_list',
                                       'pb_data_sensor_list', self._getData)
                    if ret == 1 and len(self._getData.pb_data_sensors) > 0:
                        _status_value = int(
                            self._getData.pb_data_sensors[0].value)
                        _good_status = True
                        log.debug('[%s]当前运行状态为:%s' %
                                  (self._task.name, _status_value))
                except Exception as e:
                    log.error('获取[%s]get data异常,原因:%s' %
                              (self._task.name, repr(e)))

                if _good_status:
                    self._task.set_status(_status_value)
                    self._task.set_status_last_time(
                        common.get_current_timespan())
                else:
                    self._task.set_status(0)
Ejemplo n.º 3
0
def write_data(name, node_name, data_name, data_type, list_data):
    print('正在向数据节点[%s]中写入数据......' % node_name)
    # bind data
    is_write_ok = False
    for data in list_data:
        bind_ret = dsif.bindData(name, data_type, data, data_name)
        if eval(str(bind_ret)) == 1:
            set_ret = dsif.setData(name, data_name, data_type, data)
            if eval(str(set_ret)) == 1:
                print('数据节点[%s]写入数据[%s]成功.' % (node_name, data_type))
                is_write_ok = True
            else:
                print('数据节点[%s]写入数据[%s]失败(%s).' %
                      (node_name, data_type, set_ret))
        else:
            print('数据节点[%s]写入数据[%s]失败(%s).' % (node_name, data_type, bind_ret))

    return is_write_ok
Ejemplo n.º 4
0
#------------------------------------------------------------
ret = dsif.start('rtds', 'rtds_01')
print('start return:', ret)
print('%s start over %s' % ('-' * number, '-' * number))

#------------------------------------------------------------
bindData = pb_data_sensor_list.pb_data_sensor_list()
bindData.list_id = 1
sensor1 = bindData.pb_data_sensors.add()
sensor1.name = '10001'
sensor2 = bindData.pb_data_sensors.add()
sensor2.name = '10002'
# sensor3 = bindData.pb_data_sensors.add()
# sensor3.name = 'run_status_rtds_01'

ret = dsif.bindData('rtds', 'pb_data_sensor_list', bindData, 'get_sensor_01')
print('bindData return:', ret)
print('%s bindData over %s' % ('-' * number, '-' * number))

#------------------------------------------------------------
setData = pb_data_sensor_list.pb_data_sensor_list()

setData.list_id = 1
set_sensor1 = setData.pb_data_sensors.add()
set_sensor1.name = '10001'
set_sensor1.type = pb_config_tag.ENUM_INT32
set_sensor1.size = 4
set_sensor1.value = b'100'
set_sensor1.time = int(time.time())
set_sensor2 = setData.pb_data_sensors.add()
set_sensor2.name = '10002'
Ejemplo n.º 5
0
    pdo.source_name = 'source_name_%d' % count
    pdo.event_category_id = 123
    pdo.event_category_name = 'event_category_name_01'
    pdo.condition_name = 'condition_name_01'
    pdo.sub_condition_name = 'sub_condition_name_01'
    pdo.alarm_message = 'alarm_message_01'
    pdo.condition_quality = 'condition_quality_01'
    pdo.actor_id = 1234
    pdo.ack_Required = False
    pdo.change_mask = 1
    pdo.new_state = 1
    pdo.active_time = 123
    pdo.time = int(round(time.time()))
    pdo.bak_attribute = 'abc%d' % count
    count += 1
ret = dsif.bindData('s_mongodb_service', 'pb_data_opcalarm_list', pdol,
                    'get_config_opc_01')
print('bindData return:', ret)
print('%s bindData over %s' % ('-' * number, '-' * number))

#------------------------------------------------------------
ret = dsif.setData('s_mongodb_service', 'get_config_opc_01',
                   'pb_data_opcalarm_list', pdol)
print('setData return:', ret)
print('%s setData over %s' % ('-' * number, '-' * number))

#
# opcda = pb_config_opcda_client.pb_config_opcda_client()
# opcda.opcda_client_id = 123

# opcda.main_opc_server.opc_server_ip = '1'
# opcda.main_opc_server.opc_server_prgid = 'abcdefg'
Ejemplo n.º 6
0
ret = dsif.bindConfig('s_mongodb_service', 'pb_config_mongodb', config,
                      'config_name_01')
print('bindConfig return:', ret)
print('%s bindConfig over %s' % ('-' * number, '-' * number))

#------------------------------------------------------------
ret = dsif.start('s_mongodb_service', 'config_name_01')
print('start return:', ret)
print('%s start over %s' % ('-' * number, '-' * number))

#------------------------------------------------------------
import pb_data_mongodb
bindData = pb_data_mongodb.m_config()
bindData.config_key = 'config_opc_01'
bindData.config_value = b''
ret = dsif.bindData('s_mongodb_service', 'm_config', bindData,
                    'get_config_opc_01')
print('bindData return:', ret)
print('%s bindData over %s' % ('-' * number, '-' * number))

#------------------------------------------------------------
import pb_config_opcda_client
import pb_config_tag
import opcconfig_tool

opc_config_file = 'c:\\opc_tags.xlsx'
opcda = opcconfig_tool.get_opcda_config(opc_config_file)

data_value = opcda.SerializeToString()
data = pb_data_mongodb.m_config()
data.config_key = 'config_opc_01'
data.config_value = data_value