Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

Lp trnh C cho WINCC Tng hp code C

v VB - Phn 1
Ti Nguyn 6:52 PM Add Comment lp trnh wincc cho scada , scada , trnh wincc ,VB trong WINCC

Lp trnh C cho WINCC Tng hp code C v VB

Trong qu trnh lm hc v project, mnh c nghin cu cht v phn lp trnh C, VB trong WinCC.

Di y l mt s code mnh tham kho v t code. Mong gip phn no cho cc bn mi s dng

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 ; i<75
; i++){

SetPropWord(Hethonghoatdong.pdl,ong,Left,lef t i);

===================================================================

Cho cc s huynh! Trong WinCC mnh mun phn quyn truy cp trong (v d:trong graphics mnh to
mt nt nhn, Khi runtime nu nhn vo nt th n s hin ln bng logon yu cu ng nhp.) Mnh s dng
cng c user Adminnator to user v password cho ngi s dng nhng khi mnh gn user cho nt nhn th
n li khng hin ln bng yu cu ng nhp! huynh no gii quyt uc vn ny gip mnh vi!

n nt cho thm CAtion PASSLoginDialog(1);


gn quyn user bng cch : Properties -> Miscellaneous -> Authorization -> chn quyn tng ng m
bn gn : gn quyn qun tr ch ko th hin ln ca s ng nhp c,

hin ng nhp th dng cch trn n nt cho thm 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();

n = 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;

You might also like