wincc-常用C脚本_第1页
wincc-常用C脚本_第2页
wincc-常用C脚本_第3页
wincc-常用C脚本_第4页
wincc-常用C脚本_第5页
已阅读5页,还剩9页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、,word 一,完美整理版.用户注销:#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资源管理器: DeactivateRTPro

2、ject ();按钮变三种颜色#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;一个调用按钮变色#includ

3、e "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:Smartsys int iRet;hWnd = FindWindow(NULL,"WinCC-

4、运行系统-");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_YESN|MB_SYSTEMMODAL); if (r=IDYES) Set

5、TagBit("TAGNAME",TRUE);elseSetTagBit("TAGNAME",FALSE);7 .开显示关显示:(要在内部变量中建立三个二进制变量COLSE_DISPLAY DISPLAY_NODISPLAY_COMME NT/ Funktion: Bit in Doppelwort setzen;if (GetTagBitWait("COLSE_DISPLAY")=1 )SetTagBit("COLSE_DISPLAY",0);SetTagBit("DISPLAY_NO",0)

6、; /Return-Type: BOOL SetTagBit("DISPLAY_COMMENT",0); elseSetTagBit("COLSE_DISPLAY",1);SetTagBit("DISPLAY_NO",1); /Return-Type: BOOL SetTagBit("DISPLAY_COMMENT",0);8 .开阀确认:BOOL a;a=GetTagBit("30T 制水启动");/Return-Type :short int if (a=0) if(MessageBox(N

7、ULL," 真的要启动制水吗?","操作提示 ”,MB_YESNO|MB_ICONQUESTION|MB_SETFOREGROUND|MB_SYSTEMMODAL) = 6) SetTagBit("30T 制水启动",1);/Return-Type :BOOL elseif(MessageBox(NULL,” 真的要停止制水吗?","操作提示”,MB_YESNO|MB_ICONQUESTION|MB_SETFOREGROUND|MB_SYSTEMMODAL) = 6) SetTagBit("30T制水停止”,1);

8、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(

9、"hiddVtext",TRUE); /Return-Type: BOOL /Return-Type: BOOL elseSetTagBit("hiddVtext",FALSE); 11 .打开编辑画面的脚本#pragma option(mbcs)#ifdef RUN_ON_WEBNAVIGATOR#elseHWND hExplorerWindow= NULL;HWND hRuntimeWindow= NULL;hExplorerWindow= FindWindow("WinCCExplorerFrameWndClass",NULL)

10、;hRuntimeWindow= FindWindow("PDLRTisAliveAndWaitsForYou",NULL); if(hExplorerWindow) ShowWindow(hExplorerWindow, SW_MINIMIZE); / This entry is onlynecessary for Windows 2000ShowWindow(hExplorerWindow, SW_SHOWNORMAL); SetForegroundWindow(hExplorerWindow); elseprintf("rn SetForeground fa

11、iled");#endif12 .如何在 WINCW制作一个保持型按钮 方法1:if( GetTagBit("M10") SetTagBit("M10",0);else SetTagBit("M10",1);方法2:SetTagBit("M1.0",(SHORT)!GetTagBit("M1.0");求反指令,如果为1点击变为0,如果为0点击变为1方法3:或者做两个按钮,按钮一:显示,直接连接 m1.0,是-不显示,否-显示。事件,直接连接,源, 常数1,变量M1.0;按钮二:事件,直

12、接连接,源,常数 0,变量M1.0;用按钮一覆盖按钮二12变量每秒加1DWORD a;a=GetTagDWord("Tank");a+=1;if(a>100) (a=0);SetTagDWord("Tank",a);return 0;WINCC动画脚本电机风扇旋转(几何-起始角度):#include "apdefap.h"long _main(char* lpszPictureName, char* lpszObjectName, char*lpszPropertyName)static DWORD f=20;if (GetTa

13、gBit("DI电机运行信号")f= f+30;if (f=360) (f=0);return f;电机风扇旋转(几何-结束角度):#include "apdefap.h"long _main(char* IpszPictureName, char* IpszObjectName, char*IpszPropertyName)static DWORD i=80;if (GetTagBit("DI电机运行信号")i = i+30;if (i=360) (i=0);return i;*物料水平右移动(几何-位置X)(停车后,物料回到原点)

14、*#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

15、 "apdefap.h"long _main(char* IpszPictureName, char* IpszObjectName, char*IpszPropertyName)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* lpszPictureNam

16、e, 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

17、 *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* IpszPictureName, char* IpszObjectName, char*IpszPropertyName)t

18、ime_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* lpszObject

19、Name, 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* IpszPictureName, char* IpszObjectName, char

20、* IpszPropertyName, 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* IpszPictureName, char* IpszObjectName, char* IpszPropertyName, UINT nFlags, i

21、nt x, int y)DeactivateRTProject ();单位递增按钮(到上限不提示出错)#include "apdefap.h"void OnCIick(char* IpszPictureName, char* IpszObjectName, char*IpszPropertyName)DWORD vaIue;vaIue=GetTagDWord("AI标签");if (vaIue>90) (vaIue= 上限);else value=value+10;SetTagDWord("AI标签",value);单位递减按钮

22、(到下限不提示出错)#include "apdefap.h"void OnClick(char* IpszPictureName, char* IpszObjectName, char*IpszPropertyName)DWORD value;value=GetTagDWord("AI标签");if (value<10) (value= 下限);else value=value-10;SetTagDWord("AI标签",value);* *单位递增按钮(到上限提示出错)单位递减按钮(到下限提示出错)*#include &quo

23、t;apdefap.h"#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,”已到达上限值

24、!","错误”,MB_OK|MB_ICONWARNING|MB_APPLMODAL);SetTagDWord("AI标签",value);void OnClick(char* IpszPictureName, char* IpszObjectName, char*IpszPropertyName)DWORD value;HWND hWnd=NULL ;hWnd=FindWindow(NULL,"Wincc-运行系统-");value=GetTagDWord("AI标签");if (value>0) (valu

25、e=value-10);else MessageBox(hWnd,"已到达下限值!","错误”,MB_OK|MB_ICONWARNING|MB_APPLMODAL);SetTagDWord("AI 标签",value);* *自动登陆到指定的用户(画面属性-其它一授权)询问框(最好用于单机启动,组启也可,2个按钮,NO不操作)*#include "apdefap.h"void OnLButtonDown(char* lpszPictureName, char* lpszObjectName,char* lpszPropert

26、yName, UINT nFlags, int x, int y)HWND hWnd=NULL;int上位启动信号;#include "apdefap.h"long _main(char* lpszPictureName, char* lpszObjectName, char*lpszPropertyName)#pragma code("useadmin.dll")#include "PWRT_API.H"#pragma code()PWRTSilentLogin(" 用户名","口令)return(0X

27、0);hWnd=FindWindow(NULL,"WinCC C-Course");if (GetTagBit("DI 备妥")上位启动信号=MessageBox(hWnd,"电源已备妥,您现在确定要启动吗?","启动!",MB_YESNO|MB_ICONQUESTION|MB_APPLMODAL);printf("rnExample 3rn");if (上位启动信号=IDNO) (printf("User selected NO button r'n");else

28、(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

29、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 buttonrn");elseif (上位启动

30、信号=IDYES) (SetTagByte("上位启动信号",1);else (SetTagByte("上位启动信号",0); else MessageBox(hWnd,"电源未备妥,请查证后重试!","启动!",MB_OK|MB_ICONHAND|MB_APPLMODAL);*搅拌器左侧扇页(几何一宽度)*#include "apdefap.h"long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyN

31、ame)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+

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论