我弄了一段程序添加在鼠标点击左键里面,编译正常,
FILE *fpFile;
char *strTag[5] = { "TagA", "TagB", "TagC", "TagD", "TagE" };
char *pTmp;
char buffer[MaxLineLength];
double dVal;
int i;
fpFile = fopen(GetTagChar("D:\\WRITE.txt"), "w+" ); //open file to write
printf ("C-Script: write file: %s\r\n", GetTagChar("D:\\WRITE.txt"));
if (fpFile !=NULL)
{
for (i=0; i<=4; i++){
dVal = GetTagDouble(strTag[i]);
sprintf(buffer, "%s;%lf\n", strTag[i],dVal);
// Search for '.' and replace with ','
pTmp = strchr(buffer, (int)'.');
if (pTmp != NULL){
*pTmp = ',';
}
fputs(buffer,fpFile);
printf("%s\r\r\n", buffer);
}
fclose(fpFile); //close file
} else {
printf ("Error: File not found!\r\n");
}
1.我在WINCC里面建了5个文本8位内部变量TagA,TagB,TagC,TagD,TagE,画面上做了5个输入输出域连接这5个变量,输入值后点击鼠标左键,发现D盘下的文件WRITE.txt里什么都没有,高手给分析下原因啊,谢谢
2. 如果我想写入5个整数型变量该怎么改动程序呢?
最佳答案
1、fpFile = fopen(GetTagChar("D:\\WRITE.txt"), "w+" ); //open file to write
printf ("C-Script: write file: %s\r\n", GetTagChar("D:\\WRITE.txt"));
这两句不能用GetTagChar,改为:
fpFile = fopen("D:\\WRITE.txt", "w+" ); //open file to write
printf ("C-Script: write file: %s\r\n", "D:\\WRITE.txt");
2、这句的目的是什么?
dVal = GetTagDouble(strTag[i]);
strTag[i]是个字符变量,为何用GetTagDouble?要读出变量内容应该用GetTagChar。
3、整数型变量使用GetTagWord函数即可。
提问者对于答案的评价:
谢谢
原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc251597.html