试过"项目范围内更新","计算机本地更新","运行系统保持"这些选项,都不行.
是不是只能使用脚本把变量值写到硬盘文件,在启动时读取,希望提供代码,谢谢!!!
问题补充:
手动取消激活时可以保存吗?
我打算给工控机增加UPS电源,不会突然掉电了.
因为系统运行一段时间,会暴露出BUG,需要停机维护(例如:结构变量在运行状态似乎不能更改),系统某些设置保存在内部变量里比较方便,但停机后再启动,这些设置都无效了,重新设置比较麻烦.
最佳答案
C脚本比较普遍:
退出是保存
#include "apdefap.h"
void Click(char* lpszPictureName, char* lpszObjectName )
{
// WINCC:TAGNAME_SECTION_START
// syntax: #define TagNameInAction "DMTagName"
// next TagID : 1
// WINCC:TAGNAME_SECTION_END
int abc;
char* Message = (char*) malloc(512);
struct tiaojie
{
int zishoukg;
float shousheding;
float zisheding;
};
struct shoudong
{
int zishoukg;
float shousheding;
};
struct baojing
{
float gaobaoj;
float dibaoj;
float zisheding;
int zishoukg;
};
struct tiaojie pic[4];
struct baojing yewei[2];
struct shoudong pinglv[6];
FILE *fp1,*fp2, *fp3;
strcpy(Message,"\r\n确定退出吗?\r\n");
abc=MessageBox(NULL,Message,"MessageBox",1|MB_SYSTEMMODAL);
if (abc==1)
{
pic[0].zisheding=GetTagFloat("sd_pic201a"); //tiaojie start
pic[0].shousheding=GetTagFloat("sd_pic201ak");
if((GetTagWord("WCword5IN"))&&1)
{ pic[0].zishoukg=1;}
else
{ pic[0].zishoukg=0;}
pic[1].zisheding=GetTagFloat("sd_pic201b");
pic[1].shousheding=GetTagFloat("sd_pic201bk");
if((GetTagWord("WCword5IN"))&&4)
{ pic[1].zishoukg=1;}
else
{ pic[1].zishoukg=0;}
pic[2].zisheding=GetTagFloat("sd_pic205a");
pic[2].shousheding=GetTagFloat("sd_pic205ak");
if((GetTagWord("WCword5IN"))&&2)
{ pic[2].zishoukg=1;}
else
{ pic[2].zishoukg=0;}
pic[3].zisheding=GetTagFloat("sd_pic205b");
pic[3].shousheding=GetTagFloat("sd_pic205bk");
if((GetTagWord("WCword5IN"))&&8)
{ pic[3].zishoukg=1;}
else
{ pic[3].zishoukg=0;}
fp1=fopen("D:\\DATA\\tiaoj.txt","wb+");
if(fp1!=NULL)
{
fwrite(pic,sizeof(struct tiaojie),4,fp1); //tiaojie end
}
yewei[0].zisheding=GetTagFloat("sd_v0103a");
yewei[0].gaobaoj=GetTagFloat("gb_v0103a");
yewei[0].dibaoj=GetTagFloat("db_v0103a");
if((GetTagWord("WCword5IN"))&&40)
{ yewei[0].zishoukg=1;}
else
{yewei[0].zishoukg=0;}
yewei[1].zisheding=GetTagFloat("sd_v0104a");
yewei[1].gaobaoj=GetTagFloat("gb_v0104a");
yewei[1].dibaoj=GetTagFloat("db_v0104a");
if((GetTagWord("WCword5IN"))&&100)
{ yewei[1].zishoukg=1;}
else
{yewei[1].zishoukg=0;}
fp2=fopen("D:\\DATA\\baoj.txt","wb+");
if(fp2!=NULL)
{
fwrite(yewei,sizeof(struct baojing),2,fp2); //yewei end
}
pinglv[0].shousheding=GetTagFloat("sdpl_p0100"); //shoudong start
pinglv[0].zishoukg=0;
pinglv[1].shousheding=GetTagFloat("sdpl_p0102a");
pinglv[1].zishoukg=0;
pinglv[2].shousheding=GetTagFloat("sdpl_p0103a");
pinglv[2].zishoukg=0;
pinglv[3].shousheding=GetTagFloat("sdpl_p0103b");
pinglv[3].zishoukg=0;
pinglv[4].shousheding=GetTagFloat("sdpl_m201a");
pinglv[4].zishoukg=0;
pinglv[5].shousheding=GetTagFloat("sdpl_m201b");
pinglv[5].zishoukg=0;
fp3=fopen("D:\\DATA\\shoud.txt","wb+");
if(fp3!=NULL)
{
fwrite(pinglv,sizeof(struct shoudong),6,fp3); //shoudong end
}
fclose(fp3);
fclose(fp2);
fclose(fp1);
SetTagBit("Exit_Flag",0);
ExitWinCC();
}
// WINCC:PICNAME_SECTION_START
// syntax: #define PicNameInAction "PictureName"
// next PicID : 1
// WINCC:PICNAME_SECTION_END
}
读取时结构基本一样,只是命令不一样FREAD(),取数据处理
提问者对于答案的评价:
谢谢
专家置评
对于 WinCC V7.0 可以参考 文静东东 的方法。
原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc267544.html