wincc 常用脚本
wincc 常用脚本
DeactivateRTProject ();//退出系统#pragma code("useadmin.dll")#include"PWRT_api.h"#pragma code()char* CUser=NULL;CUser=GetTagChar("@CurrentUser");if (strlen(CUser)==0){PWRTSilentLogin("operator","123456");//用户“operator",密码"123456”登录}OpenPicture("@MAIN.pdl");}在画面中结合不同按钮来组态下面 C 操作LoginAction for login (for example, "mouse click" event):#pragma code ("useadmin.dll")#include "PWRT_api.h"#pragma code()PWRTLogin('c');LogoutAction for logout (for example, "mouse click" event):#pragma code ("useadmin.dll")#include "PWRT_api.h"#pragma code()PWRTLogout();PWRTLogin 参数必须是CHAR 字符。
它指定了显示对话框的监视器。
如果只使用一个监视器,那么保留默认参数“c”或者指定“1”。
注意可以使用PASSLoginDialog 函数来代替PWRTLogin 或者PWRTLogout 函数。
这个函数需要和函数PWRTLogin 相同的参数。
wincc-全套脚本总结
)
}
-------------------------------------
——————7、对话框调用——————
BOOL A;
BOOL B;
}
// WINCC:PICNAME_SECTION_START
// syntax: #define PicNameInAction "PictureName"
// next PicID : 1
// WINCC:PICNAME_SECTION_END
return 0;
}
=====================================================
int value;
value=GetTagBit("IM_in");//"IM_in"为触发的变量。
if(value==1)
{
SetVisible("lianxi.pdl","按钮8",TRUE);//lianxi.pdl为控制对象所在画etVisible("lianxi.pdl","按钮8",FALSE);//lianxi.pdl
SetPropWord(lpszPictureName,"qushi","ValueAxisEndValue",Hi);
————————————————————————
——————4、获取位号————————
SetTagChar("TrendTagName1","ProcessValueArchive\\PT111");//Return-Type: BOOL
wincc-全套脚本总结
—————-1、wincc全局脚本动作-——-—-—隐藏控件——————#include "apdefap.h"int gscAction( void ){// WINCC:TAGNAME_SECTION_START// syntax: #define TagNameInAction "DMTagName"// next TagID : 1// WINCC:TAGNAME_SECTION_ENDint value;value=GetTagBit(”IM_in”);//"IM_in”为触发的变量.if(value==1){SetVisible("lianxi.pdl”,”按钮8",TRUE);//lianxi。
pdl为控制对象所在画面名,“按钮8”为对象名称}else{SetVisible(”lianxi.pdl","按钮8",FALSE);//lianxi.pdl}// WINCC:PICNAME_SECTION_START// syntax:#define PicNameInAction "PictureName”// next PicID : 1// WINCC:PICNAME_SECTION_ENDreturn 0;}=====================================================说明:在触发器里选择变量IM_in-—————2、wincc全局脚本动作-——-提示框————--#include "apdefap.h”int gscAction( void ){// WINCC:TAGNAME_SECTION_START// syntax: #define TagNameInAction "DMTagName”// next TagID : 1// WINCC:TAGNAME_SECTION_ENDint value;value=GetTagBit(”IM_in”);if(value==1){MessageBox(NULL,”请确认三厅相关门是否关好,或者请解锁。
WINCC常用 脚本
11、在画面中显示用户名
1.组态静态文本
2.字体属性中的文本,连接系统变量@CurrentUser
----------------------------------------------
(2)新密码设置(C)
SetOutputValueChar(lpszPictureName,lpszObjectName,GetInputValueChar(lpszPictureName,lpszObjectName));
注:字符串格式的输入输出域》事件》属性主题》输出/输入》输出值》更改》以上代码。
{
MessageBox (Handle, "新密码和旧密码不能相同 !", "请重新输入密码", MB_OK |
MB_ICONEXCLAMATION | MB_SYSTEMMODAL);
}
else
{
// this 2 lines are necessary to get the DSN-Name of the project
a=MsgBox("hello!",vbYesNo)
If vbYes=a Then
objCon2.text="ok" '如点击是,则按钮文本变为ok
Else
objCon2.text="no" '如点击否,则按钮文本变为no
End If
注:放置按钮,起名按钮1.
----------------------------------------------
wincc-脚本大全
{
SetTagBit("TJ_ANNIU",1);
MessageBox (hwnd, "停机", "停机警告", MB_OK|MB_SYSTEMMODAL|MB_SETFOREGROUND);
SetTagBit("TJ_ANNIU",0);
}
else B=0;
}
else
————————————————————————
——————4、获取位号————————
SetTagChar("TrendTagName1","ProcessValueArchive\\PT111");//Return-Type: BOOL
SetTagSWord("TrendHi",200);
SetTagSWord("TrendLo",0);
z=GetTagBit("202搅拌机运行"); //取得PLC搅拌机的运行状态
if(z!=0)
{
switch(y)
{
case 0:
x=x-4;
if(x<=0)
y=1;
break;
default :
x=x+4;
if(x>=25)
y=0;
break;
}
}
return x;
}
——————12、运行时图形产生动态旋转——————
#include "apdefap.h"
long _main(char* lpszPictureName, char* lpszObjectName, char*
wincc常用C脚本功能
.用户注销:#pragma code ("useadmin.dll")#include "PWRT_api.h”#pragma code()PWRTLogout();2. 用户登录:#pragma code ("useadmin.dll")#include "PWRT_api.h"#pragma code()PWRTLogin('c');3. 关闭项目并退出wincc :ExitWinCC ();4. 退出运行到wincc资源管理器:DeactivateRTProject ();按钮变三种颜色#include "apdefap.h"long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){#pragma option(mbcs)if(GetTagWord("TX/ZSH001")==1)return 0x0000ff00;elseif(GetTagWord("TX/ZSL001")==1)return 0x000000ff;elsereturn 0x00c0c0c0;}一个调用按钮变色#include "apdefap.h"long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){#pragma option(mbcs)if(GetTagWord("NewTag")==0)return 0x0000ff00;elsereturn 0x00ffffff;}5. 结束监控并关闭计算机(会弹出确认对话框)HWND hWnd = NULL;//Author:Smartsysint iRet;hWnd = FindWindow(NULL,"WinCC-运行系统-");iRet=MessageBox(hWnd,”结束监控并关闭计算机",”关闭操作站”,MB_YESNO|MB_ICONWARNING|MB_APPLMODAL); if(iRet==IDYES)DMExitWinCCEx (DM_SDMODE_POWEROFF);6. 点击事件弹出对话框,通过点击弹出对话框的确定和取消按钮实现对变量的置位或取消:int r;r=MessageBox(NULL, "YES为开,NO 为关","确定开命令:",MB_YESNO |MB_SYSTEMMODAL);if (r==IDYES)SetTagBit("TAGNAME”,TRUE);elseSetTagBit("TAGNAME”,FALSE);7. 开显示关显示:(要在内部变量中建立三个二进制变量COLSE_DISPLAY DISPLAY_NO 和DISPLAY_COMMENT)// Funktion: Bit in Doppelwort setzen;if (GetTagBitWait("COLSE_DISPLAY")==1 ){SetTagBit("COLSE_DISPLAY",0);世甜羽淋二<i^^pW#^$l>.t_imN)xoae6esse|A|)j!} es|e { { 100日:edAi-ujniey// 昭目顷10£)}旧阮gas } (9 == (iVaOIAIIAI mis 人S—SIAlleNnoaomaOzlimS 一日lAllNOLLSmnONO。
wincc-全套脚本总结
——————1、wincc全局脚本动作-------隐藏控件——————#include "apdefap.h"int gscAction( void ){// WINCC:TAGNAME_SECTION_START// syntax: #define TagNameInAction "DMTagName"// next TagID : 1// WINCC:TAGNAME_SECTION_ENDint value;value=GetTagBit("IM_in");//"IM_in"为触发的变量。
if(value==1){SetVisible("lianxi.pdl","按钮8",TRUE);//lianxi.pdl为控制对象所在画面名,“按钮8”为对象名称}else{SetVisible("lianxi.pdl","按钮8",FALSE);//lianxi.pdl}// WINCC:PICNAME_SECTION_START// syntax: #define PicNameInAction "PictureName"// next PicID : 1// WINCC:PICNAME_SECTION_ENDreturn 0;}=====================================================说明:在触发器里选择变量IM_in——————2、wincc全局脚本动作----提示框——————#include "apdefap.h"int gscAction( void ){// WINCC:TAGNAME_SECTION_START// syntax: #define TagNameInAction "DMTagName"// next TagID : 1// WINCC:TAGNAME_SECTION_ENDint value;value=GetTagBit("IM_in");if(value==1){MessageBox(NULL,"请确认三厅相关门是否关好,或者请解锁。
Wincc常用C脚本及常用功能
Wincc常用C脚本及常用功能打开用户管理器ProgramExecute("Passcs.exe"); 取消激活#include "apdefap.h"void OnLButtonDown(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName,UINT nFlags, int x, int y){#pragma option(mbcs)HWND hwnd=NULL;int iRet;hwnd=FindWindow(NULL,"WinCC-运行系统 - "); //获得句柄iRet=MessageBox(hwnd,"是否取消激活?","Deactivate",MB_OKCANCEL|MB_ICONWARNING|MB_APPLMODAL);if(iRet==1)DeactivateRTProject (); //Return-Type: BOOL}关闭计算机#include "apdefap.h"void OnLButtonDown(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName,UINT nFlags, int x, int y){#pragma option(mbcs)HWND hwnd=NULL;int iRet;hwnd=FindWindow(NULL,"WinCC-运行系统 - ");iRet=MessageBox(hwnd,"是否关闭计算机?","ShutDown",MB_OKCANCEL|MB_ICONWARNING|MB_APPLMODAL);if(iRet==1)DMExitWinCCEx(DM_SDMODE_SYSTEM); }==================================================================== ==登陆代码:#pragma code(“useadmin.dll”)#include <pwrt_api.h>#pragma code()PWRTLogin (…e?);==================================== 取消激活(Deactivate)DeactivateRTProject();====================================== Wincc变量操作GetTagDWord(“变量名称”); 获取Wincc变量值SetTagDWord(“变量“,设定值); 设置Wincc变量对文本读写操作写操作#include "apdefap.h"void OnLButtonUp(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName,UINT nFlags, int x, int y) {#pragma option(mbcs)FILE* lpFile;char *shuzhu[6]={"tag_1","tag_2","tag_3","tag_4","tag_5","tag_6"};char* lpszStr;int i,j;lpszStr=SysMalloc(60); //Return-Type: void*lpFile = fopen("D:\\test.txt", "w+");for(i=0;i<6;i++){lpszStr=GetTagChar(shuzhu[i]); strcat(lpszStr,"\r\n");if(lpFile == NULL){ printf("can not open file\r\n"); return;}fprintf(lpFile, lpszStr); }SysFree(lpszStr);fclose(lpFile);}读操作#include "apdefap.h"void OnLButtonUp(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName,UINT nFlags, int x, int y) {#pragma option(mbcs)char* shuzhu[6]={"tag_1","tag_2","tag_3","tag_4","tag_5","tag_6"}; char tmp[255];int i=0;int ChrNumLine=38;FILE *fp;fp=fopen("D:\\test.txt","r"); if (fp==NULL){return;}else{rewind(fp);while(!feof(fp)){fgets(tmp,ChrNumLine,fp);SetTagChar(shuzhu[i],tmp);i++;}}fclose(fp);}画面窗口显示界面切换SetPictureName(lpszPictureName,"PicWindow_button","produce_manage_bu tton.pdl");SetVisible(lpszPictureName,"PicWindow_button",1);注:PicWindow_button是画面窗口名称;produce_manage_button.pdl是要显示的子画面。
wincc常用C脚本
1.用户注销:#pragma code ("useadmin.dll")#include "PWRT_api.h"#pragma code()PWRTLogout();2.用户登录:#pragma code ("useadmin.dll")#include "PWRT_api.h"#pragma code()PWRTLogin('c');3.关闭项目并退出wincc:ExitWinCC ();4.退出运行到wincc资源管理器:DeactivateRTProject ();按钮变三种颜色#include "apdefap.h"long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName) {#pragma option(mbcs)if(GetTagWord("TX/ZSH001")==1)return 0x0000ff00;elseif(GetTagWord("TX/ZSL001")==1)return 0x000000ff;elsereturn 0x00c0c0c0;}一个调用按钮变色#include "apdefap.h"long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName) {#pragma option(mbcs)if(GetTagWord("NewTag")==0)return 0x0000ff00;elsereturn 0x00ffffff;}5.结束监控并关闭计算机(会弹出确认对话框)HWND hWnd = NULL;//Author:Smartsysint iRet;hWnd = FindWindow(NULL,"WinCC-运行系统 - ");iRet=MessageBox(hWnd,"结束监控并关闭计算机","关闭操作站",MB_YESNO|MB_ICONWARNING|MB_APPLMODAL);if(iRet==IDYES)DMExitWinCCEx (DM_SDMODE_POWEROFF);6.点击事件弹出对话框,通过点击弹出对话框的确定和取消按钮实现对变量的置位或取消: int r;r=MessageBox(NULL, "YES为开,NO为关", "确定开命令:", MB_YESNO |MB_SYSTEMMODAL); if (r==IDYES)SetTagBit("TAGNAME",TRUE);elseSetTagBit("TAGNAME",FALSE);7.开显示关显示:(要在内部变量中建立三个二进制变量COLSE_DISPLAY、DISPLAY_NO和DISPLAY_COMMENT)// Funktion: Bit in Doppelwort setzen;if (GetTagBitWait("COLSE_DISPLAY")==1 ){SetTagBit("COLSE_DISPLAY",0);SetTagBit("DISPLAY_NO",0); //Return-Type: BOOLSetTagBit("DISPLAY_COMMENT",0);}else{SetTagBit("COLSE_DISPLAY",1);SetTagBit("DISPLAY_NO",1); //Return-Type: BOOLSetTagBit("DISPLAY_COMMENT",0);}8.开阀确认:BOOL a;a=GetTagBit("30T制水启动"); //Return-Type :short intif (a==0){if(MessageBox(NULL,"真的要启动制水吗?","操作提示",MB_YESNO|MB_ICONQUESTION|MB_SETFOREGROUND|MB_SYSTEMMODAL) == 6){ SetTagBit("30T制水启动",1);//Return-Type :BOOL}}else{if(MessageBox(NULL,"真的要停止制水吗?","操作提示",MB_YESNO|MB_ICONQUESTION|MB_SETFOREGROUND|MB_SYSTEMMODAL) == 6){ SetTagBit("30T制水停止",1);}}9.将WinCC运行画面最小化HWND WinCCHwnd;WinCCHwnd=FindWindow(NULL,"WinCC-Runtime - "); //如果运行语言为英文if (WinCCHwnd==0) WinCCHwnd=FindWindow(NULL,"WinCC-运行系统 - "); //如果运行语言为中文CloseWindow(WinCCHwnd);10.显示或不显示(其中hiddVtext为内部的二进制变量)if(GetTagBit("hiddVtext")==0) //Return-Type: BOOL{SetTagBit("hiddVtext",TRUE); //Return-Type: BOOL//Return-Type: BOOL}else{SetTagBit("hiddVtext",FALSE);}10.打开编辑画面的脚本#pragma option(mbcs)#ifdef RUN_ON_WEBNAVIGATOR#elseHWND hExplorerWindow= NULL;HWND hRuntimeWindow= NULL;hExplorerWindow= FindWindow("WinCCExplorerFrameWndClass",NULL);hRuntimeWindow= FindWindow("PDLRTisAliveAndWaitsForYou",NULL);if(hExplorerWindow){ShowWindow(hExplorerWindow, SW_MINIMIZE); // This entry is only necessary for Windows 2000ShowWindow(hExplorerWindow, SW_SHOWNORMAL);SetForegroundWindow(hExplorerWindow);}elseprintf("rn SetForeground failed");#endif11.如何在WINCC中制作一个保持型按钮方法1:if( GetTagBit("M10") )SetTagBit("M10",0);elseSetTagBit("M10",1);方法2:SetTagBit("M1.0",(SHORT)!GetTagBit("M1.0"));求反指令,如果为1点击变为0,如果为0点击变为1方法3:或者做两个按钮,按钮一:显示,直接连接m1.0,是--不显示,否--显示。
Wincc常用C脚本
{
DWORD value;
HWND hWnd=NULL ;
hWnd=FindWindow(NULL,"Wincc-运行系统- ");
value=GetTagDWord("AI标签");
#include "apdefap.h"
long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName)
{
#pragma code("useadmin.dll")
#include "PWRT_API.H"
#pragma code()
a+=20;
if (a>=720) (a=350);
}
return a;
}
物料向上移动(几何---位置Y)(停车后,物料停在该点)
#include "apdefap.h"
long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName)
{
HWND hWnd=NULL;
int上位启动信号;
hWnd=FindWindow(NULL,"WinCC C-Course");
if (GetTagBit("DI备妥"))
{
上位启动信号=MessageBox(hWnd,"电源已备妥,您现在确定要启动吗?","启动!",
wincc 脚本,实践可用
1风机风叶c动作全局脚本触发器时间0.5s#include"apdefap.h"int gscAction( void ){#pragma option(mbcs)int a,b,c;b=GetTagWord("fdf");//风机风叶状态显示a=GetTagBit("i12");//风机运行反馈的I1.2if (a==1){b=b*2;if (b>4||b<1) b=1;}elseb=0;SetTagWord("fdf",b);return 0;}2 火焰状态全局vb 触发器时间0.5sOption ExplicitFunction actionDim a,b,c,d,ea=HMIRuntime.tags("huoyan2").Read 'plc变量火焰状态 0 1 2 3 b=HMIRuntime.tags("wc1").Read '火焰状态显示是内部变量16位无符号Select Case aCase 0HMIRuntime.tags("wc1").write 0Case 1b=b+1If b>2 Then b=1HMIRuntime.tags("wc1").write b'statementblock_1Case 2If b<4 Then b=4b=b*2If b>20 Then b=4HMIRuntime.tags("wc1").write b'statementblock_2Case 3If b<40 Then b=32b=b*2If b>128 Then b=32HMIRuntime.tags("wc1").write bCase ElseHMIRuntime.tags("wc1").write 0'statementblock_nEnd SelectEnd Function3 仓泵气阀开关状态显示这个在图形编辑器,圆属性的颜色属性c脚本触发时间0.25s#include"apdefap.h"long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName) {#pragma option(mbcs)int a,b,c,d;a=GetTagWord("DB22_DW62");//plc 开关状态1 2 3 4SetTagBit("prec2",!GetTagBit("prec2")); //Return-Type: BOOLb=GetTagBit("prec2");//plc内部辅助变量这个运行的定义变量无法保存,所以要借用内部变量。
wincc常用C脚本
.用户注销:#pragma code ("useadmin.dll")#include "PWRT_api.h"#pragma code()PWRTLogout();2.用户登录:#pragma code ("useadmin.dll")#include "PWRT_api.h"#pragma code()PWRTLogin('c');3.关闭项目并退出wincc:ExitWinCC ();4.退出运行到wincc资源管理器:DeactivateRTProject ();按钮变三种颜色#include "apdefap.h"long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName) {#pragma option(mbcs)if(GetTagWord("TX/ZSH001")==1)return 0x0000ff00;elseif(GetTagWord("TX/ZSL001")==1)return 0x000000ff;elsereturn 0x00c0c0c0;}一个调用按钮变色#include "apdefap.h"long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName) {#pragma option(mbcs)if(GetTagWord("NewTag")==0)return 0x0000ff00;elsereturn 0x00ffffff;}5.结束监控并关闭计算机(会弹出确认对话框)HWND hWnd = NULL;//Author:Smartsysint iRet;hWnd = FindWindow(NULL,"WinCC-运行系统 - ");iRet=MessageBox(hWnd,"结束监控并关闭计算机","关闭操作站",MB_YESNO|MB_ICONWARNING|MB_APPLMODAL);if(iRet==IDYES)DMExitWinCCEx (DM_SDMODE_POWEROFF);6.点击事件弹出对话框,通过点击弹出对话框的确定和取消按钮实现对变量的置位或取消: int r;r=MessageBox(NULL, "YES为开,NO为关", "确定开命令:", MB_YESNO |MB_SYSTEMMODAL); if (r==IDYES)SetTagBit("TAGNAME",TRUE);elseSetTagBit("TAGNAME",FALSE);7.开显示关显示:(要在内部变量中建立三个二进制变量COLSE_DISPLAY、DISPLAY_NO和DISPLAY_COMMENT)// Funktion: Bit in Doppelwort setzen;if (GetTagBitWait("COLSE_DISPLAY")==1 ){SetTagBit("COLSE_DISPLAY",0);SetTagBit("DISPLAY_NO",0); //Return-Type: BOOLSetTagBit("DISPLAY_COMMENT",0);}else{SetTagBit("COLSE_DISPLAY",1);SetTagBit("DISPLAY_NO",1); //Return-Type: BOOLSetTagBit("DISPLAY_COMMENT",0);}8.开阀确认:BOOL a;a=GetTagBit("30T制水启动"); //Return-Type :short intif (a==0){if(MessageBox(NULL,"真的要启动制水吗?","操作提示",MB_YESNO|MB_ICONQUESTION|MB_SETFOREGROUND|MB_SYSTEMMODAL) == 6){ SetTagBit("30T制水启动",1);//Return-Type :BOOL}}else{if(MessageBox(NULL,"真的要停止制水吗?","操作提示",MB_YESNO|MB_ICONQUESTION|MB_SETFOREGROUND|MB_SYSTEMMODAL) == 6){ SetTagBit("30T制水停止",1);}}9.将WinCC运行画面最小化HWND WinCCHwnd;WinCCHwnd=FindWindow(NULL,"WinCC-Runtime - "); //如果运行语言为英文if (WinCCHwnd==0) WinCCHwnd=FindWindow(NULL,"WinCC-运行系统 - "); //如果运行语言为中文CloseWindow(WinCCHwnd);10.显示或不显示(其中hiddVtext为内部的二进制变量)if(GetTagBit("hiddVtext")==0) //Return-Type: BOOL{SetTagBit("hiddVtext",TRUE); //Return-Type: BOOL//Return-Type: BOOL}else{SetTagBit("hiddVtext",FALSE);}10.打开编辑画面的脚本#pragma option(mbcs)#ifdef RUN_ON_WEBNAVIGATOR#elseHWND hExplorerWindow= NULL;HWND hRuntimeWindow= NULL;hExplorerWindow= FindWindow("WinCCExplorerFrameWndClass",NULL);hRuntimeWindow= FindWindow("PDLRTisAliveAndWaitsForYou",NULL);if(hExplorerWindow){ShowWindow(hExplorerWindow, SW_MINIMIZE); // This entry is only necessary for Windows 2000ShowWindow(hExplorerWindow, SW_SHOWNORMAL);SetForegroundWindow(hExplorerWindow);}elseprintf("rn SetForeground failed");#endif11.如何在WINCC中制作一个保持型按钮方法1:if( GetTagBit("M10") )SetTagBit("M10",0);elseSetTagBit("M10",1);方法2:SetTagBit("M1.0",(SHORT)!GetTagBit("M1.0"));求反指令,如果为1点击变为0,如果为0点击变为1方法3:或者做两个按钮,按钮一:显示,直接连接m1.0,是--不显示,否--显示。
wincc-全套脚本总结
wincc-全套脚本总结——————1、wincc全局脚本动作-------隐藏控件——————#include "apdefap.h"int gscAction( void ){// WINCC:TAGNAME_SECTION_START// syntax: #define TagNameInAction "DMTagName"// next TagID : 1// WINCC:TAGNAME_SECTION_ENDint value;value=GetTagBit("IM_in");//"IM_in"为触发的变量。
if(value==1){SetVisible("lianxi.pdl","按钮8",TRUE);//lianxi.pdl为控制对象所在画面名,“按钮8”为对象名称}else{SetVisible("lianxi.pdl","按钮8",FALSE);//lianxi.pdl}// WINCC:PICNAME_SECTION_START// syntax: #define PicNameInAction "PictureName"// next PicID : 1// WINCC:PICNAME_SECTION_ENDreturn 0;}====================================== ===============说明:在触发器里选择变量IM_in——————2、wincc全局脚本动作----提示框——————#include "apdefap.h"int gscAction( void ){// WINCC:TAGNAME_SECTION_START// syntax: #define TagNameInAction "DMTagName"// next TagID : 1// WINCC:TAGNAME_SECTION_ENDint value;value=GetTagBit("IM_in");if(value==1){MessageBox(NULL,"请确认三厅相关门是否关好,或者请解锁。
Wincc常用C脚本及常用功能
打开用户管理器ProgramExecute("");取消激活#include ""void OnLButtonDown(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y){#pragma option(mbcs)HWND hwnd=NULL;int iRet;hwnd=FindWindow(NULL,"WinCC-运行系统- "); 01-1",".A01-0",".A00-2",".A00-3",".A00-6",".A21-2",".A21-1",".T1",".T2",".T3",".T4",".steady_time ",".overfeed_time",".A01-3",".A01-4",".A30-1",".A30-2",".A30-3",".A30-4",".A30-5",".A30-6",".A30-7",".A30-8",".A30-9",".A30-10",".A3 0-11",".A30-12",".A31-1",".A31-2",".A31-3",".A31-4",".A31-5",".A31-6",".A31-7",".A31-8",".A31-9",".A31-10",".A3 1-11",".A31-12"};char *chr_current;char *pos;HWND hWnd=NULL;hWnd=FindWindow(NULL,"WinCC-运行系统- ");chr_current=SysMalloc(30); //Return-Type: void*pos=SysMalloc(10); //Return-Type: void*pos=GetTagChar("current");//--------------Get Value-----------------------------------if(GetTagWord("current")>=1){for(i=0;i<39;i++){strcpy(chr_current,"stru_pos_");strcat(chr_current,pos);strcat(chr_current,houzui[i]);mid_value[i]=GetTagFloat(chr_current);}//-------------------------muti send---------------------------------------start_flag=GetTagWord("start");end_flag=GetTagWord("end");if(start_flag<=end_flag){for(i=start_flag;i<=end_flag;i++){SetTagWord("mid_pos",i);pos=GetTagChar("mid_pos");for(j=0;j<39;j++){strcpy(chr_current,"stru_pos_");strcat(chr_current,pos);strcat(chr_current,houzui[j]);SetTagFloat(chr_current,mid_value[j]);}}MessageBoxA(hWnd,"群设置完成!","Multi Send",MB_OK|MB_ICONINFORMATION|MB_APPLMODAL);}elseMessageBoxA(hWnd,"起始位需小于等于结束位!","Warning",MB_OK|MB_ICONWARNING|MB_APPLMODAL);}elseMessageBoxA(hWnd,"当前位号输入错误!","Warning",MB_OK|MB_ICONWARNING|MB_APPLMODAL);}。
Wincc常用C脚本及常用功能
Wincc常用C脚本及常用功能打开用户管理器ProgramExecute("Passcs.exe");取消激活#include "apdefap.h"void OnLButtonDown(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y){#pragma option(mbcs)HWND hwnd=NULL;int iRet;hwnd=FindWindow(NULL,"WinCC-运行系统- "); //获得句柄iRet=MessageBox(hwnd,"是否取消激活?","Deactivate",MB_OKCANCEL|MB_ICONW ARNING|MB_APPLMODAL);if(iRet==1)DeactivateRTProject (); //Return-Type: BOOL关闭计算机#include "apdefap.h"void OnLButtonDown(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y){#pragma option(mbcs)HWND hwnd=NULL;int iRet;hwnd=FindWindow(NULL,"WinCC-运行系统- ");iRet=MessageBox(hwnd,"是否关闭计算机?","ShutDown",MB_OKCANCEL|MB_ICONW ARNING|MB_APPLMODAL);if(iRet==1)DMExitWinCCEx(DM_SDMODE_SYSTEM);}====================================== ================================ 登陆代码: #pragma code(“useadmin.dll”)#include#pragma code()PWRTLogin (…e?);====================================取消激活(Deactivate)DeactivateRTProject();====================================== Wincc变量操作GetTagDWord(“变量名称”); 获取Wincc变量值SetTagDWord(“变量“,设定值);设置Wincc变量对文本读写操作写操作#include "apdefap.h"void OnLButtonUp(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y){#pragma option(mbcs)FILE* lpFile;char*shuzhu[6]={"tag_1","tag_2","tag_3","tag_4","tag_5","tag_6"};char* lpszStr;lpszStr=SysMalloc(60); //Return-Type: void*lpFile = fopen("D:\\test.txt", "w+");for(i=0;i<6;i++){lpszStr=GetTagChar(shuzhu[i]);strcat(lpszStr,"\r\n");if(lpFile == NULL){ printf("can not open file\r\n"); return;}fprintf(lpFile, lpszStr);}SysFree(lpszStr);fclose(lpFile);}读操作#include "apdefap.h"void OnLButtonUp(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y){#pragma option(mbcs)char*shuzhu[6]={"tag_1","tag_2","tag_3","tag_4","tag_5","tag_6"};char tmp[255];int i=0;int ChrNumLine=38;FILE *fp;fp=fopen("D:\\test.txt","r");if (fp==NULL){}else{rewind(fp);while(!feof(fp)){fgets(tmp,ChrNumLine,fp);SetTagChar(shuzhu[i],tmp);i++;}}fclose(fp);}画面窗口显示界面切换SetPictureName(lpszPictureName,"PicWindow_button","pro duce_manage_button.pdl");SetVisible(lpszPictureName,"PicWindow_button",1);注:PicWindow_button是画面窗口名称;produce_manage_button.pdl是要显示的子画面。
WINCC常用脚本说明
Conn.open“Provider=SQLLEDB.1;Integrated Security = SSPI; Persist Security Info = false ; Initial Catalog = CC_OpenArch; Data Source = .\WinCC”
1. BOOL GetHWDiag(LPCTSTR lpszPictureName, LPCTSTR lpszObjectName, LPCTSTR
lpProperties)函数
运行时该函数可实现诊断的直接启动,由事件触发。
2. BOOL GetHWDiagLevel(LPCTSTR lpszPictureName, LPCTSTR lpszObjectName, LPCTSTR
根据在 dwLevel 下面指定的用户管理员功能号为激活的用户执行用 户配置文件级测试。
4. void OnDeactivateExecute()函数 终止 WinCC 时调用该函数。 由于它是标准函数,可以插入指令,然后执行它们。
5. void OnErrorExecute(CCAPErrorExecute ErrorExecute)函数 执行动作或函数而发生错误时由系统调用 OnErrorExecute。 此函数能够确定出错的准确原因。 由系统调用该函数,并且不要求附加的调用命令。 由于包括作为标准函数的此函数,可以改变输出的类型。
5.调用 windows dialog
格式:MsgBox("", vbYesNo, "CONFIRM") 实例:MsgBox("确定工单开始?", vbYesNo, "CONFIRM") = vbYes Then
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
DeactivateRTProject ();//退出系统#pragma code("useadmin.dll")#include"PWRT_api.h"#pragma code()char* CUser=NULL;CUser=GetTagChar("@CurrentUser");if (strlen(CUser)==0){PWRTSilentLogin("operator","123456");//用户“operator",密码"123456”登录}OpenPicture("@MAIN.pdl");}在画面中结合不同按钮来组态下面 C 操作LoginAction for login (for example, "mouse click" event):#pragma code ("useadmin.dll")#include "PWRT_api.h"#pragma code()PWRTLogin('c');LogoutAction for logout (for example, "mouse click" event):#pragma code ("useadmin.dll")#include "PWRT_api.h"#pragma code()PWRTLogout();PWRTLogin 参数必须是CHAR 字符。
它指定了显示对话框的监视器。
如果只使用一个监视器,那么保留默认参数“c”或者指定“1”。
注意可以使用PASSLoginDialog 函数来代替PWRTLogin 或者PWRTLogout 函数。
这个函数需要和函数PWRTLogin 相同的参数。
PWRTLogin 和PASSLoginDialog 函数可以调用登录界面,在上面可以登录或者注销。
函数PWRTLogout 被正确执行并且不调用登录界面。
正确执行后这两个函数都返回“1”。
然而,登录不会等到显示对话框之后。
注意如果使用多个显示器,为了能使登录对话框显示在合适的显示器上,需要WinCC Basic Process Control (OS项目编辑器)。
不使用WinCC Basic Process Control 时,可以指定显示器编号,但登录对话框始终显示在第一个显示器上。
#include"apdefap.h"//调用函数代码void OnClick(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){SetVisible(lpszPictureName,"@ERROR",FALSE); //当前画面上有一个名称为"@ERROR"对象,将其隐藏。
FALSE或者0都可以SetOperation(lpszPictureName,"@LoginIn",TRUE); //函数SetOperation是控制画面对象的可操作性SetOperation(lpszPictureName,"@PasswordIn",TRUE);SetOperation(lpszPictureName,"@OK",TRUE);Set_Focus(lpszPictureName,"@LoginIn"); //次函数表示将光标重新聚焦到当前画面中,名称为“@Loginin”对象中SetVisible(lpszPictureName,lpszObjectName,FALSE);SetVisible函数是用来执行是否显示的函数在利用画面窗口实现画面切换中使用了SetPictureName函数实现画面属性的更改使用了SetPropChar函数SetPictureName("@MAIN.pdl", "Alarm", "AlarmList.pdl"); //调用MAIN中Alarm画面中的AlarmList画面SetProp是一种函数,功能是增加一个新项,修改一个现有项。
实现画面属性的更改使用了SetPropChar函数SetPropChar("@MAIN.pdl","Alarm","CaptionText","报警清单"); //更改MAIN中Alarm画面中标题属性为报警清单SetPropBOOL("@MAIN.Pdl","Alarm","Visible",1);} // MAIN画面中中Alarm对象属性被设置为1SetVisible("@MAIN.pdl","LoginWindow",TRUE);}void Open_AI_Pannel(char *AI_Num,char *TagName,char *Unit) //定义变量//void *可以指向任何类型的数据//Open_AI_Pannel名称{char AI_TemplateName[80]; //80为最大字符长度char str_Title[80];char str_Unit[80];char str_Loop_Name[80];strcpy(AI_TemplateName,"AI_Template");//strcpy复制地址strcat(AI_TemplateName,AI_Num); //strcat两个char类型链接strcpy(str_Title,TagName);strcat(str_Title," AI Loop Control Pannel");SetPropChar("@MAIN.pdl",AI_TemplateName,"CaptionText",str_Title); //置为变量SetPropBOOL("@MAIN.pdl",AI_TemplateName,"Visible",0); //To make the Picture window NO visible //不显示SetPropChar("@MAIN.pdl",AI_TemplateName,"TagPrefix",TagName); //Set the ObjectName as TagPrefix -???¨???¨?oSetPropBOOL("@MAIN.pdl",AI_TemplateName,"Visible",1); //To make the Picture window visible ?-¨strcpy(str_Unit , TagName);strcpy(str_Loop_Name,TagName);//SetPropChar("PID_Pannel.pdl","PidTitle","Text",TagName); //Set the title to the oject name//SetText("PID_Pannel.pdl","Unit01",Unit);//Unit_VL//SetText("PID_Pannel.pdl","Unit02",Unit);//Unit_VLstrcat(str_Unit,"._LOOP_UNIT"),SetTagChar(str_Unit,Unit);//SetPropWord("PID_Pannel.pdl","SetPointBarCtrl","RangeMin",PID_Zero);//strcat(str_Zero,"._PID_ZERO");//SetTagWord(str_Zero,PID_Zero);//SetPropWord("PID_Pannel.pdl","SetPointBarCtrl","RangeMax",PID_Span);//strcat(str_Span,"._PID_SPAN");//SetTagWord(str_Span,PID_Span);//SetPropWord("PID_Pannel.pdl","ProcessValueBarCtrl","RangeMin",PID_Zero);//SetPropWord("PID_Pannel.pdl","ProcessValueBarCtrl","RangeMax",PID_Span);strcat(str_Loop_Name,"._LOOP_NAME");SetTagChar(str_Loop_Name,TagName); //str_Loop_Name=TagName}DOL电机脚本:void Open_Motor_Pannel(char *Pannel_Num,char * Motor_Name){//char pannel_name[80];char tagname[80];char str_Title[80];strcpy(pannel_name,"Motor_Template");strcat(pannel_name,Pannel_Num);//SetPropBOOL("@MAIN.Pdl",pannel_name,"Visible",0);strcpy(tagname,Motor_Name);strcat(tagname,"._MOTOR_NAME"); //._MOTOR_NAME模版变量名SetTagChar(tagname,Motor_Name);SetPropChar("@MAIN.pdl",pannel_name,"TagPrefix",Motor_Name); //TagPrefix变量前缀SetPropChar("@MAIN.pdl",pannel_name,"PictureName","Motor_Pannel.pdl");//画面名称strcpy(str_Title,Motor_Name);strcat(str_Title," MOTOR Control Pannel");SetPropChar("@MAIN.Pdl", pannel_name,"CaptionText",str_Title);SetPropBOOL("@MAIN.Pdl",pannel_name,"Visible",1); //让画面窗口可见PID模版void Open_PID_Pannel(char *PID_Num,char *TagName,char *Unit){char PID_TemplateName[80];char str_Title[80];char str_Unit[80];char str_Loop_Name[80];strcpy(PID_TemplateName,"PID_Template");strcat(PID_TemplateName,PID_Num);strcpy(str_Title,TagName);strcat(str_Title," PID Loop Control Pannel");SetPropChar("@MAIN.pdl",PID_TemplateName,"CaptionText",str_Title); //±êìa??±?SetPropBOOL("@MAIN.pdl",PID_TemplateName,"Visible",0); //To make the Picture window NO visible ?-??2??é??£??é2?ó?SetPropChar("@MAIN.pdl",PID_TemplateName,"TagPrefix",TagName); //Set the ObjectName as TagPrefix -??μ?±?á??ó?°×oSetPropBOOL("@MAIN.pdl",PID_TemplateName,"Visible",1); //To make the Picture window visible ?-é??strcpy(str_Unit , TagName);strcpy(str_Loop_Name,TagName);//SetPropChar("PID_Pannel.pdl","PidTitle","Text",TagName); //Set the title to the oject name//SetText("PID_Pannel.pdl","Unit01",Unit);//Unit_VL//SetText("PID_Pannel.pdl","Unit02",Unit);//Unit_VLstrcat(str_Unit,"._LOOP_UNIT"),SetTagChar(str_Unit,Unit);//SetPropWord("PID_Pannel.pdl","SetPointBarCtrl","RangeMin",PID_Zero);//strcat(str_Zero,"._PID_ZERO");//SetTagWord(str_Zero,PID_Zero);//SetPropWord("PID_Pannel.pdl","SetPointBarCtrl","RangeMax",PID_Span);//strcat(str_Span,"._PID_SPAN");//SetTagWord(str_Span,PID_Span);//SetPropWord("PID_Pannel.pdl","ProcessValueBarCtrl","RangeMin",PID_Zero); //SetPropWord("PID_Pannel.pdl","ProcessValueBarCtrl","RangeMax",PID_Span); strcat(str_Loop_Name,"._LOOP_NAME");SetTagChar(str_Loop_Name,TagName); //str_Loop_Name=TagName。