在WinCC中,我要做一个按钮,通过按这个按钮,实现给定值的加或减,比如每点一下“+”按钮给定值输出就增加1,这个用C脚本可以很简单的实现。例如我在WinCC做的脚本如下:
具体的代码我贴出来:
每点一下按钮+1:
#include “apdefap.h”
void OnClick(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName)
{
double dOldValue, dNewValue, dHL, dLL;dOldValue = GetTagDouble(“28BHC01/M1.SP_IN”);
dHL = GetTagDouble(“28BHC01/M1.SP_HLM”);
dLL = GetTagDouble(“28BHC01/M1.SP_LLM”);// If I’m at the limit -> don’t do anything
if (dOldValue == dHL)
return;// decrement 1%
dNewValue = dOldValue + 1;if (dNewValue > dHL)
dNewValue = dHL;//SetTagDouble(“28BHC01/M1.SP_IN”, dNewValue);
SetTagDoubleWait(“28BHC01/M1.SP_IN”, dNewValue); //Return-Type: BOOLreturn;
}
每点一下按钮-1:
#include “apdefap.h”
void OnClick(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName)
{
double dOldValue, dNewValue, dHL, dLL;
char szText[128];
int l;dOldValue = GetTagDouble(“28BHC01/M1.SP_IN”);
dHL = GetTagDouble(“28BHC01/M1.SP_HLM”);
dLL = GetTagDouble(“28BHC01/M1.SP_LLM”);// If I’m at the limit -> don’t do anything
if (dOldValue == dLL)
return;// decrement 1%
dNewValue = dOldValue – 1;if (dNewValue < dLL)
dNewValue = dLL;//SetTagDouble(“28BHC01/M1.SP_IN”, dNewValue);
SetTagDoubleWait(“28BHC01/M1.SP_IN”, dNewValue); //Return-Type: BOOLreturn;
}