location.py 2.4 KB
'''
@ author: jie
@ tools: pycharm 
@ content: 库位操作类
@ date: 2021.6.02
'''
import logging
import os
import csv
from config import Config

class Location():
    def __init__(self):
        # self.basepath = os.path.dirname(__file__)
        self.uploads_path = Config.UPLOAD_FOLDER

    def read_location_file(self):
        config_dict = {}
        convert_dict = {}
        try:
            with open(self.uploads_path +'/linePositions.csv', 'r',encoding='gbk') as f:
                reader = csv.reader(f)
                head = next(reader)
                # lines = f.readlines()[1:]
                for row in reader:
                    row[1]=row[1].replace('B','A1')
                    config_dict[row[0]] = row[2]+'@'+row[1]+'@'+row[3]
                    convert_dict[row[3]+'@'+row[1]] = row[2]+'@'+row[1]+'@'+row[0]
                    # led_addr_dict[row[2]+'@'+row[1]] = row[0]+'@'+row[3]
                    # option_list.append(row[0])
            # logging.warning("配置文件加载成功...")
        except Exception as e:
            print (e)
            # logging.warning("配置文件加载失败,请上传配置文件")
        return config_dict,convert_dict

    def init_location_option(self):
        config_location,covert = self.read_location_file()
        option_list = list(config_location.keys())
        return option_list

    def production_location_init(self):
        locations = {}
        print (locations)
        config_location,convert_dict = self.read_location_file()
        print (config_location)
        print (convert_dict)
        # 从配置表获取库位,初始化库位
        for loc,values in config_location.items():
            c_value = {
                        'addr':values.split('@')[1],
                        'led_index':int(values.split('@')[0]),
                        'sensor_index':int(values.split('@')[2]),
                        'in_blink':False,
                        'out_blink':False,
                        # 'loc_inlocation':False,
                        'inloc_ng':False,
                        'outloc_ng':False,
                        'color':'off',
                        # 'guide_locin':False,
                        'blink':False,
                        'blink_num':0,
                        'action':False
                        }
            locations[loc] = c_value
        return locations