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-脚本大全
{
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-全套脚本总结
——————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脚本功能
..用户注销:#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.关闭项目并退出winccExitWinCC ();wincc资源管理器:退出运行到4.DeactivateRTProject ();按钮变三种颜色#include apdefap.hlong _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){#pragma option(mbcs)if(GetTagWord(TX/ZSH001)==1)文档Word.return 0x0000ff00;elseif(GetTagWord(TX/ZSL001)==1)return 0x000000ff;elsereturn 0x00c0c0c0;}一个调用按钮变色#include apdefap.hlong _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){#pragma option(mbcs)if(GetTagWord(NewTag)==0)return 0x0000ff00;elsereturn 0x00ffffff;}文档Word.5.结束监控并关闭计算机(会弹出确认对话框)HWND hWnd = NULL;//Author:Smartsysint iRet;- ); 运行系统hWnd = FindWindow(NULL,WinCC-,结束监控并关闭计算机剩瑥?獥慳敧潂?坨摮尬,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.: )DISPLAY_NO和DISPLAY_COMMENT、COLSE_DISPLAY// Funktion: Bit in Doppelwort setzen;if (GetTagBitWait(COLSE_DISPLAY)==1 ){SetTagBit(COLSE_DISPLAY,0);文档Word.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;); //Return-Type :short int a=GetTagBit(T制水启动if (a==0){操作提示?晩?獥慳敧潂?啎?尬真的要启动制水吗?,MB_YESNO|MB_ICONQUESTION|MB_SETFOREGROUND|MB_SY STEMMODAL) == 6),1); { SetTagBit(T制水启动//Return-Type :BOOL}}else操作提示?真的要停止制水吗?楻?敍獳条?硯丨??文档Word.,MB_YESNO|MB_ICONQUESTION|MB_SETFOREGROUND|MB_SYSTE MMODAL) == 6),1); 制水停止{ SetTagBit(T}}运行画面最小化将WinCC9.HWND WinCCHwnd;如果运行语WinCCHwnd=FindWindow(NULL,WinCC-Runtime - ); //言为英文运行if (WinCCHwnd==0)WinCCHwnd=FindWindow(NULL,WinCC- 如果运行语言为中文系统- ); //CloseWindow(WinCCHwnd);hiddVtext为内部的二进制变量)10.显示或不显示(其中if(GetTagBit(hiddVtext)==0) //Return-Type: BOOL{SetTagBit(hiddVtext,TRUE); //Return-Type: BOOL//Return-Type: BOOL}else{SetTagBit(hiddVtext,FALSE);}文档Word.打开编辑画面的脚本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 2000 ShowWindow(hExplorerWindow, SW_SHOWNORMAL); SetForegroundWindow(hExplorerWindow);}elseprintf(n SetForeground failed);#endif中制作一个保持型按钮11.如何在WINCC :1方法文档Word .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脚本
Wincc常用C脚本WINCC动画脚本电机风扇旋转(几何---起始角度):#include "apdefap.h"long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName) {static DWORD f=20;if (GetTagBit("DI电机运行信号")) {f= f+30;if (f==360) (f=0);}return f;}电机风扇旋转(几何---结束角度):#include "apdefap.h"long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName) {static DWORD i=80;if (GetTagBit("DI电机运行信号")) {i = i+30;if (i==360) (i=0);}return i;}**物料水平右移动(几何---位置X)(停车后,物料回到原点)**#include "apdefap.h"long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName) {static int a=350;if (GetTagBit("DI电机运行信号") && (a<=730)) {a+=20;if (a>=720) (a=350);}if (!GetTagBit("DI电机运行信号")) (a=350);return a;}物料水平右移动(几何---位置X)(停车后,物料停在该点)#include "apdefap.h"long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName) {static int a=350;if (GetTagBit("DI电机运行信号") && (a<=730)) {a+=20;if (a>=720) (a=350);}return a;}物料向上移动(几何---位置Y)(停车后,物料停在该点)#include "apdefap.h"long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName) {static int b=450;if (GetTagBit("DI电机运行信号") && (b>=290)) {b-=10;if (b<=280) (b=450);}return b;}年月日(静态文本)#include "apdefap.h"char* _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName) {time_t timer ;struct tm *ptm;char *p;time(&timer);ptm =localtime(&timer);p =SysMalloc(9);sprintf(p,"%04d/%02d/%02d",ptm->tm_year-100+2000,ptm->tm_mon+1,ptm->tm_mday); return(p);}时分秒(静态文本)#include "apdefap.h"char* _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){time_t timer ;struct tm *ptm;char *p;time(&timer);ptm =localtime(&timer);p =SysMalloc(9);sprintf(p,"%02d:%02d:%02d",ptm->tm_hour,ptm->tm_min, ptm->tm_sec);return(p);}登陆到指定的用户名无须手动输入(按钮操作)#include "apdefap.h"void OnLButtonDown(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y)#pragma code("useadmin.dll")#include "PWRT_API.H"#pragma code()PWRTSilentLogin("用户名", "口令");}**显示登陆对话框无须热键(按钮操作)**#include "apdefap.h"void OnLButtonDown(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y){#pragma code ("useadmin.dll")#include "PWRT_api.h"#pragma code( )PWRTLogin('c');}退出WINCC运行(按钮操作)#include "apdefap.h"void OnLButtonDown(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y){DeactivateRTProject ();}}单位递增按钮(到上限不提示出错)#include "apdefap.h"void OnClick(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName) {DWORD value;value=GetTagDWord("AI标签");if (value>90) (value=上限);else value=value+10;SetTagDWord("AI标签",value);}单位递减按钮(到下限不提示出错)#include "apdefap.h"void OnClick(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName) {DWORD value;value=GetTagDWord("AI标签");if (value<10) (value=下限);else value=value-10;SetTagDWord("AI标签",value);}**单位递增按钮(到上限提示出错)**#include "apdefap.h"void OnClick(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){DWORD value;HWND hWnd=NULL ;hWnd=FindWindow(NULL,"Wincc-运行系统- ");value=GetTagDWord("AI标签");if (value<=90) (value=value+10);else MessageBox(hWnd,"已到达上限值!","错误",MB_OK|MB_ICONWARNING|MB_APPLMODAL);SetTagDWord("AI标签",value);}**单位递减按钮(到下限提示出错)**#include "apdefap.h"void OnClick(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){DWORD value;HWND hWnd=NULL ;hWnd=FindWindow(NULL,"Wincc-运行系统- ");value=GetTagDWord("AI标签");if (value>0) (value=value-10);else MessageBox(hWnd," 已到达下限值!"," 错误",MB_OK|MB_ICONWARNING|MB_APPLMODAL);SetTagDWord("AI标签",value);}**自动登陆到指定的用户(画面属性--其它—**)**#include "apdefap.h"long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){#pragma code("useadmin.dll")#include "PWRT_API.H"#pragma code()PWRTSilentLogin("用户名", "口令");return(0X0);}**询问框(最好用于单机启动,组启也可,2个按钮,NO不操作)**#include "apdefap.h"void OnLButtonDown(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y){HWND hWnd=NULL;int 上位启动信号;hWnd=FindWindow(NULL,"WinCC C-Course");if (GetTagBit("DI备妥")){上位启动信号=MessageBox(hWnd,"电源已备妥,您现在确定要启动吗?","启动!",MB_YESNO|MB_ICONQUESTION|MB_APPLMODAL);printf("\r\nExample 3\r\n");if (上位启动信号==IDNO) (printf("User selected NO button \r\n"));else (SetTagByte("上位启动信号",1));}elseMessageBox(hWnd,"电源未备妥,请查证后重试!","启动!", MB_OK|MB_ICONHAND|MB_APPLMODAL);}**询问框(最好用于单机启动,组启也可,3个按钮,NO复位)**#include "apdefap.h"void OnLButtonDown(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y){HWND hWnd=NULL;int上位启动信号;hWnd=FindWindow(NULL,"WinCC C-Course");if (GetTagBit("DI备妥")){上位启动信号=MessageBox(hWnd," 电源已备妥,您现在确定要启动吗?","启动!",MB_YESNOCANCEL|MB_ICONQUESTION|MB_APPLMODAL);if (上位启动信号==IDCANCEL) (printf("User selected NO button \r\n"));else{if (上位启动信号==IDYES) (SetTagByte("上位启动信号",1));else (SetTagByte("上位启动信号",0));}}elseMessageBox(hWnd," 电源未备妥,请查证后重试!","启动!", MB_OK|MB_ICONHAND|MB_APPLMODAL);}**搅拌器左侧扇页(几何—宽度)**#include "apdefap.h"long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName) {static int h=50;static int u=0;if (GetTagBit("DI电机运行信号")) {if ((h>0)&&(h<=50)){(h-=2);return h;}if ((u>=0)&&(u<50)){(u+=2);return u;}u=0;h=50;return h;return u;}if (!GetTagBit("DI电机运行信号")){ h=50;u=0;return h;return u;}}**搅拌器左侧扇页(几何—位置X,右侧扇页没有位置变化)** #include "apdefap.h"long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName) {static int h=75;static int u=125;if (GetTagBit("DI电机运行信号")){if ((h>=75)&&(h<125)){(h+=2);return h;}if ((u<=125)&&(u>75)){(u-=2);return u;}u=125;h=75;return h;return u;}if (!GetTagBit("DI电机运行信号")){h=75;u=125;return h;return u;}}**显示层按钮**SubX6309X94AE2X0000X0000_X6309X94AE2X0000X60C5_X630 9X94AE2X0000X653E_OnLB uttonDown(ByV al Item, ByV al Flags, ByV al x, ByV al y)Dim objScreenDim CountLayerSet objScreen = HMIRuntime.Screens("layer")For CountLayer=1 To 32 Step 1/doc/b84310496.html,yers(CountLaye r).Visible = vbFalseNext/doc/b84310496.html,yers(n).Visible = vbTrueEnd Subn=层数+1初始画面程序(画面空地--属性--事件--其它--打开画面--动作)**打印按钮**#include "apdefap.h"void OnLButtonDown(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y){WinExec("PRTSCR.EXE -hardcopy",SW_SHOWNORMAL);}**一个圈代表电机两种状态**#include "apdefap.h"void OnClick(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){char* opentag="DI1电机运行信号";char* closetag="DI2电机运行信号";BOOL open,close;open = GetTagBit(opentag);close = GetTagBit(closetag);if (open)return CO_GREEN;if (close)return CO_BLUE; }。
wincc 全套脚本总结
} -------------------------------------
——————6、时间同步——————
void SetCpuTime() { #pragma code("kernel32.dll"); void GetLocalTime(SYSTEMTIME *lpst); #pragma code(); SYSTEMTIME time BOOL ret; //printf("Start function SetCpuTime\r\n"); GetLocalTime(&time); ret= SetTagMultiWait("%d%d%d%d%d%d%d",
"data_FLAG",1
) }
-------------------------------------
——————7、对话框调用——————
BOOL A; BOOL B; HWND hwnd=NULL; int RetMsg; A=GetTagBit("TJ_ANNIU"); //Return-Type: BOOL hwnd=FindWindow(NULL,"WinCC-运行系统 - "); if (A==0)
MB_OK|MB_SYSTEMMODAL|MB_SETFOREGROUND); SetTagBit("TJ_ANNIU",0);
} else B=0; } else { } ------------------------------------------
——————8、声音报警——————
#pragma code("Winmm.dll") VOID WINAPI PlaySoundA(char* pszSound,char* hmode,DWORD dwflag); #pragma code()
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 <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_button.pdl"); SetVisible(lpszPictureName,"PicWindow_button",1);注:PicWindow_button是画面窗口名称;produce_manage_button.pdl是要显示的子画面。
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常用脚本说明
GetTagByte("WSJ_A_OFWO5");
4.写变量赋值
格式:SetTagByte("",); 实例:SetTagByte("WSJ_A_GDBL",1);
SetTagByte("WSJ_A_OFWO5",1);
setobjcommandnothingobjconnectionclosesetobjrnothingsetobjconnection数据库存储过程操作objcommandcommandtextwsjreport?gdh1??bc1??pch1??ph1??silo1?cl1?cstrnow?3wsjreport?gdh??bc??pch??ph??silo?cl?cstrnow?3?msgbox1bks?objcommandexecute定义变量格式
三、 动态对话框
函数判断取值
实 例 : ('C_SA509_CASING_CUR_1'<=63 || 'C_SA509_CASINபைடு நூலகம்_CUR_2'<=63 || 'C_SA509_CASING_CUR_3'<=63) && 'C_SA509_STATE'==1
四、 WinCC 组包含影响整个 WinCC 系统的函数
实例:Set conn = CreateObject(“ADODB.Connection”)
Conn.open“Provider=SQLLEDB.1;Integrated Security = SSPI; Persist Security Info = false ; Initial Catalog = CC_OpenArch; Data Source = .\WinCC”
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脚本
查看文章wincc常用C动作2010-06-27 10:311.用户注销:#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 ();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("\r\n 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脚本及常用功能
打开用户管理器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脚本
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,是--不显示,否--显示。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
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.
----------------------------------------------
if ( nChar==13 )//if press enter
{
int xRet = MessageBox(NULL,szBuffer,"确认窗口",MB_YESNO|MB_ICONQUESTION|MB_SYSTEMMODAL);//message
if ( xRet == IDYES )//confirm operate
char *pold_pass=NULL;
char *pnew_pass=NULL;
char *pconfirm=NULL;
char old_pass[51];
char new_pass[51];
char confirm[51];
long int ret;
BOOL ret2;
memset(&pr_info,0,sizeof(DM_PROJECT_INFO));
//Get the differents strings old, new password and confirmation
pold_pass=GetPropChar(lpszPictureName,"IOField_OldPassWord","OutputValue");
pnew_pass=GetPropChar(lpszPictureName,"IOField_NewPassWord","OutputValue");
(4)确认按钮(C)
#pragma code ("usegen.dll")
#include "usegenap.h"
#pragma code ()
HWND Handle;
DM_PROJECT_INFO pr_info;
DM_DIRECTORY_INFO dir_info;
CMN_ERROR error;
----------------------------------------------
4、单键的置位与复位(C)
BOOL Z;
Z=GetTagBit("TAG");
if(Z==0) SetTagBit("TAG",1);
else SetTagBit("TAG",0);
----------------------------------------------
9、通过按钮实现用户登录(C)
#pragma code("useadmin.dll")
#include "PWRT_API.H"
#pragma code()
PWRTLogin('1');
pconfirm=GetPropChar(lpszPictureName,"IOField_Confirmation","OutputValue");
strncpy(old_pass,pold_pass,50);
strncpy(new_pass,pnew_pass,50);
strncpy(confirm,pconfirm,50);
注:1、选中[计算机],然后在左边选择当前项目的服务器名,双击弹出项目的[计算机属性]对话框。选择最后一栏[运行系统],里面就有一个[监视器键盘],用来实现无键盘WinCC全屏运行时数值输入的;
2、如果想使用系统的虚拟键盘,可以用按钮的点击事件的C代码,添加以上代码。
3、如果想要手写输入,就安装Tablet PC面板组建来实现了。
12、WINCC在线修改用户密码
(1)旧密码设置(C)
SetOutputValueChar(lpszPictureName,lpszObjectName,GetInputValueChar(lpszPictureName,lpszObjectName));
注:字符串格式的输入输出域》事件》属性主题》输出/输入》输出值》更改》以上代码。
4、在同一个输入/输出域的事件,选择 键盘--释放--C动作,输入以上代码。
----------------------------------------------
6、VBS弹出提示小窗口(VB)
Dim a
Dim objCon2
Set objCon2 = HMIRuntime.ActiveScreen.ScreenItems("按钮1")
memset(&dir_info,0,sizeof(DM_DIRECTORY_INFO));
//this line is necessary when you want to have a realy modal message box
Handle = FindWindow("PDLRTisAliveAndWaitsForYou",NULL);
(3)新密码确认设置(C)
SetOutputValueChar(lpszPictureName,lpszObjectName,GetInputValueChar(lpszPictureName,lpszObjectName));
注:字符串格式的输入输出域》事件》属性主题》输出/输入》输出值》更改》以上代码。
ret2=DMGetRuntimeProject(pr_info.szProjectFile,sizeof(pr_info.szProjectFile),NULL);
ret2=DMGetProjectInformation(pr_info.szProjectFile,&pr_info,NULL);
{
SetTagWord("DisplayValue",TempValue);// set data
}
}
注:1、DisplayValue是实际需要控制的变量,TempValue作为临时变量使用。
2、新建一个输入/输出域,在输出值处打开动态对话框。选择DisplayValue
3、在同一个输入/输出域的事件,选择 输出/输入--输入值--直接连接 ,选择直接连接到临时变量TempValue
tag=GetTagByte("tag1");
tag=tag-1;
SetTagByte("tag1",tag);
----------------------------------------------
3、颜色改变(VB)
ScreenItems("Rectangle1").BackColor = RGB(255,0,0)
1、变量自加1(C)
int tag;
tag=GetTagByte("tag1");
tag=tag+1;
SetTagByte("tag1",tag);
----------------------------------------------
2、变量自减1(C)
int tag;
ret2=PWGENChangePassword (GetTagChar("@CurrentUser"),old_pass,new_pass,&error);
----------------------------------------------
5、输入/输出域实现带确认的输入操作(C)
int TempValue=GetTagWord("TempValue");
char szBuffer[20];
sprintf( szBuffer,"Input number:%d",TempValue);
MB_ICONEXCLAMATION | MB_SYSTEMMODAL);