Citect SCADA 7.4 SP 2 - CTAPI stops working after some time

agoslinski

Member
Join Date
Jun 2016
Location
Poznan
Posts
10
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.

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
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
 

Similar Topics

I am trying to display a variable within a cicode function onto a graphics page. This function queries a SQL database. I can get the value onto a...
Replies
3
Views
228
We are trying to set up a newer generation Omron PLC (NX/NS Series) with Citect / Aveva Plant SCADA using the Ethernet/IP CIP Protocol to read...
Replies
2
Views
266
I am new to Citect SCADA and I am building the graphics for a page that will contain the control of a plant by a Kingfisher RTU. The project I...
Replies
0
Views
219
Hi All, I aim to use Aveva Plant SCADA 2020 to read and write data from/to Omron CJ2M CPU35 PLC using OMFINS protocol. However I have Bad Data...
Replies
1
Views
686
Hey, I'm trying to do the following, I have some experience with Citect but can't seem to figure this out. I/O Tag: BoxPos1_ProdNum (Data Type...
Replies
0
Views
554
Back
Top Bottom