SYED.ABIDI
Member
Dear All,
I need urgent help on the following issue about WinCC:
I have button which once clicked will run the following script to read contents of a CSV file. However I want to make this process continuous so that I don't have to click the button again to read the updated contents of CSV. Please suggest asap.
I need urgent help on the following issue about WinCC:
I have button which once clicked will run the following script to read contents of a CSV file. However I want to make this process continuous so that I don't have to click the button again to read the updated contents of CSV. Please suggest asap.
Code:
#define MaxLineLength 80
FILE *fpFile;
char *strTag, *strValue, *pTmp;
char buffer[MaxLineLength];
double dVal;
fpFile = fopen(GetTagChar("Filename"), "r" ); //open file to read
printf ("C-Script: read file: %s\r\n", GetTagChar("Filename"));
if (fpFile !=NULL)
{
while (fgets (buffer, MaxLineLength , fpFile))
{
strTag = buffer;
// Split String and cut carriage return
pTmp = strchr(buffer, (int)',');
*pTmp = '\0';
strValue = ++pTmp;
strValue[strlen(strValue)-1] = '\0';
// Search for ',' and replace with '.'
pTmp = strchr(strValue, (int)',');
if (pTmp != NULL){
*pTmp = '.';
}
// Convert Value-String to double and write to WinCC
sscanf (strValue , "%lf", &dVal);
SetTagDouble(strTag,dVal);
printf("%s Value: %lf\r\n", strTag, dVal);
}
fclose(fpFile); //close file
} else {
printf ("Error: File not found!\n");
}