forked from faraquet/RSLogix5000-Tag-Generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRS5000AliasGenerator.py
63 lines (46 loc) · 2.25 KB
/
RS5000AliasGenerator.py
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
# -*- coding: cp1251 -*-
# Генерация алиасов для RSLogix по теглисту
# !!!!!!!!!!!!!!!!! обращайте внимание на то, какой разделитель строк стоит в региональных настройках !!!!!!!!!!!
XLS = r'..\taglist.xls' # путь к файлу тег-листа
CSV = r'PLC-Tagsakue.CSV' # путь к csv-файлу
import codecs
f = codecs.open(CSV, 'wt', 'cp1251')
separator = u';' # укажите разделитель строк (такой же, как и в региональных настройках)
template = u'''ALIAS;;%s;"%s";"";"%s";"(Constant := false, ExternalAccess := Read/Write)"''' # для алиасов
template = template.replace(';', separator)
header = '''remark;"CSV-Import-Export"
0.3
TYPE;SCOPE;NAME;DESCRIPTION;DATATYPE;SPECIFIER;ATTRIBUTES'''
header = header.replace(';', separator)
f.write(header + '\n')
import xlrd
rbook = xlrd.open_workbook(XLS, encoding_override='cp1251')
sheet_name = u'TAGS'
TYPES = {'AI':'_AI','DI':'_DI','DO':'_DO','AO':'PID','VALVE':'_VALVE','ENGINE':'_ENGINE'}
if not sheet_name in rbook.sheet_names():
print 'warning! file have not sheet', sheet_name
print 'Analysing sheet', sheet_name, '...\n',
sheet = rbook.sheet_by_name(sheet_name)
print header
for row in range(120, 293): #sheet.nrows
if sheet.cell(row, 3).value == '':
continue
tagname = sheet.cell(row, 2).value.strip()
tagtype = sheet.cell(row, 3).value.strip()
shassi = sheet.cell(row, 4).value
slot = sheet.cell(row, 5).value
point = sheet.cell(row, 6).value
if tagtype == u'AI':
alias = shassi + ':' + str(int(slot)) + ':I.Ch' + str(int(point)) + 'Data'
if tagtype == u'DI':
alias = shassi + ':' + str(int(slot)) + ':I.Data.' + str(int(point))
if tagtype == u'DO':
alias = shassi + ':' + str(int(slot)) + ':I.Data.' + str(int(point))
tagcomment = sheet.cell(row, 1).value.strip()
if tagtype not in TYPES:
continue
comment = repr(tagcomment)[2:-1].replace('\u', '$')
string = template % (tagname, comment, alias)
print string
f.write(string + '\n')
f.close()