Lập trình C cho WINCC – Tổng hợp code C và VB - Phần 1

Lập trình C cho WINCC – Tổng hợp code C và VB
Trong quá trình làm học và project, mình có nghiên cứu chút về phần lập trình C, VB trong WinCC.
Dưới đây là một số code mình tham khảo và tự code. Mong giúp phần nào đó cho các bạn mới sử dụng
WinCC.
code an/hien window picture
#include “apdefap.h”
void OnLButtonDown(char* lpszPictureName,char* lpszObjectName,char*lpszPropertyName, UINT Flags,
int x,int y)
{
SetVisible(lpszPic
tureName,“set_oto”,1GetVisible(lpszPictureName,“set_oto”));
}
========================================
void move_xy(char* lpszPictureName,
char* lpszObjectName,int x1,int y1,int x2,
int y2)
{
static
int x0,y0;
// Chuyen dong ve phia tang x
x0=x1,y0=y1;
if(x1<=x2)
{ x0+=10;
y0=(int)((y2y1)*(x0x1)/(x2x1)+y1);
if(x0>=x2)
{
x0=x2; y0=y2;
}
}
// Chuyen dong ve phia giam x
else
{ x0-=10;
y0=(int)((y2y1)*(x0x1)/(x2x1)+y1);

if(x0<=x2)

{
x0=x2; y0=y2;

}
}
SetTop(lpszPictureName,lpszObjectName,y0);
SetLeft(lpszPictureName,lpszObjectName,x0);
//SetTagDWord(“move_x”,x0);
//SetTagDWord(“move_y”,y0);
}
==========================================================
#include “apdefap.h”

long _main(char* lpszPictureName,
char* lpszObjectName,
char* lpszPropertyName)
{
#include “dmclient.h”
extern Delay(ms);
static
int x1=990,y1=270;
static
int x2=650,y2=460;
static x=x1,y=y1;
//x=x1,y=y1;
if(GetTagBit(“start”)==1)
{
x-=8;
y=(int)((y2y1)*(xx1)/(x2x1)+y1);

if(x<=x2)

{
x=x2;

}
}
SetTagDWord(“move_xy”,y);
//Return-Type: BOOL
return x;
}
===============================
nut nhan 2 trang thai
//***************
BOOL value;
value = GetTagBit(“Lamp”);
if
(value==0)
SetTagBit(“Lamp”,1);
else
SetTagBit(“Lamp”,0);
//**************
====================================================
di chuyen tu a _> b theo truc x
#include “apdefap.h”

long _main(char* lpszPictureName,
char* lpszObjectName,
char* lpszPropertyName)
{
static a=970,b=680;
if(GetTagBit(“start”)==1) a=a10;
if(a<=b) a=b;
//delay(2000);
return a;
}
========================================================
code xoay tron
#include “apdefap.h”

long _main(char* lpszPictureName,
char* lpszObjectName,
char* lpszPropertyName)
{
static a=0;
if(GetTagBit(“start”)==1)
{
a=a+20;
}
if(a>=360) a=0;
if(GetTagBit(“start”)==0) a=0;
return a;
}
==========================================================================
#include “apdefap.h”

long _main(char* lpszPictureName,
char* lpszObjectName,
char* lpszPropertyName)
{
static a=0;
if(GetTagBit(“phai”)==1) a=a+10;
if(GetTagBit(“trai”)==1) a=a10;
if(a>=500) a=500;
if(a<=0) a=0;
return a;
}
====================================================================================
#include “apdefap.h”

long _main(char* lpszPictureName,
char* lpszObjectName,
char* lpszPropertyName)
{
static b=0;
if(GetTagBit(“len”)==1) b=b10;
if(GetTagBit(“xuong”)==1) b=b+10;
if(b>=500) b=500;
if(b<=0) b=0;
return b;
}
==================================================================================================
Code X:
#include “apdefap.h”
long _main(char* lpszPictureName,
char* lpszObjectName,
char* lpszPropertyName)
{
static a=433;
if(GetTagBit(“bang_chuyen_sp_lon”)==1&&a<=436)
{
a=a1;
}
if(GetTagBit(“bang_chuyen_sp_lon”)==1&&a>436)
{
a=433;
}
return a;
// WINCC:TAGNAME_SECTION_START
// syntax: #define TagNameInAction “DMTagName”
// next TagID : 1
// WINCC:TAGNAME_SECTION_END
// WINCC:PICNAME_SECTION_START
// syntax: #define PicNameInAction “PictureName”
// next PicID : 1
// WINCC:PICNAME_SECTION_END
}
Code Y :
#include “apdefap.h”
long _main(char* lpszPictureName,
char* lpszObjectName,
char* lpszPropertyName)
{
static b=200;
if(GetTagBit(“bang_chuyen_sp_lon”)==1&&b<=203)
{
b=b+2;
}
if(GetTagBit(“bang_chuyen_sp_lon”)==1&&b>203)
{
b=200;
}
return b;
// WINCC:TAGNAME_SECTION_START
// syntax: #define TagNameInAction “DMTagName”
// next TagID : 1
// WINCC:TAGNAME_SECTION_END
// WINCC:PICNAME_SECTION_START
// syntax: #define PicNameInAction “PictureName”
// next PicID : 1
// WINCC:PICNAME_SECTION_END
}
====================================================================
static
int a=340;
if
(GetTagBit(“dichtrai”)==1)
{
a=a10;
}
if(a<=200)a=340;
if
(GetTagBit(“dichphai”)==1)
{
a=a+10;
}
if(a>=600)a=340;
return a;
================================================================
int left = GetPropWord(“Hethonghoatdong.pdl”,“ong”,“Left”);
for(; i<75
; i++){
SetPropWord(“Hethonghoatdong.pdl”,“ong”,“Left”,lef t i);
}
===================================================================
Chào các sư huynh! Trong WinCC mình muốn phân quyền truy cập trong đó (ví dụ:trong graphics mình tạo một nút nhấn, Khi runtime nếu nhấn vào nút đó thì nó sẻ hiện lên bảng logon yêu cầu đăng nhập.) Mình đã sử dụng công cụ user Adminnator để tạo user và password cho người sử dụng nhưng khi mình gán user đó cho nút nhấn thì nó lại không hiện lên bảng yêu cầu đăng nhập! huynh nào đã giải quyết đuộc vấn đề này giúp mình với!
ấn nút cho thêm CAtion PASSLoginDialog(“1”);
gán quyền user bằng cách : Properties -> Miscellaneous -> Authorization -> chọn quyền tương ứng mà bạn đã gán : gán quyền quản trị chứ ko thể hiện lên cửa sổ đăng nhập được,
hiện đăng nhập thì dùng cách trên ấn nút cho thêm CAtion PASSLoginDialog(“1”);
==========================================================================================
#include “apdefap.h”
void OnClick(char* lpszPictureName,
char* lpszObjectName,
char* lpszPropertyName)
{
#pragma code (“UseAdmin.DLL”)
#include “pwrt_api.h”
#pragma code ()
int i, j, n;
char pic_name[256];
char obj_name[60];
PWRTLogout();
= strlen( lpszPictureName );
for
( i = n; i >
0; i
)

if
( lpszPictureName[i]
==
‘.’
)

{
strncpy( pic_name, lpszPictureName, i );
strcpy( obj_name,
&lpszPictureName[i+1]
);

for
( j =
0; j <
(ni); j++)

if
( obj_name[j]
==
‘:’
)

{
obj_name[j]
=
;

break;

}
SetVisible(pic_name,obj_name,FALSE);

break;

}
}

No comments

Powered by Blogger.