WINCC常用 脚本
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
1、变量自加1(C)
int tag;
tag=GetTagByte("tag1");
tag=tag+1;
SetTagByte("tag1",tag);
----------------------------------------------
2、变量自减1(C)
int tag;
tag=GetTagByte("tag1");
tag=tag-1;
SetTagByte("tag1",tag);
----------------------------------------------
3、颜色改变(VB)
ScreenItems("Rectangle1").BackColor = RGB(255,0,0)
----------------------------------------------
4、单键的置位与复位(C)
BOOL Z;
Z=GetTagBit("TAG");
if(Z==0) SetTagBit("TAG",1);
else SetTagBit("TAG",0);
----------------------------------------------
5、输入/输出域实现带确认的输入操作(C)
int TempValue=GetTagWord("TempValue");
char szBuffer[20];
sprintf( szBuffer,"Input number:%d",TempValue);
if ( nChar==13 )//if press enter
{
int xRet = MessageBox(NULL,szBuffer,"确认窗口",MB_YESNO|MB_ICONQUESTION|MB_SYSTEMMODAL);//message
if ( xRet == IDYES )//confirm operate
{
SetTagWord("DisplayValue",TempValue);// set data
}
}
注:1、DisplayValue是实际需要控制的变量,TempValue作为临时变量使用。
2、新建一个输入/输出域,在输出值处打开动态对话框。选择DisplayValue
3、在同一个输入/输出域的事件,选择 输出/输入--输入值--直接连接 ,选择直接连接到临时变量TempValue
4、在同一个输入/输出域的事件,选择 键盘--释放--C动作,输入以上代码。
----------------------------------------------
6、VBS弹出提示小窗口(VB)
Dim a
Dim objCon2
Set objCon2 = HMIRuntime.ActiveScreen.ScreenItems("按钮1")
a=MsgBox("hello!",vbYesNo)
If vbYes=a Then
objCon2.text="ok" '如点击是,则按钮文本变为ok
Else
objCon2.text="no" '如点击否,则按钮文本变为no
End If
注:放置按钮,起名按钮1.
----------------------------------------------
7、位状态实现带确认的输入操作(C)
BOOL a;
a=GetTagBit("30T制水启动"); //Return-Type :short int
if (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制水启动",0);
}}
----------------------------------------------
8、wincc运行界面里面怎么调用屏幕键盘 (C)
ProgramExecute("c:\\windows\\system32\\osk.exe");
注:1、选中[计算机],然后在左边选择当前项目的服务器名,双击弹出项目的[计算机属性]对话框。选择最后一栏[运行系统],里面就有一个[监视器键盘],用来实现无键盘WinCC全屏运行时数值输入的;
2、如果想使用系统的虚拟键盘,可以用按钮的点击事件的C代码,添加以上代码。
3、如果想要手写输入,就安装Tablet PC
面板组建来实现了。
----------------------------------------------
9、通过按钮实现用户登录(C)
#pragma code("useadmin.dll")
#include "PWRT_API.H"
#pragma code()
PWRTLogin('1');
----------------------------------------------
10、通过按钮实现用户注销(C)
#pragma code ("useadmin.dll")
#include "PWRT_api.h"
#pragma code()
PWRTLogout();
----------------------------------------------
11、在画面中显示用户名
1.组态静态文本
2.字体属性中的文本,连接系统变量@CurrentUser
----------------------------------------------
12、WINCC在线修改用户密码
(1)旧密码设置(C)
SetOutputValueChar(lpszPictureName,lpszObjectName,GetInputValueChar(lpszPictureName,lpszObjectName));
注:字符串格式的输入输出域》事件》属性主题》输出/输入》输出值》更改》以上代码。
(2)新密码设置(C)
SetOutputValueChar(lpszPictureName,lpszObjectName,GetInputValueChar(lpszPictureName,lpszObjectName));
注:字符串格式的输入输出域》事件》属性主题》输出/输入》输出值》更改》以上代码。
(3)新密码确认设置(C)
SetOutputValueChar(lpszPictureName,lpszObjectName,GetInputValueChar(lpszPictureName,lpszObjectName));
注:字符串格式的输入输出域》事件》属性主题》输出/输入》输出值》更改》以上代码。
(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;
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));
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);
//Get the differents strings old, new password and confirmation
pold_pass=GetPropChar(lpszPictureName,"IOField_OldPassWord","OutputValue");
pnew_pass=GetPropChar(lpszPictureName,"IOField_NewPassWord","OutputValue");
pconfirm=GetPropChar(lpszPictureName,"IOField_Confirmation","OutputValue");
strncpy(old_pass,pold_pass,50);
strncpy(new_pass,pnew_pass,50);
strncpy(confirm,pconfirm,50);
//if the new password and the confirmation are not the same display a message in a modal messagebox
ret = strcmp(pnew_pass,pconfirm);
if (ret)
MessageBox (Handle, "输入密码不一致!", "请重新输入", MB_OK |
MB_ICONEXCLAMATION | MB_SYSTEMMODAL);
else
{
// if the new and the old password are the same display a message in a modal messagebox
if (!strcmp(pnew_pass,pold_pass))
{
MessageBox (Handle, "新密码和旧密码不能相同 !", "请重新输入密码", MB_OK |
MB_ICONEXCLAMATION | MB_SYSTEMMODAL);
}
else
{
// this 2 lines are necessary to get the DSN-Name of the project
ret2=DMGetRuntimeProject(pr_info.szProjectFile,sizeof(pr_info.szProjectFile),NULL);
ret2=DMGetProjectInformation(pr_info.szProjectFile,&pr_info,NULL);
//connect to the Database with the DSN-Name contained in the pr_info-Structure
PWGENConnect (pr_info.szDSNName,&error);
// Change the password from Old_pass to New_pass of the user @CurrentUser
ret2=PWGENChangePassword (GetTagChar("@CurrentUser"),old_pass,new_pass,&error);
if (!ret2)
{
// when a password of another user is given, display a message in a modal messagebox
MessageBox (Handle, "请检查用户名密码!", "请重新输入密码", MB_OK |
MB_ICONEXCLAMATION | MB_SYSTEMMODAL);
}
else
{
// Disconnect from the Database
PWGENDisconnect(&error);
SetVisible("start.pdl","PictureWindow1",0); //hide the window "ChangePassword"
}
}
}
注:事件》鼠标》释放左键。
----------------------------------------------
13、如何触发计算机扬声器的声音 (C)
#pragma code("kernel32.dll");
BOOL Beep(DWORD dwFreq,DWORD dwDuration);
#pragma code();
Beep(500,500);
----------------------------------------------
14、画面窗口的显示与隐藏(C)
(1)窗口显示
SetVisible(lpszPictureName,"PictureWindow1",1);
(2)窗口隐藏
SetVisible("Start.pdl","PictureWindow1",0);
----------------------------------------------
15、单按钮的窗口的显示与隐藏(C)
SetVisible(lpszPictureName,"画面窗口名称",1-GetVisible(lpszPictureName,"画面窗口名称"));
----------------------------------------------
16、报表变量C计算求三个浮点数平均值(C)
#include "apdefap.h"
double _main()
{
#pragma option(mbcs)
double v1,v2,v3,aver;
v1=GetTagFloat("v1");
v2=GetTagFloat("v2");
v3=GetTagFloat("v3");
aver=(v1+v2+v3)/3;
SetTagFloat("aver",aver);
return(aver);
}
----------------------------------------------
17、C脚本播放wav文件(C)
#pragma code ("Winmm.dll ")
VOID WINAPI PlaySoundA ( char* pszSound, char* hmode, DWORD dwflag );
#pragma code()
PlaySoundA("C:\\Winnt.400\\Media\\tada.wav",NULL,1);
注:播放的路径用\\隔开。
----------------------------------------------
18、运行状态调出用户管理界面(C)【7.0软件下使用】
ProgramExecute("PASSCS.exe C:\Program Files\Siemens\WinCC\WinCCProjects\demo2\demo2.mcp");
----------------------------------------------