agoslinski
Member
Hello
On my Citect SCADA server I have few python scripts that read and write data to Citect using CTAPI.
I have a problem that after some time(hour or two) SOME (not all)of my scripts are unable to write data to tags.
All my scripts use the same code for connecting to citect (code below).
Restarting Citect Client service helps for some time.
Hare are some errors from citect log files:
[ipc.log]
IPC: IPCSocketReceive (recv detected that the peer closed connection gracefully), error: 0xe9
CtApi Server: Win32CAPIWaitForCmd: IPCRead failed. 0x2736 (instance id = 11152)
[tracelog.dat]
Cannot perform TagReadProperty operation on Unresolved Tag=TAG_AiB_R_2_42_L2_18_Status_Bledu (this tag is working I don't know why it is unresolved)
Do You have any idea what could be the cause of ctapi not working after some time?
Best regards
On my Citect SCADA server I have few python scripts that read and write data to Citect using CTAPI.
I have a problem that after some time(hour or two) SOME (not all)of my scripts are unable to write data to tags.
All my scripts use the same code for connecting to citect (code below).
Restarting Citect Client service helps for some time.
Code:
from ctypes import *
import os
import sys
import servicemanager
import win32api
class CTAPI:
def __init__(self, dll_path):
os.chdir(dll_path)
self.CtApi = WinDLL("CtApi")
self.Ct_ipc = WinDLL("Ct_ipc")
self.CiDebugHelp = WinDLL("CiDebugHelp")
self.CtEng32 = WinDLL("CtEng32")
self.CtRes32 = WinDLL("CtRes32")
self.CtUtil32 = WinDLL("CtUtil32")
self.hCTAPI = None
def ct_open(self, address, user_name, password):
if self.hCTAPI is not None:
servicemanager.LogInfoMsg("Already connected")
return
self.hCTAPI = windll.CtApi.ctOpen(address, user_name, password, 0)
if self.hCTAPI is None:
servicemanager.LogInfoMsg("Connection failed")
return
def ct_close(self):
windll.CtApi.ctClose(self.hCTAPI)
self.hCTAPI = None
def ct_tag_read(self, tag_name):
buffer = create_string_buffer('\000' * 32)
ok = windll.CtApi.ctTagRead(self.hCTAPI, tag_name, byref(buffer), sizeof(buffer))
if ok is False:
print("Unable to read TAG")
return
return buffer.value
def ct_tag_write(self, tag_name, value):
while self.write_lock is True:
pass
self.write_lock = True
ok = windll.CtApi.ctTagWrite(self.hCTAPI, tag_name, value)
if ok == 0:
e = win32api.GetLastError()
try:
f = hex(e)
f -= 0x10000000
g = int(f)
servicemanager.LogInfoMsg(
"Unable to write: " + tag_name + ": " + str(value) + " Error: " + str(g) + "(" + str(e) + ")")
print("Unable to write: " + tag_name + ": " + str(value) + " Error: " + str(g) + "(" + str(e) + ")")
except:
servicemanager.LogInfoMsg(
"Unable to write: " + tag_name + ": " + str(value) + " Error: " + str(e))
print("Unable to write: " + tag_name + ": " + str(value) + " Error: " + str(e))
self.write_lock = False
[ipc.log]
IPC: IPCSocketReceive (recv detected that the peer closed connection gracefully), error: 0xe9
CtApi Server: Win32CAPIWaitForCmd: IPCRead failed. 0x2736 (instance id = 11152)
[tracelog.dat]
Cannot perform TagReadProperty operation on Unresolved Tag=TAG_AiB_R_2_42_L2_18_Status_Bledu (this tag is working I don't know why it is unresolved)
Do You have any idea what could be the cause of ctapi not working after some time?
Best regards