Data communication via CTAPI and Citect SCADA software

Source: Internet
Author: User

Reference: http://www.docin.com/p-275216804.html

(Variable flux Stacker control system based on Citect remote control Wang Yuzan, Gu Yingni, Wang Wei Jinan University, School of Mechanical Engineering, CITECT,CTAPI)

Citect configuration software has been acquired by Schneider. Through the API provided by the software, you can program and configure the software internal data point communication through the advanced language.

Here is an example of Python that has not been tested:

https://github.com/mitchyg/Random/blob/master/pyctapi/src/pyctapi.py

#!/usr/bin/python##File:pyctapi.py#Author:mitchell Gayner#date:06/08/2009##Desc:#Wrapper for Citect ctapi dll#Compatible with Citect V6.1 DLLs##You must has the following DLLs:#-CiDebugHelp.dll#-Ct_ipc.dll#-CtApi.dll#-CtEng32.dll#-CtRes32.DLL#-CtUtil32.dll#ImportPlatform fromcTYPESImport*ImportSYSifPlatform.system ()! ="Windows":    RaiseOSErrorclassPyctapi:def __init__(Self, dllpath_ ="c:/citect/bin/"):        #Load Required DLLsCdll (Dllpath_ +'/cidebughelp') Cdll (dllpath_+'/ctutil32') Cdll (dllpath_+'/CT_IPC') self.__LIBC= Cdll (Dllpath_ +'/ctapi') self.__CN= None#Create Connection Object    defOpen (self, address_, username_, password_, Mode_ =0):"Open connection to running Citect process"        ifSelf.__CN!=None:Print "already connected"            returnSelf .__CN= Windll. Ctapi.ctopen (Address_, Username_, Password_, 2)    defClose (self):"Close connection to running Citect process"CT= Windll. Ctapi.ctclose (self.__CN) self.__CN=NonedefConnected (self):ifSelf.__execcicode("Version (0)") !="":            returnTruereturnFalsedefTagreadint (Self, tagname_):"Read tag from Citect and covert to int"Str= self.__tagread(tagname_)#Try:        returnint (str)#except:        return-1deftagreadfloat (Self, tagname_):"Read tag from Citect and covert to float"Str= self.__tagread(tagname_)#Try:        returnfloat (str)#except:        return-1deftagreadstr (Self, tagname_):"Read tag from Citect and covert to string"Str= self.__tagread(tagname_)returnStrdeftagwrite (self, Tagname_, value_):"Write value to Citect tag"OK= self.__tagwrite(Tagname_, str (value_))returnOKdefExecutecicode (Self, function_):returnSelf.__execcicode(Function_)def __tagread(self, tagname_):"private:read tag from citect tag"F= Create_string_buffer ('\000'* 32) OK= Windll. Ctapi.cttagread (self.__CN, Tagname_, ByRef (f), sizeof (f))returnF.valuedef __tagwrite(self, Tagname_, value_):"private:write value to Citect tag"OK= Windll. Ctapi.cttagwrite (self.__CN, Tagname_, Value_)returnOKdef __execcicode(Self, function_, hwin_=0, nmode_=0): F= Create_string_buffer ('\000'* 32) OK= Windll. Ctapi.ctcicode (self.__CN, Function_, Hwin_, Nmode_, ByRef (f), sizeof (f), None)returnF.value#TODO LIST:" "Done extern HANDLE Ctapicall Ctopen (Lpcstr,lpcstr,lpcstr,dword); /* Open CTAPI interface * /" "#extern BOOL Ctapicall Ctopenex (lpcstr,lpcstr,lpcstr,dword,handle);#extern HANDLE Ctapicall ctclientcreate ();#extern BOOL Ctapicall Ctclientdestroy (HANDLE);" "Done extern BOOL Ctapicall ctclose (HANDLE); /* Close CTAPI interface * /" "#extern BOOL Ctapicall Ctcloseex (HANDLE, BOOL);#extern BOOL Ctapicall Ctcancelio (handle,ctoverlapped*); /* Cancel pending I/O */" "Done extern DWORD Ctapicall Ctcicode (handle,lpcstr,dword,dword,lpstr,dword,ctoverlapped*); /* Execute Cicode * /" "#extern BOOL Ctapicall ctpointwrite (handle,handle,void*,dword,ctoverlapped*); /* Write to point handle * /#extern BOOL Ctapicall ctpointread (handle,handle,void*,dword,ctoverlapped*); /* read from point handle * /#extern HANDLE Ctapicall cttagtopoint (handle,lpcstr,dword,ctoverlapped*); /* Convert tag into point handle*/#extern BOOL Ctapicall ctpointclose (handle,handle); /* Free a point handle * /#extern HANDLE Ctapicall ctpointcopy (HANDLE); /* Copy a point handle * /#extern BOOL Ctapicall ctpointgetproperty (Handle,lpctstr,void*,dword,dword*,dword); /* Get Point Property */#extern DWORD Ctapicall ctpointdatasize (HANDLE); /* Size of point data buffer * /#extern DWORD Ctapicall ctpointbitshift (HANDLE); /* Calculate bit shift offset * /#extern BOOL Ctapicall ctpointtostr (Handle,byte*,dword,byte*,dword,dword); /* Format point data to String * /#extern BOOL Ctapicall ctstrtopoint (Handle,lpcstr,dword,byte*,dword,dword); /* format string data into point*/" "Done extern BOOL Ctapicall cttagwrite (HANDLE,LPCSTR,LPCSTR); /* Write to Tag * /" "" "Done extern BOOL Ctapicall cttagread (Handle,lpcstr,lpstr,dword); /* Read from Tag * /" "#extern BOOL Ctapicall Ctengtoraw (Double*,double,ctscale*,dword); /* scale from ENG to RAW * /#extern BOOL Ctapicall Ctrawtoeng (Double*,double,ctscale*,dword); /* scale from RAW to ENG * /#extern BOOL Ctapicall Ctgetoverlappedresult (Handle,ctoverlapped*,dword*,bool); /* Get overlapped result * /#extern BOOL Ctapicall Ctengtoraw (Double*,double,ctscale*,dword); /* scale from ENG to RAW * /#extern BOOL Ctapicall Ctrawtoeng (Double*,double,ctscale*,dword); /* scale from RAW to ENG * /#extern HANDLE Ctapicall Ctfindfirst (Handle,lpctstr,lpctstr,handle*,dword); /* Initiate a search * /#extern BOOL Ctapicall ctfindnext (handle,handle*); /* Get the next Search item * /#extern BOOL Ctapicall Ctfindprev (handle,handle*); /* Get the Prev Search item * /#extern DWORD Ctapicall ctfindscroll (handle,dword,long,handle*); /* Scroll to Search item * /#extern BOOL Ctapicall ctfindclose (HANDLE); /* Close a search * /#extern LONG Ctapicall ctfindnumrecords (HANDLE); /* Get The total number of records in the search */#extern BOOL Ctapicall ctgetproperty (Handle,lpctstr,void*,dword,dword*,dword); /* Get a named property * /#extern HANDLE Ctapicall ctlistnew (Handle,dword); /* Create poll list * /#extern BOOL Ctapicall ctlistfree (HANDLE); /* FREE Poll list * /#extern HANDLE Ctapicall ctlistadd (HANDLE,LPCSTR); /* Add tag to poll list * /#extern BOOL Ctapicall ctlistdelete (HANDLE); /* Delete tag from poll list * /#extern BOOL Ctapicall ctlistread (handle,ctoverlapped*); /* Read Poll list * /#extern BOOL Ctapicall ctlistwrite (handle,lpcstr,ctoverlapped*); /* Write poll list item * /#extern BOOL Ctapicall ctlistdata (Handle,void*,dword,dword); /* Get list data * /#extern HANDLE Ctapicall ctlistevent (Handle,dword); /* Get list Event * /#extern BOOL Ctapicall ctgetnumberoflicenses (HANDLE, short*, BYTE); /* Key Check CTAPI interface * /
Python code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.