您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 销售管理 > wincc常用C脚本
.用户注销:#pragmacode(useadmin.dll)#includePWRT_api.h#pragmacode()PWRTLogout();2.用户登录:#pragmacode(useadmin.dll)#includePWRT_api.h#pragmacode()PWRTLogin('c');3.关闭项目并退出wincc:ExitWinCC();4.退出运行到wincc资源管理器:DeactivateRTProject();按钮变三种颜色#includeapdefap.hlong_main(char*lpszPictureName,char*lpszObjectName,char*lpszPropertyName){#pragmaoption(mbcs)if(GetTagWord(TX/ZSH001)==1)return0x0000ff00;elseif(GetTagWord(TX/ZSL001)==1)return0x000000ff;elsereturn0x00c0c0c0;}一个调用按钮变色#includeapdefap.hlong_main(char*lpszPictureName,char*lpszObjectName,char*lpszPropertyName){#pragmaoption(mbcs)if(GetTagWord(NewTag)==0)return0x0000ff00;elsereturn0x00ffffff;}5.结束监控并关闭计算机(会弹出确认对话框)HWNDhWnd=NULL;//Author:SmartsysintiRet;hWnd=FindWindow(NULL,WinCC-运行系统-);iRet=MessageBox(hWnd,结束监控并关闭计算机,关闭操作站,MB_YESNO|MB_ICONWARNING|MB_APPLMODAL);if(iRet==IDYES)DMExitWinCCEx(DM_SDMODE_POWEROFF);6.点击事件弹出对话框,通过点击弹出对话框的确定和取消按钮实现对变量的置位或取消:intr;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:BitinDoppelwortsetzen;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.开阀确认:BOOLa;a=GetTagBit(30T制水启动);//Return-Type:shortintif(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运行画面最小化HWNDWinCCHwnd;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.打开编辑画面的脚本#pragmaoption(mbcs)#ifdefRUN_ON_WEBNAVIGATOR#elseHWNDhExplorerWindow=NULL;HWNDhRuntimeWindow=NULL;hExplorerWindow=FindWindow(WinCCExplorerFrameWndClass,NULL);hRuntimeWindow=FindWindow(PDLRTisAliveAndWaitsForYou,NULL);if(hExplorerWindow){ShowWindow(hExplorerWindow,SW_MINIMIZE);//ThisentryisonlynecessaryforWindows2000ShowWindow(hExplorerWindow,SW_SHOWNORMAL);SetForegroundWindow(hExplorerWindow);}elseprintf(rnSetForegroundfailed);#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,变量M1.0;按钮二:事件,直接连接,源,常数0,变量M1.0;用按钮一覆盖按钮二12变量每秒加1DWORDa;a=GetTagDWord(Tank);a+=1;if(a100)(a=0);SetTagDWord(Tank,a);return0;}WINCC动画脚本电机风扇旋转(几何---起始角度):#includeapdefap.hlong_main(char*lpszPictureName,char*lpszObjectName,char*lpszPropertyName){staticDWORDf=20;if(GetTagBit(DI电机运行信号)){f=f+30;if(f==360)(f=0);}returnf;}电机风扇旋转(几何---结束角度):#includeapdefap.hlong_main(char*lpszPictureName,char*lpszObjectName,char*lpszPropertyName){staticDWORDi=80;if(GetTagBit(DI电机运行信号)){i=i+30;if(i==360)(i=0);}returni;}**物料水平右移动(几何---位置X)(停车后,物料回到原点)**#includeapdefap.hlong_main(char*lpszPictureName,char*lpszObjectName,char*lpszPropertyName){staticinta=350;if(GetTagBit(DI电机运行信号)&&(a=730)){a+=20;if(a=720)(a=350);}if(!GetTagBit(DI电机运行信号))(a=350);returna;}物料水平右移动(几何---位置X)(停车后,物料停在该点)#includeapdefap.hlong_main(char*lpszPictureName,char*lpszObjectName,char*lpszPropertyName){staticinta=350;if(GetTagBit(DI电机运行信号)&&(a=730)){a+=20;if(a=720)(a=350);}returna;}物料向上移动(几何---位置Y)(停车后,物料停在该点)#includeapdefap.hlong_main(char*lpszPictureName,char*lpszObjectName,char*lpszPropertyName){staticintb=450;if(GetTagBit(DI电机运行信号)&&(b=290)){b-=10;if(b=280)(b=450);}returnb;}年月日(静态文本)#includeapdefap.hchar*_main(char*lpszPictureName,char*lpszObjectName,char*lpszPropertyName){time_ttimer;structtm*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);}时分秒(静态文本)#includeapdefap.hchar*_main(char*lpszPictureName,char*lpszObjectName,char*lpszPropertyName){time_ttimer;structtm*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);}登陆到指定的用户名无须手动输入(按钮操作)#includeapdefap.hvoidOnLButtonDown(char*lpszPictureName,char*lpszObjectName,char*lpszPropertyName,UINTnFlags,intx,inty){#pragmacode(useadmin.dll)#includePWRT_API.H#pragmacode()PWRTSilentLogin(用户名,口令);}**显示登陆对话框无须热键(按钮操作)**#includeapdefap.hvoidOnLButtonDown(char*lpszPictureName,char*lpszObjectName,char*lpszPropertyName,UINTnFlags,intx,inty){#pragmacode(useadmin.dll)#includePWRT_api.h#pragmacode()PWRTLogin('c');}退出WINCC运行(按钮操作)#includeapdefap.hvoidOnLButtonDown(char*lpszPictureName,char*lpszObjectName,char*lpszPropertyName,UINTnFlags,intx,inty){{DeactivateRTProject();}}单位递增按钮(到上限不提示出错)#includeapdefap.hvoidOnClick(cha
本文标题:wincc常用C脚本
链接地址:https://www.777doc.com/doc-4297534 .html