wincc-全套脚本总结

lpszPropertyName) {

static int x=25,y,z;//x为半径的初始值为25,y为切换变量,z为搅拌机运行状态变量 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; }

——————13、WINCC--如何在程序中动态修改用户密码 —————— 1、点击“开始”--》“设置”--》“控制面板”--》“管理工具”--》“数据源(ODBC)”,打开ODBC数据源管理器

2、在用户DSN页面的用户数据源中找到与当前项目所关联的一项,其名称为“CC_项目名_项目建立日期时间”,记下该项的名称 3、在脚本中加入以下代码: #pragma code(\ #include \.H\ #pragma code()

LPCMN_ERROR err; //定义的LPCMN_ERROR型变量,在函数调用中需使用 if (PWGENConnect(\建立与数据库的联接,其中CC_ass_04-09-21_16:35:22用第二步中记下的名称取代 { if

(PWGENChangePassword(GetTagChar(\(\修改密码,user,oldpassword,password分别为存贮用户名,原密码,新密码的内部变量,类型为文本变量8位字符集 {

//密码修改成功后的操作,如给用户提示等 } }

6

PWGENDisconnect(err); //断开与数据库的联接 4、编译运行程序 5、工作完成

6、与用户管理相关的函数定义存贮在APPLIB目录下的USEGENAP.H文件中,可根据上面示例自行完成添加用户,修改权限等功能。

——————14、WinCC如何实现鼠标OnMouseOVer事件 —————— 用WINDOWAPI函数GetCusorPos获取当前鼠标位置,用GetWindowRect函数获取窗口位置,两值相减得鼠标在WINCC frame上的相对位置。用全局脚本(设定为1s定时刷新),然后获取要OnMouseOver事件的物体的位置,并与鼠标位置相比较,如一致则触发自己定义的动作。

#include \int gscAction( void ) {

#pragma code(\

BOOL GetCusorPos(POINT lpPoint); //获取鼠标的位置(绝对位置-对应屏幕分辨率) BOOL GetWindowRect(HWND hwnd,LPRECT lpRect); //获取窗体位置 #pragma code(); POINT pPos; RECT rRec; HWND hwnd; BOOL bRet,bRet2;

long lLeft,lTop,lWidth,lHeight; long lX,lY; char szStr[100];

hwnd=FindWindow(NULL,\如语言为中文应为\运行系统-\if (hwnd==0) {printf(\bRet=GetCursorPos(&pPos); if (bRet==0) goto over;

bRet2=GetWindowRect(hwnd,&rRec); if (bRet2==0) goto over;

lX=pPos.x-rRec.left; //鼠标 对{置 lY=pPos.y-rRec.top; //鼠标 位置

//如果为非全屏模式,需将上述数值中的高height判断减去标题栏的宽度 //printf(\

//printf(\ lLeft=GetLeft(\ lTop=GetTop(\ lWidth=GetWidth(\ lHeight=GetHeight(\

if ((lX>=lLeft)&&(lY>=lTop)&&(lX<=lLeft+lWidth)&&(lY<=lTop+lHeight)) { sprintf(szStr,\

7

SetText(\}

//printf(\ over: return 0; }

——————————————————————————————————————— ——————15、如何在退出

WINCC监控时直接关闭电脑 ——————

1.利用动态向导

2.在脚本中加入 DMExitWinCCEx (DM_SDMODE_SYSTEM);也可以

——————16、过

WINCC API函数读出当前报警消息 ——————

1、使用GMsgFunction中读出当前报警信息的ID(dwMsgNr);

2、使用MSRTGetMsgCSData函数读出该报警信息ID对应文本库TEXTLIB中的文本ID(dwTextID1);

3、使用MSRTGetMsgText函数读出该文本ID的文本。 信息到达处理:如果读取文本成功,则置文本变量MSG。

信息离去处理:如果MsgNr与上一次相同,则复位MSG,如果不是,则继续保持信息。 具体函数说明请看ODK文档

BOOL GMsgFunction( char* pszMsgData) {

#pragma code(\ #i nclude \ #pragma code();

MSG_TEXT_STRUCT tMeld; MSG_CSDATA_STRUCT sM; CMN_ERROR err; BOOL bRet;

DWORD dwTextID1; DWORD dwMsgNum; char szMsg[255];

#define TAG_MSG \

MSG_RTDATA_STRUCT mRT;

memset( &mRT, 0, sizeof( MSG_RTDATA_STRUCT ) ); if( pszMsgData != NULL ) {

printf( \ sscanf( pszMsgData, \ &mRT.dwMsgNr, // Meldungsnummer

&mRT.dwMsgState, // Status MSG_STATE_COME, .._GO, .._QUIT, .._QUIT_SYSTEM &mRT.stMsgTime.wYear, // Tag

8

&mRT.stMsgTime.wMonth, // Monat &mRT.stMsgTime.wDay, // Jahr &mRT.stMsgTime.wHour, // Stunde &mRT.stMsgTime.wMinute, // Minute &mRT.stMsgTime.wSecond, // Sekunde

&mRT.stMsgTime.wMilliseconds, // Millisekunde

&mRT.dwTimeDiff, // Zeitdauer der anstehenden Meldung &mRT.dwCounter, // Interner Meldungsz?hler &mRT.dwFlags, // Flags( intern ) &mRT.wPValueUsed, &mRT.wTextValueUsed );

//**************************************************************************************code for dcount

if (mRT.dwMsgState==MSG_STATE_COME)//信息到达处理 {

dwMsgNum=mRT.dwMsgNr;

printf(\ bRet=MSRTGetMsgCSData(dwMsgNum,&sM,&err); if (bRet==TRUE) {

dwTextID1=sM.dwTextID[0];

printf(\ bRet=MSRTGetMsgText(1,dwTextID1,&tMeld,&err); if (bRet==TRUE) {

sprintf(szMsg,\

printf(\ } } }

if (mRT.dwMsgState==MSG_STATE_GO)//信息离去处理 {

dwMsgNum=mRT.dwMsgNr;

if (dwMsgNum==GetTagDWord(TAG_MSG_NR)) SetTagChar(TAG_MSG,\}

//**************************************************************************************code for dcount // Meldungsdaten einlesen

// Prozesswerte lesen, falls gew???????§???1nscht }

printf(\ mRT.dwMsgNr, mRT.dwMsgState, mRT.stMsgTime.wDay, mRT.stMsgTime.wMonth, mRT.stMsgTime.wYear,

9

mRT.stMsgTime.wHour, mRT.stMsgTime.wMinute, mRT.stMsgTime.wMilliseconds, mRT.dwTimeDiff, mRT.dwCounter, mRT.dwFlags ) ; SetTagChar(TAG_MSG,szMsg); return( TRUE ); }

mRT.stMsgTime.wSecond,

——————17、实现用户登陆日志(wincc中用c脚本实现?)—————— 用户登陆日志:(包括用户的登陆退出信息,以便查询在什么时间段是哪个用户在使用这个监控软件)

#i nclude \int gscAction( void ) {

#pragma code(\

VOID GetLocalTime(LPSYSTEMTIME lpSystemTime); #pragma code() char* username; char buf[128];

static char preuser[128]; unsigned a,b,c,d,e,f; FILE* fp;

SYSTEMTIME sysTime;

//读取系统时间,并且复制给变量a,b,c,d,e,f GetLocalTime(&sysTime); a=sysTime.wHour; b=sysTime.wMinute; c=sysTime.wSecond; f=sysTime.wYear; e=sysTime.wMonth; d=sysTime.wDay; //得到当前用户名称

username = GetTagChar(\ fp= fopen(\

if(strcmp(username, preuser)!=0) //如果当前用户名称和前一个用户名不同 {

if((strcmp(username, \如果当前用户名称不空同时前一个用户名为空 {

sprintf(buf, \用户:%st登陆时间是:t %d-%d-%d,%d-%d-%dn\ fputs(buf, fp); } else

10

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4