wincc常用C脚本功能

wincc常用C脚本功能
wincc常用C脚本功能

.用户注销:

#pragma code ("")

#include ""

#pragma code()

PWRTLogout();

2.用户登录:

#pragma code ("")

#include ""

#pragma code()

PWRTLogin('c');

3.关闭项目并退出wincc:

ExitWinCC ();

4.退出运行到wincc资源管理器:

DeactivateRTProject ();

按钮变三种颜色

#include ""

long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName)

{

#pragma option(mbcs)

if(GetTagWord("TX/ZSH001")==1)

return 0x0000ff00;

else

if(GetTagWord("TX/ZSL001")==1)

return 0x000000ff;

else

return 0x00c0c0c0;

}

一个调用按钮变色

#include ""

long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName)

{

#pragma option(mbcs)

if(GetTagWord("NewTag")==0)

return 0x0000ff00;

else

return 0x00ffffff;

}

5.结束监控并关闭计算机(会弹出确认对话框)

HWND hWnd = NULL;击事件弹出对话框,通过点击弹出对话框的确定和取消按钮实现对变量的置位或取消:

int r;

r=MessageBox(NULL, "YES为开,NO为关", "确定开命令:",

MB_YESNO |MB_SYSTEMMODAL);

if (r==IDYES)

SetTagBit("TAGNAME",TRUE);

else

SetTagBit("TAGNAME",FALSE);

7.开显示关显示:(要在内部变量中建立三个二进制变量COLSE_DISPLAY、DISPLAY_NO和DISPLAY_COMMENT)

阀确认:

BOOL a;

a=GetTagBit("30T制水启动"); WinCC运行画面最小化

HWND WinCCHwnd;

WinCCHwnd=FindWindow(NULL,"WinCC-Runtime - "); 示或不显示(其中hiddVtext为内部的二进制变量)

if(GetTagBit("hiddVtext")==0) 开编辑画面的脚本

#pragma option(mbcs)

#ifdef RUN_ON_WEBNAVIGATOR

#else

HWND hExplorerWindow= NULL;

HWND hRuntimeWindow= NULL;

hExplorerWindow=

FindWindow("WinCCExplorerFrameWndClass",NULL);

hRuntimeWindow=

FindWindow("PDLRTisAliveAndWaitsForYou",NULL);

if(hExplorerWindow)

{

ShowWindow(hExplorerWindow, SW_MINIMIZE); 何在WINCC 中制作一个保持型按钮

方法1:

if( GetTagBit("M10") )

SetTagBit("M10",0);

else

SetTagBit("M10",1);

方法2:

SetTagBit("",(SHORT)!GetTagBit(""));

求反指令,如果为1点击变为0,

如果为0点击变为1

方法3:

或者做两个按钮,

按钮一:显示,直接连接,是--不显示,否--显示。事件,直接连接,源,常数1,变量;

按钮二:事件,直接连接,源,常数0,变量;

用按钮一覆盖按钮二

12变量每秒加1

DWORD a;

a=GetTagDWord("Tank");

a+=1;

if(a>100) (a=0);

SetTagDWord("Tank",a);

return 0;

}

WINCC动画脚本

电机风扇旋转(几何---起始角度):

#include ""

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 ""

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 ""

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 ""

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 ""

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 ""

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 ""

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->t m_sec);

return(p);

}

登陆到指定的用户名无须手动输入(按钮操作)

#include ""

void OnLButtonDown(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y) {

#pragma code("")

#include ""

#pragma code()

PWRTSilentLogin("用户名", "口令");

}

**显示登陆对话框无须热键(按钮操作)**

#include ""

void OnLButtonDown(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y) {

#pragma code ("")

#include ""

#pragma code( )

PWRTLogin('c');

}

退出WINCC运行(按钮操作)

#include ""

void OnLButtonDown(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y) {

{

DeactivateRTProject ();

}

}

单位递增按钮(到上限不提示出错)

#include ""

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 ""

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 ""

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 ""

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 ""

long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName)

{

#pragma code("")

#include ""

#pragma code()

PWRTSilentLogin("用户名", "口令");

return(0X0);

}

**询问框(最好用于单机启动,组启也可,2个按钮,NO不操作)**

#include ""

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));

}

else

MessageBox(hWnd,"电源未备妥,请查证后重试!","启动!", MB_OK|MB_ICONHAND|MB_APPLMODAL);

}

**询问框(最好用于单机启动,组启也可,3个按钮,NO复位)**

#include ""

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));

}

}

else

MessageBox(hWnd," 电源未备妥,请查证后重试!","启动!", MB_OK|MB_ICONHAND|MB_APPLMODAL);

}

**搅拌器左侧扇页(几何—宽度)**

#include ""

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;

相关主题
相关文档
最新文档