def __init__(self, path: str): self.log = [] self.single_log = {'log_name': '', 'detail': []} self.config = load_config(path) self.fields = self.config['log']['fields'] self.__fix = 2592000 # 1*30*24*60*60 one month self.valid_time = self.config['log']['valid_time'] * self.__fix
def __init__(self, path: str): self.config = load_config(path)['client'] self.username = self.config['username'] self.password = self.config['password'] self.topic_prefix = self.config['topic_prefix'] self.ipaddr = self.config['ipaddr'] self.port = self.config['port'] self.keep_alive = self.config['keepalive'] self.client = mqtt.Client()
def setup_logging(default_path="log_config.yaml", default_level=logging.INFO, env_key="LOG_CFG"): path = default_path value = os.getenv(env_key, None) if value: path = value config = load_config(path) if config: logging.config.dictConfig(config) else: logging.basicConfig(level=default_level)
def __init__(self, task_id, file_config_path, mqtt_config_path): # 发送mqtt消息 self.mqtt_cfg = load_config(mqtt_config_path) # 根据task id进行初始化 if task_id == 0: # 读取log file self.log_file = Logfile(file_config_path) self.equipment_id = self.mqtt_cfg['equipment']['hlh']['id'] elif task_id == 1: self.log_file = PrinterLog(file_config_path) self.equipment_id = self.mqtt_cfg['equipment']['printer']['id'] self.payload = { 'log': [], 'image': {} }
def __init__(self, path: str): self.config = load_config(path)['ocr_config'] self.num_config = self.config['num_config'] self.chi_sim_config = self.config['chi_sim_config'] self.boxes = [] self.__get_boxes() self.image = None self.parameters = [] self.parameters_dict = { '生产模式': '', 'PCB长度': '', 'PCB宽度': '', 'PCB厚度': '', '运输速度': '', '印刷速度': '', '运动状态': '', '印刷长度': '', '印刷起点': '', '脱模长度': '', '后刮刀压力': '', '前刮刀压力': '', '脱模方式': '', '印刷方式': '', '平台X轴': '', '平台Y1轴': '', '平台Y2轴': '', '平台Z轴': '', 'CCD X轴': '', 'CCD Y轴': '', '清洗': '', '刮刀': '', '取像方式': '', '清洗次数': '', '清洗纸': '', '脱模速度': '', '清洗速度': '', '清洗间隔': '', '清洗液': '', '空气压力': '', '下轮清洗': '', '生产周期': '', '产量': '', # '刮刀片使用次数1': '', # '刮刀片使用次数2': '' }
def __init__(self, task_id, file_config_path, mqtt_config_path): # 发送mqtt消息 self.client = MQTTClient(mqtt_config_path) self.mqtt_cfg = load_config(mqtt_config_path) # 根据task id进行初始化 if task_id == 0: # 读取log file self.log_file = Logfile(file_config_path) # 识别屏幕参数 self.param = HLHOCR(file_config_path) self.equipment_id = self.mqtt_cfg['equipment']['hlh']['id'] elif task_id == 1: self.log_file = PrinterLog(file_config_path) self.param = PrinterOCR(file_config_path) self.equipment_id = self.mqtt_cfg['equipment']['printer']['id'] self.client.setup() self.payload = {'log': [], 'dynamic_param': {}}
def __init__(self, path: str): self.config = load_config(path)['parameter'] self._bg_color = tuple(self.config['bg_color']) self._border_color = tuple(self.config['border_color']) self._ocr_config = self.config['ocr_config'] # 4行8列的参数数组 self._row = 4 self._col = 8 # 下面是一些需要提取的参数 self.parameter = [[0 for i in range(self._col)] for j in range(self._row)] self.parameter_dict = tree() self.cool = [0, 0] self.cool_dict = {} self.pcb_statistic = [0, 0, 0] self.pcb_dict = {} self.trans_speed = [0.0, 0.0] self.trans_speed_dict = {} self.frequency = 0 self.frequency_dict = {} self.image = None
return "" if __name__ == '__main__': print('------program start------') cur_path = os.getcwd() hlh_config_path = "config/HLH_config.yaml" log_config_path = "config/log_config.yaml" mqtt_config_path = "config/mqtt_config.yaml" printer_config_path = "config/printer_config.yaml" hlh_path = os.path.join(cur_path, hlh_config_path) log_path = os.path.join(cur_path, log_config_path) mqtt_path = os.path.join(cur_path, mqtt_config_path) printer_path = os.path.join(cur_path, printer_config_path) # 配置logger setup_logging(log_path) logging.info('current directory: ' + cur_path) # 配置任务 mqtt_cfg = load_config(mqtt_path) logging.info('Loading Task Configuration:' + json.dumps(load_config(mqtt_path), indent=2)) client = MQTTClient(mqtt_config_path) client.setup() app.run(host='0.0.0.0', port=5000, debug=False)
import paho.mqtt.client as mqtt from Utils.config_util import load_config def on_connect(client, userdata, flags, rc): print("Connected with result code: " + str(rc)) def on_message(client, userdata, msg): print(msg.topic + " " + str(msg.payload)) config = load_config('../config/mqtt_config.yaml') client = mqtt.Client() client.on_connect = on_connect client.on_message = on_message client.username_pw_set('root', 'root1234') client.connect(config['client']['ipaddr'], 16885, 600) # 600为keepalive的时间间隔 client.subscribe('equipment/parameter/#', qos=0) client.loop_forever() # 保持连接