I am trying to write a python program that interfaces with a scada software program. The scada program provides an api through some dll files and provides some example code (written in C I think) in the help. So basically I am trying to translate the example code into python. This is the code I am working with:
HANDLE hSearch;
HANDLE hObject;
HANDLE hFind;
// Search the Tag table
hSearch = ctFindFirst(hCTAPI, "Tag", NULL, &hObject, 0);
if (hSearch == NULL) {
// no tags found
} else {
do {
char sName[32];
// Get the tag name
ctGetProperty(hObject, "Tag", sName, sizeof(sName), NULL,
DBTYPE_STR);
} while (ctFindNext(hSearch, &hObject));
ctFindClose(hSearch);
}
// Get Historical Trend data via CTAPI
// Get 100 samples of the CPU trend at 2 second
hFind = ctFindFirst(hCTAPI, "CTAPITrend(\"10:15:00 \", \"11/8/1998\", 2, 100, 0, \"CPU\")", &hObject, 0);
while (hFind) {
char sTime[32], sDate[32], sValue[32];
ctGetProperty(hObject, "TIME", sTime, sizeof(sTime), NULL, DBTYPE_STR);
ctGetProperty(hObject, "DATE", sDate, sizeof(sDate), NULL, DBTYPE_STR);
ctGetProperty(hObject, "CPU", sValue, sizeof(sValue), NULL, DBTYPE_STR);
// do something with the trend data.
if (!ctFindNext(hFind, &hObject)) {
ctFindClose(hFind);
hFind = NULL;
break;
}
}
I am having two problems. The first is I don't know how to use the DBTYPE_STR datatype in the ctGetProperty function using ctypes. The API help provides this information on that parameter (dwType):
dwType
Type: DWORD
Input/output: Input
Description: The desired return type as follows:
Value | Meaning
DBTYPE_UI1 | UCHAR
DBTYPE _I1 | 1 byte INT
DBTYPE _I2 | 2 byte INT
DBTYPE _I4 | 4 byte INT
DBTYPE _R4 | 4 byte REAL
DBTYPE _R8 | 8 byte REAL
DBTYPE _BOOL | BOOLEAN
DBTYPE_BYTES | Byte stream
DBTYPE _STR | NULL Terminated STRING
The other thing I can't figure out is how to declare a handle datatype using ctypes. Any help you guys could provide is much appreciated, thanks.