-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathopcTest.py
More file actions
27 lines (21 loc) · 697 Bytes
/
opcTest.py
File metadata and controls
27 lines (21 loc) · 697 Bytes
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
import OpenOPC
import pywintypes
def readopc(tags):
pywintypes.datetime = pywintypes.TimeType
opc = OpenOPC.client()
opc.connect('Matrikon.OPC.Simulation.1')
try:
data = opc.read(tags, group='Group0', update=1)
except OpenOPC.TimeoutError:
print("TimeoutError occured")
return data
def writeToFile(path, data):
for (tagName, value, conf, timeStamp) in data:
fileName=path+tagName+'.csv'
line=str(value)+';'+str(conf)+';'+str(timeStamp)+'\n'
with open(fileName, "a") as f:
f.write(line)
if __name__=='__main__':
tags = ['Random.Int1','Random.Int4']
data = readopc(tags)
writeToFile('C:\\temp\\',data)