1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- import json
- class modelOpcConf:
- # OPC服务地址
- opc_server_url = None
- # 矿名id
- sys_key = None
- # 系统名
- sys_name = None
- # 接口配置文件名
- file_name = None
- # 接口配置路径
- path = None
- # 点位数组路径
- # point_arr_path = None
- class modelBaseConf:
- server_port = None
- def get_conf(file_name="config.json", file_path="./config"):
- path = f"{file_path}/{file_name}"
- try:
- with open(path, "r", encoding="utf-8") as f:
- content = json.load(f)
- f.close()
- return content
- except BaseException as e:
- print(e)
- print(f"异常,配置文件读取错误!path:{path}")
- def get_base_conf():
- model = modelBaseConf()
- base_conf = get_conf()
- model.server_port = base_conf['server_port']
- return model
- def get_opc_sys_conf(sys_key, sys_name):
- base_conf = get_conf()
- conf_dict = base_conf['sys_conf'][sys_key][sys_name]
- # 创建model
- model = modelOpcConf()
- # model赋值
- model.opc_server_url = conf_dict['opc_server_url']
- model.sys_key = conf_dict['sys_key']
- model.sys_name = conf_dict['sys_name']
- model.file_name = conf_dict['file_name']
- model.path = conf_dict['path']
- return model
- def get_opc_point_json_conf(sys_key, sys_name):
- config = get_opc_sys_conf(sys_key, sys_name)
- # 获取opc服务地址
- sys_file_path = config.path
- sys_file_name = config.file_name
- point_conf = get_conf(sys_file_name, sys_file_path)
- return point_conf
- def get_opc_point_arr_conf(sys_key, sys_name):
- config = get_opc_sys_conf(sys_key, sys_name)
- # 获取opc服务地址
- arr_file_path = f"{config.path}/array"
- arr_file_name = f"{config.sys_key}_arr.json"
- point_conf_arr = get_conf(arr_file_name, arr_file_path)
- return point_conf_arr
- if __name__ == "__main__":
- sys_key = 'jinjiaqu'
- sys_name = 'support'
- point_arr = get_opc_point_arr_conf(sys_key, sys_name)
|