I think I found my problem.
Problem
def waitForFracWell(timeout=2.0, interval=0.05):
start = time.time()
while time.time() - start < timeout:
wellNum = getFracWell(12)
if wellNum != 0:
return wellNum
time.sleep(interval)
return 0
def getFracWell(numWells):
#print("numWells passed in: ", numWells)
base = "[IPC Demo]Pad/Well"
placeFrac = "/HMI/Modes/Frac"
removeFrac = "/HMI/Modes/Remove Frac"
balldrop = "/HMI/Modes/Balldrop Frac"
paths = []
for x in range(numWells):
i = x + 1
paths.append(base + str(i) + placeFrac)
paths.append(base + str(i) + removeFrac)
paths.append(base + str(i) + balldrop)
results = system.tag.readBlocking(paths)
for x in range(numWells):
placeVal = results[x*3].value
removeVal = results[x*3 + 1].value
balldropVal= results[x*3 + 2].value
if placeVal or removeVal or balldropVal:
return x + 1
return 0
I'm wondering if these readBlocking are suspending processing for too long.
I tried to do the following, but tag.readAsync doesn't allow passing in parameters
Doesn't work
def onTagChange(initialChange, newValue, previousValue, event, executionCount):
if (
not initialChange
and newValue is not None
and newValue.value != previousValue.value
#and executionCount % 2 == 0 #filters out odd repeating onTagChange
):
value = newValue.value
tagPathStr = str(event.tagPath)
tagName = tagPathStr.split("/")[-1]
#print("New Value: ", newValue.value)
#print("tagPath: ", tagPathStr)
#test = system.tag.readBlocking(["[.]Zipper Entries/Frac Pin"], 1000)
if isinstance(value, bool) and tagName.endswith("Pin Ok"):
general.PinChange(tagName)
# in Project Library "general"
def PinChange(tagName):
getFracWell(12, tagName)
def getFracWell(numWells, tagName):
base = "[IPC Demo]Pad/Well"
placeFrac = "/HMI/Modes/Frac"
removeFrac = "/HMI/Modes/Remove Frac"
balldrop = "/HMI/Modes/Balldrop Frac"
paths = []
for x in range(numWells):
i = x + 1
paths.append(base + str(i) + placeFrac)
paths.append(base + str(i) + removeFrac)
paths.append(base + str(i) + balldrop)
system.tag.readAsync(paths, _callback(tagName, numWells))
def _callback(results, tagName, numWells):
for x in range(numWells):
placeVal = results[x*3].value
removeVal = results[x*3 + 1].value
balldropVal= results[x*3 + 2].value
if placeVal or removeVal or balldropVal:
_pinChange(x + 1, tagName)
def _pinChange(wellNum, tagName):
if wellNum and wellNum != 0:
wellNameTag = "[IPC Demo]Pad/Well" + str(wellNum) + "/Last Known Name"
wellName = system.tag.readBlocking([wellNameTag])[0].value
action = ""
pin = 0
FracName = ""
VtName = ""
WlName = ""
WsmName = ""
prefix = tagName.replace(" Pin Ok", "")
if (prefix == "Frac"):
action = "Frac pin entered"
pin = system.tag.readBlocking(["[IPC Demo]Zipper Pins/Frac Pin"])[0].value
if pin != 0:
FracName = findUserName(pin, "FRAC")
#print(pin)
elif (prefix == "VT"):
action = "Valvetech pin entered"
pin = system.tag.readBlocking(["[IPC Demo]Zipper Pins/VT Pin"])[0].value
if pin != 0:
VtName = findUserName(pin, "VT")
elif (prefix == "Wline"):
action = "Wireline pin entered"
pin = system.tag.readBlocking(["[IPC Demo]Zipper Pins/Wline Pin"])[0].value
if pin != 0:
WlName = findUserName(pin, "WIRELINE")
elif (prefix == "WSM"):
action = "WSM pin entered"
pin = system.tag.readBlocking(["[IPC Demo]Zipper Pins/WSM Pin"])[0].value
if pin != 0:
WsmName = findUserName(pin, "WSM")
else:
print("Zipper Pin tag change didn't find any Pin Ok")
if pin != 0:
namedQuery = "Insert User Action"
queryParams = {"wellNum": wellNum, "wellName": wellName, "action": action, "pin": pin, "frac": FracName, "wsm": WsmName, "wl": WlName, "vt": VtName, "wellPressure": "", "fracPressure": ""}
system.db.execUpdate(namedQuery, queryParams)