-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPI_dataEntry.py
More file actions
90 lines (67 loc) · 2.47 KB
/
Copy pathPI_dataEntry.py
File metadata and controls
90 lines (67 loc) · 2.47 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python
# coding: utf-8
# In[ ]:
# General Libraries
import sys
import clr
import pandas as pd
# Osisoft Libraries
sys.path.append("C:\\Program Files (x86)\\PIPC\\AF\\PublicAssemblies\\4.0\\")
clr.AddReference("OSIsoft.AFSDK")
from Osisoft.AF.PI import *
from Osisoft.AF.Asset import *
from Osisoft.AF.Data import *
# connecting on server
def connectToPIServer(piserver):
try:
global currentServer
servers = PIServers()
currentServer = servers[piserver]
# if it was ok, so return success to the user
print(f"It was connected to the server: {currentServer}")
except:
# if it wasn't ok, so return fail to the user
print(f"It wasn't possible to connect to the server: {currentServer}")
# Inserting a new value
def setValueOnTag(tag, value):
try:
# inserting in afValue the AFValue() class
afValue = AFValue()
# inserting the value on afValue.Value
afValue.Value = value
# trying to find the pi point on the current server
findPIPoint = PIPoint.FindPIPoint(currentServer, tag)
# updating the value on the tag
findPIPoint.UpdateValue(afValue, AFUpdateOption.Replace, AFBufferOption.BufferIfPossible)
# if it was ok, so return success to the user
print("Success")
except:
# if it wasn't ok, so return fail to the user
print("Failed")
# reading file where the tags are defined
file = pd.read_csv("file.csv", sep = ';')
# getting only the column where the tags are
mappedTags = file['column_tagname']
# connecting on server
connectToPIServer("server_name")
print("Start Message")
for tag in mappedTags:
try:
if currentServer == None:
print("This server doesn't exist, try to use another")
break
# phrase to context the user about the current tag
print("Insert the value on the tag: " + tag)
# getting input value
value = input("Insert a value: ")
if value != '':
# using this function to insert value on the tag
setValueOnTag(tag, float(value))
# if it was ok, so return success to the user
print("Success")
else:
# if it wasn't ok, so return fail to the user
print("Failed")
except:
# if it wasn't ok, so return fail to the user
print("Failed")