location.py
2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
'''
@ 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