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常用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常用 脚本
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-全套脚本总结
——————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常用脚本说明
GetTagByte("WSJ_A_OFWO5");
4.写变量赋值
格式:SetTagByte("",); 实例:SetTagByte("WSJ_A_GDBL",1);
SetTagByte("WSJ_A_OFWO5",1);
c) 使用 VBS 脚本通过 ODBC 访问数据库
1) 连接数据库:
实例: YX = HMIRuntime.Tags("CP_A_GDH").READ
strConnectiOnString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=dbzs1;Password=dbzs1;Initial Catalog=DBZS1;Data Source=10.65.248.20\WINCC"
5.调用 windows dialog
格式:MsgBox("", vbYesNo, "CONFIRM") 实例:MsgBox("确定工单开始?", vbYesNo, "CONFIRM") = vbYes Then
6.提示 Messagebox
格式:MsgBox("") 实例:MsgBox("CP 工单开始取消")
"
'V
="WSJ_REPORT
'"&GDH&"','"&BC&"','"&PCH&"','"&PH&"','"&Silo&"',"&CL&",'"&CStr(Now)&"',3"
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脚本
查看文章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脚本
按钮开头#include "apdefap.h" //通过该文件,向C动作预告所有项目的函数.标准函数以及内部函数。
C动作标题的第二部分为函数标题。
该函数标题提供有关C动作的返回值和可以在C动作中使用的传送参数的信息。
void OnClick(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName)//将三个参数传送给C动作。
它们是画面名称(Lpsz PictureName),对象名(lpszObjectName)和属性名(lpszPropertyName)不要更改。
.{}用户注销:#pragma code ("useadmin.dll")/wincc内部动态库,登陆和注销等内部变量#include "PWRT_api.h"//登陆与注销的内部变量#pragma code() //#pragma code是调用windows标准API 函数库中的哪个函数。
PWRTLogout();2.用户登录:#pragma code ("useadmin.dll")#include "PWRT_api.h"#pragma code()PWRTLogin('c');3.#pragma code("useadmin.dll")#include "PWRT_API.H"#pragma code()if (strcmp(GetTagChar("@CurrentUser"),"")==0){PWRTLogin('1');}else{OpenPicture("登陆画面.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脚本
电机风扇旋转(几何---起始角度):
#include "apdefap.h"
long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName)
{
static DWORD f=20;
{
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);
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)
return(p);
}
时分秒(静态文本)
#include "apdefap.h"
char* _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName)
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 脚本,实践可用
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-全套脚本总结
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脚本第一篇: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)return0x0000ff00;else if(GetTagWord(“TX/ZSL001”)==1)return 0x000000ff;else return 0x00c0c0c0;} 一个调用按钮变色#include “apdefap.h” long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){ #pragma option(mbcs)if(GetTagWord(“NewTag”)==0)return0x0000ff00;else return 0x00ffffff;}5.结束监控并关闭计算机(会弹出确认对话框)HWND hWnd = NULL;//Author:Smartsys int iRet;hWnd = FindWindow(NULL,“WinCC-运行系统”);//如果运行语言为英文if(WinCCHwnd==0)WinCCHwnd=FindWindow(NULL,“Win CC-运行系统-”);//如果运行语言为中文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);hRuntim eWindow=FindWindow(“PDLRTisAliveAndWaitsForYou”,NULL);if(hExplor erWindow){ ShowWindow(hExplorerWindow, SW_MINIMIZE);// This entry is only necessary for Windows 2000 ShowWindow(hExplorerWindow,SW_SHOWNORMAL);SetForegroundWindow(hExplorerWindow) ;} else printf(“rn SetForeground failed”);#endif 11.如何在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)。
D e a c t i v a t e R T P r o j e c t();//退出系统#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操作LoginActionforlogin(forexample,"mouseclick"event):#pragmacode("useadmin.dll")#include"PWRT_api.h"#pragmacode()PWRTLogin('c');LogoutActionforlogout(forexample,"mouseclick"event):#pragmacode("useadmin.dll")#include"PWRT_api.h"#pragmacode()PWRTLogout();PWRTLogin参数必须是CHAR字符。
它指定了显示对话框的监视器。
如果只使用一个监视器,那么保留默认参数“c”或者指定“1”。
注意可以使用PASSLoginDialog函数来代替PWRTLogin?或者PWRTLogout函数。
这个函数需要和函数PWRTLogin相同的参数。
PWRTLogin?和PASSLoginDialog函数可以调用登录界面,在上面可以登录或者注销。
函数PWRTLogout被正确执行并且不调用登录界面。
正确执行后这两个函数都返回“1”。
然而,登录不会等到显示对话框之后。
注意如果使用多个显示器,为了能使登录对话框显示在合适的显示器上,需要WinCCBasicProcessControl(OS项目编辑器)。
不使用WinCCBasicProcessControl时,可以指定显示器编号,但登录对话框始终显示在第一个显示器上。
#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,"AILoopControlPannel");SetPropChar("@MAIN.pdl",AI_TemplateName,"CaptionText",str_Title);//置为变量SetPropBOOL("@MAIN.pdl",AI_TemplateName,"Visible",0);//TomakethePicturewindowNOvisible//不显示SetPropChar("@MAIN.pdl",AI_TemplateName,"TagPrefix",TagName);//SettheObjectNameasTagPrefix-¨¨oSetPropBOOL("@MAIN.pdl",AI_TemplateName,"Visible",1);//TomakethePicturewindowvisible-¨strcpy(str_Unit,TagName);strcpy(str_Loop_Name,TagName);//SetPropChar("PID_Pannel.pdl","PidTitle","Text",TagName);//Setthetitletotheojectname//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,"MOTORControlPannel");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,"PIDLoopControlPannel");SetPropChar("@MAIN.pdl",PID_TemplateName,"CaptionText",str_Title);//±êìa±SetPropBOOL("@MAIN.pdl",PID_TemplateName,"Visible",0);//TomakethePicturewindowNOvisible-2é£é2óSetPropChar("@MAIN.pdl",PID_TemplateName,"TagPrefix",TagName);//SettheObjectNameasTagPrefix-μ±áó°×oSetPropBOOL("@MAIN.pdl",PID_TemplateName,"Visible",1);//TomakethePicturewindowvisible-éstrcpy(str_Unit,TagName);strcpy(str_Loop_Name,TagName);//SetPropChar("PID_Pannel.pdl","PidTitle","Text",TagName);//Setthetitletotheojectname//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。