You are not registered yet. Please click here to register!

plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
Try our online PLC Simulator- FREE.  Click here now to try it.

---------->>>>>Get FREE PLC Programming Tips

New Here? Please read this important info!!!

Go Back - Interactive Q & A > - Interactive Q & A > LIVE PLC Questions And Answers

PLC training tools sale

Thread Tools Display Modes
Old March 5th, 2018, 03:28 AM   #1

agoslinski is offline
Join Date: Jun 2016
Location: Poznan
Posts: 10
Unhappy Citect SCADA 7.4 SP 2 - CTAPI stops working after some time


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.

from ctypes import *
import os
import sys
import servicemanager
import win32api

class CTAPI:
    def __init__(self, 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")
        self.hCTAPI = windll.CtApi.ctOpen(address, user_name, password, 0)
        if self.hCTAPI is None:
            servicemanager.LogInfoMsg("Connection failed")

    def ct_close(self):
        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 buffer.value

    def ct_tag_write(self, tag_name, value):
        while self.write_lock is True:
        self.write_lock = True
        ok = windll.CtApi.ctTagWrite(self.hCTAPI, tag_name, value)
        if ok == 0:
            e = win32api.GetLastError()
                f = hex(e)
                f -= 0x10000000
                g = int(f)
                    "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) + ")")
                    "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: IPCSocketReceive (recv detected that the peer closed connection gracefully), error: 0xe9
CtApi Server: Win32CAPIWaitForCmd: IPCRead failed. 0x2736 (instance id = 11152)

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
  Reply With Quote
Jump to Live PLC Question and Answer Forum


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
Citect Vs WinCC - Long Doug_Adam LIVE PLC Questions And Answers 22 October 3rd, 2014 12:56 PM
Connecting Citect Scada 5.5 to PLC newinscadacitect LIVE PLC Questions And Answers 1 May 10th, 2012 06:52 AM
find minimum working time between 4 pump unclehamid LIVE PLC Questions And Answers 21 April 21st, 2009 04:20 AM
Citect SCADA sandymax LIVE PLC Questions And Answers 0 March 19th, 2005 05:58 AM
Citect SCADA and Modem comms Kordain LIVE PLC Questions And Answers 3 December 18th, 2003 06:06 PM

All times are GMT -5. The time now is 12:31 PM.