Tải bản đầy đủ (.docx) (27 trang)

Lập trình c cho WINCC

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (87.54 KB, 27 trang )

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(lpszPictureName,“set_oto”,1–GetVisible(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)((y2–y1)*(x0–x1)/(x2–x1)+y1);
if(x0>=x2)
{
x0=x2; y0=y2;


}


}
// Chuyen dong ve phia giam x
else
{ x0-=10;
y0=(int)((y2–y1)*(x0–x1)/(x2–x1)+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)((y2–y1)*(x–x1)/(x2–x1)+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=a–10;
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=a–10;
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=b–10;
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=a–1;
}
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=a–10;
}
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);
}
===================================================================
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 C–Ation 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 C–Ation 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 <
(n–i); j++)
if
( obj_name[j]
==
‘:’
)
{


obj_name[j]
=
”;
break;
}
SetVisible(pic_name,obj_name,FALSE);
break;
}
}
=========================================================================
#include “apdefap.h”
void OnClick(char* lpszPictureName,
char* lpszObjectName,
char* lpszPropertyName)
{
SetVisible(lpszPictureName,“@ERROR”,FALSE);
SetOperation(lpszPictureName,“@LoginIn”,TRUE);
SetOperation(lpszPictureName,“@PasswordIn”,TRUE);

SetOperation(lpszPictureName,“@OK”,TRUE);
Set_Focus(lpszPictureName,“@LoginIn”);
SetVisible(lpszPictureName,lpszObjectName,FALSE);
}
================================================================
#include “apdefap.h”
void OnClick(char* lpszPictureName,
char* lpszObjectName,
char* lpszPropertyName)
{
// WINCC:TAGNAME_SECTION_START
// syntax: #define TagNameInAction DMTagName
// next TagID : 1
#define Apc_CurrentUser “@CurrentUser”
// WINCC:TAGNAME_SECTION_END
// WINCC:PICNAME_SECTION_START
// syntax: #define PicNameInAction PictureName
// next PicID : 1
#define Apcpictu_0_startpicture_00_PDL “pictu_0_startpicture_00.PDL”
// WINCC:PICNAME_SECTION_END
int i, j, n;
char pic_name[256];
char obj_name[60];
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 <
(n–i); j++)
if
( obj_name[j]
==
‘:’
)
{
obj_name[j]
=
”;
break;
}
SetVisible(pic_name,obj_name,FALSE);
break;
}
/*if ((strcmp(GetTagChar(Apc_CurrentUser),””))==0) {
SetVisible(Apcpictu_0_startpicture_00_PDL,”Picture Window6″,1);

}*/
}
==================================================================
// Di chuyen cheo
#include “apdefap.h”
long _main(char* lpszPictureName,


char* lpszObjectName,
char* lpszPropertyName)
{
static
int x1=10,y1=20;
if(GetTagBit(“start”)==1) x1+=20;
y1=(int)((0.391)*x1+16.09);
if(x1>=470)
{
x1=470; y1=200;
}
SetTagDWord(“oto”,y1);
//Return-Type: BOOL
return x1;
}
//////////////////////////////////
di chuyen cheo chuan
#include “apdefap.h”
long _main(char* lpszPictureName,
char* lpszObjectName,
char* lpszPropertyName)
{

static
int x1=640,y1=350;
static
int x2=770,y2=480;
static x=x1,y=y1;
//x=x1,y=y1;
if(GetTagBit(“start”)==1)
{
x+=10;
y=(int)((y2–y1)*(x–x1)/(x2–x1)+y1);
if(x>=x2)
{
x=x2; y=y2;
}
}
SetTagDWord(“oto”,y);
//Return-Type: BOOL
return x;
}
====================================================================================
=
Option Explicit


Sub OnLButtonDown(Byval Item, Byval Flags, Byval x, Byval y)
Dim SMSSend
Dim SMS
Dim buffer
MsgBox “Xin chao”
‘ This is the name of the MSComm Control

Set SMSSend = ScreenItems(“Control 1”)
‘Comunicacion puerto COM
SMSSend.CommPort =
1
SMSSend.Settings =
“9600,E,8,1”
SMSSend.InputLen =
0
SMSSend.Handshaking =
0
SMSSend.PortOpen = True
SMSSend.Output =
“atE0”
& Chr(13)
Do
buffer = buffer & SMSSend.Input
Loop Until InStr(buffer,“OK”)
buffer =
“”
SMSSend.Output =
“AT+CMGF=1”
& Chr(13)
Do
buffer = buffer & SMSSend.Input
Loop Until InStr(buffer,“OK”)
buffer =
“”
SMSSend.Output =
“AT+CMGS=”&“+34X X X X X X X X X “
& Chr(13)+“&”+ Len(SMS)/2+“&”+Chr(13)

Do
buffer = buffer & SMSSend.Input
Loop Until InStr(buffer,
“>”)
buffer =
“”
SMSSend.Output =
“M ens aj e prueba”
+ Chr(26)
Do
buffer = buffer & SMSSend.Input


Loop Until InStr(buffer,
“OK”)
‘ try to force s ends by cl os i ng the ports and reopen i n l oop
SMSSend.PortOpen = False
MsgBox “Tam Biet”
End Sub
============================================================
Open Port
Sub OnClick(Byval Item)
Dim objMSComm1, tagConnection
Set objMSComm1 = HMIRuntime.Screens(“Main”).ScreenItems(“MSComm1”)
Set tagConnection = HMIRuntime.Tags(“Connection”)
If objMSComm1.PortOpen = False Then
‘ Assign com port number
objMSComm1.Commport =
1
‘ Values: 9600 Baud, N – No Parity, 8 – Databit, 1 – Stopbit

objMSComm1.Settings =
“9600,N,8,1”
objMSComm1.RThreshold =
1
objMSComm1.SThreshold =
1
objMSComm1.InputLen =
0
objMSComm1.PortOpen = True
tagConnection.Write(True)
HMIRuntime.Trace(“Port open.”
& vbCrLf)
Else
HMIRuntime.Trace(“Port is already opened.”
& vbCrLf)
End If
End Sub
=============================================================
Close Port
Sub OnClick(Byval Item)
Dim objMSComm1, tagConnection
Set objMSComm1 = HMIRuntime.Screens(“Main”).ScreenItems(“MSComm1”)
Set tagConnection = HMIRuntime.Tags(“Connection”)
If objMSComm1.PortOpen = True Then
objMSComm1.PortOpen = False
tagConnection.Write(False)
HMIRuntime.Trace(“Port close.”
& vbCrLf)
End If
End Sub

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


Read Buffer
Option Explicit
Function action
Dim strBuffer, strTemp
Dim objMSComm1, tagBuffer
Set objMsComm1 = HMIRuntime.Screens(“Main”).ScreenItems(“MSComm1”)
Set tagBuffer = HMIRuntime.Tags(“Buffer”)
strTemp =
“”
If objMSComm1.PortOpen = True Then
‘read the buffer
strTemp = CStr(objMSComm1.Input)
If strTemp <>
“” Then
‘checking for the delimited character
If InStr(strTemp, Chr(6)) Then
strBuffer = Left(strTemp,Len(strTemp)-1)
Else
strBuffer = strTemp
End If
tagBuffer.Value = strBuffer
tagBuffer.Write
End If
Else
HMIRuntime.Trace(“No port is opened!”
& vbCrLf)
End If

End Function
=====================================================================
Send Data
Sub OnClick(ByVal Item)
Dim tagOutput, objMSComm1
Set tagOutput = HMIRuntime.Tags(“Output”)
Set objMSComm1 = HMIRuntime.Screens(“Main”).ScreenItems(“MSComm1”)
If objMSComm1.PortOpen = True Then
tagOutput.Read
objMSComm1.Output = tagOutput.Value
tagOutput.Write(“”)
Else
HMIRuntime.Trace(“No port is opened!”
& vbCrLf)
End If
End Sub
===================================================================
#define Apc_lower_limit “lower_limit”
#define Apc_upper_limit “upper_limit”
// next TagID : 4
// WINCC:TAGNAME_SECTION_END


// WINCC:PICNAME_SECTION_START
// syntax: #define PicNameInAction “PictureName”
// next PicID : 1
// WINCC:PICNAME_SECTION_END
double a;
double lolmt;
double uplmt;

SetOutputValueDouble(lpszPictureName,“Setpoint_I”,strtod(GetOutputValueChar(lpszPict
ureName,“DisplayNr”),NULL));
a=GetOutputValueDouble(lpszPictureName,“Setpoint_I”);
lolmt=GetTagFloat (Apc_lower_limit);
uplmt=GetTagFloat (Apc_upper_limit);
if
((a <= uplmt)
&&
(a >= lolmt ))
{
SetOperation(lpszPictureName,“-_Button”,1);
//Rückgabe-Typ :BOOL
SetOperation(lpszPictureName,“._Button”,1);
//Rückgabe-Typ :BOOL
SetOutputValueChar(lpszPictureName,“DisplayNr”,“”);
SetVisible(“PA2_bld01.PDL”,“Tastatur”,0);
//Rückgabe-Typ :BOOL
SetTagDouble(Apc_Setpoint,a);
}
}
=======================================================
#include “apdefap.h”
void OnClick(char* lpszPictureName,
char* lpszObjectName,
char* lpszPropertyName)
{
char* buffer;
char* s = GetText(lpszPictureName,lpszObjectName);
char help[255]=“”;
buffer=SysMalloc(strlen(GetOutputValueChar(lpszPictureName,“DisplayNr”))+5);

buffer = GetOutputValueChar(lpszPictureName,“DisplayNr”);
sprintf(help,“%s%s”,buffer,&s[0]);
SetOutputValueChar(lpszPictureName,“DisplayNr”,help);
SetOperation(lpszPictureName,“-_Button”,0);
//Rückgabe-Typ :BOOL
SetOperation(lpszPictureName,“del_Button”,1);
//Rückgabe-Typ :BOOL
}
====================================================================
#include “apdefap.h”


void OnClick(char* lpszPictureName,
char* lpszObjectName,
char* lpszPropertyName)
{
// WINCC:TAGNAME_SECTION_START
// syntax: #define TagNameInAction DMTagName
// next TagID : 1
#define ApcVisibleTag03 “VisibleTag03”
// WINCC:TAGNAME_SECTION_END
// WINCC:PICNAME_SECTION_START
// syntax: #define PicNameInAction PictureName
// next PicID : 1
// WINCC:PICNAME_SECTION_END
SetVisible(lpszPictureName,“Tastatur”,0);
SetTagBit(ApcVisibleTag03,1–GetTagBit(ApcVisibleTag03));
}
=================================================================
#include “apdefap.h”

void OnClick(char* lpszPictureName,
char* lpszObjectName,
char* lpszPropertyName)
{
//Decrements the assigned tag by 1
int value,min;
LINKINFO plink;
PDLRTGetPropEx(0,lpszPictureName,lpszObjectName,“Process”,VT_I4,&value,NULL,NULL,0,N
ULL,NULL);
PDLRTGetPropEx(0,lpszPictureName,lpszObjectName,“Min”,VT_I4,&min,NULL,NULL,0,NULL,NU
LL);
if(value>=(min+1)) value-=1;
else value = min;
PDLRTGetLink(0,lpszPictureName,lpszObjectName,“Process”,&plink,NULL,NULL,NULL);
//Rückgabe-Typ :BOOL
if
(plink.LinkType >2)
return;
else SetTagDouble (plink.szLinkName, value);
}
====================================================================================
==============
#include “apdefap.h”
void OnLButtonDown(char* lpszPictureName,
char* lpszObjectName,
char* lpszPropertyName, UINT nFlags,
int x,
int y)
{
extern lok_fct(LPCTSTR lpszPictureName, LPCTSTR lpszObjectName);



// WINCC:TAGNAME_SECTION_START
// syntax: #define TagNameInAction “DMTagName”
#define Tag_1 “stop”
// next TagID : 2
// WINCC:TAGNAME_SECTION_END
// WINCC:PICNAME_SECTION_START
// syntax: #define PicNameInAction “PictureName”
// next PicID : 1
// WINCC:PICNAME_SECTION_END
SetTagBit(Tag_1,1);
//Triggerbit für globale Aktion lok_stop
lok_fct(“PA3_bld02_lok.pdl”,“Zustandsanzeige1”);
//Lokanimationsfunktion
}
===================================================================================
#include “apdefap.h”
int gscAction(
void
)
{
// WINCC:TAGNAME_SECTION_START
// syntax: #define TagNameInAction “DMTagName”
#define Tag_1 “loko_S36”
// next TagID : 2
// WINCC:TAGNAME_SECTION_END
// WINCC:PICNAME_SECTION_START
// syntax: #define PicNameInAction “PictureName”
#define Pic_2 “PA10_bld06.pdl”

// next PicID : 2
// WINCC:PICNAME_SECTION_END
#include “dmclient.h”
extern Delay(ms);
static
long
int a=-1;
while
(GetTagBit(Tag_1))
//Rückgabe – Typ :short int
{
SetIndex(Pic_2,“Zustandsanzeige1”,a);
printf(“loko_s36.pas return value = %d \r\n”,a);
Delay(50);
a++;
if(a==8) a=0;
}


return a;
}
=======================================================================
#include “apdefap.h”
int gscAction(
void
)
{
// 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
PrintHtml ();
//Rückgabe – Typ :void
return
0;
}
========================================================================
Creat trend
#include “apdefap.h”
int gscAction(
void
)
{
// WINCC:TAGNAME_SECTION_START
// syntax: #define TagNameInAction DMTagName
#define Tag_1 “stop”
#define Tag_2 “T01”
#define Tag_3 “T02”
#define Tag_4 “T03”
#define Tag_5 “T04”
#define Tag_6 “T05”
#define Tag_7 “T06”
#define Tag_8 “T07”
#define Tag_9 “Trend_1”
#define Tag_10 “Trend_2”
#define Tag_11 “Trend_3”

#define Tag_12 “Trend_4”
#define Tag_13 “Trend_5”
#define Tag_14 “Trend_6”
#define Tag_15 “Trend_7”
#define ApcMel_Mischer “Mel_Mischer”
#define Apc_X_Trend “X_Trend”
#define Apc_Y_Trend “Y_Trend”


// next TagID : 17
// WINCC:TAGNAME_SECTION_END
// WINCC:PICNAME_SECTION_START
// syntax: #define PicNameInAction PictureName
// next PicID : 1
// WINCC:PICNAME_SECTION_END
// create_trends.pas by Bob Meads modified by Hans-Norbert Schwoerer
// this script creates values of internal variables
// for trending and alarming.
static
long
int alarm=0;
long
int trend_1c=0;
long
int trend_2c=0;
long
int trend_3c=0;
long
int trend_4c=0;
long

int trend_5c=0;
long
int trend_6c=0;
long
int trend_7c=0;
long
int trend_1=0;
long
int trend_2=0;
long
int trend_3=0;
long
int trend_4=0;
long
int trend_5=0;
long
int trend_6=0;
long
int trend_7=0;
static
long
int trend_X=0;
static
long
int trend_Y;
if(!GetTagBit(Tag_1))
{


alarm=((alarm+1)%8);

while((trend_1<4)
||
(trend_1>128)) trend_1=rand ();
trend_1c=trend_1 /
4;
while((trend_2<21)
||
(trend_2>111)) trend_2=rand ();
trend_2c=trend_2 /
3;
while((trend_3<17)
||
(trend_3>130)) trend_3=rand ();
trend_3c=trend_3 /
4;
while((trend_4<15)
||
(trend_4>168)) trend_4=rand ();
trend_4c=trend_4 /
6;
while((trend_5<12)
||
(trend_5>173)) trend_5=rand ();
trend_5c=trend_5 /
5;
trend_6c=trend_5 /
25;
trend_7c=trend_5*7;
while((trend_6<18)
||

(trend_6>183)) trend_6=rand ();
while((trend_7<23)
||
(trend_7>193)) trend_7=rand ();
trend_X=((trend_X+1)%11);
trend_Y=(trend_X*trend_X);
}
SetTagMultiWait
(“%d%d%d%d %d%d%d%d %d%d%d%d %d%d%d%d %d”,
ApcMel_Mischer,alarm,
Tag_2, trend_1,
Tag_3, trend_2,
Tag_4, trend_3,
Tag_5, trend_4,
Tag_6, trend_5,
Tag_7, trend_6,
Tag_8, trend_7,


Tag_9, trend_1c ,
Tag_10, trend_2c,
Tag_11, trend_3c,
Tag_12,trend_4c ,
Tag_13,trend_5c,
Tag_14,trend_6c,
Tag_15,trend_7c,
Apc_X_Trend,trend_X,
Apc_Y_Trend,trend_Y
);
return

1;
}
=======================================================================
poly curve
#include “apdefap.h”
int gscAction(
void
)
{
// WINCC:TAGNAME_SECTION_START
// syntax: #define TagNameInAction “DMTagName”
#define APC_raw1 “raw1”
// next TagID : 2
// WINCC:TAGNAME_SECTION_END
// WINCC:PICNAME_SECTION_START
// syntax: #define PicNameInAction “PictureName”1
#define Pic_1 “PAX.pic_win_5:PA5_bld09_1”
#define object “Polygon_trend”
// next PicID :2
// WINCC:PICNAME_SECTION_END
long i=-1;
BYTE byte[121];
GetTagRaw(APC_raw1,byte,121);
while(++i<121)
SetActualPointTop(Pic_1,object,(byte[i]+170)*SetIndex(Pic_1,object,i+1));
// +170 –> Kurve um 170 Pixel nach unten verschieben
// +170 –> move trend 170 pixel down
return i;
}
========================================================

#include “apdefap.h”
int gscAction(
void
)


{
// WINCC:TAGNAME_SECTION_START
// syntax: #define TagNameInAction DMTagName
#define ApcTest1 “Test1”
#define ApcTest3 “Test3”
#define ApcTest2 “Test2”
#define ApcTest4 “Test4”
#define ApcMSEXCELPath “MSEXCELPath”
#define ApcProjectPath “ProjectPath”
#define ApcRT_Stat”RT_Stat”
// next TagID : 8
// WINCC:TAGNAME_SECTION_END
// WINCC:PICNAME_SECTION_START
// syntax: #define PicNameInAction PictureName
// next PicID : 1
// WINCC:PICNAME_SECTION_END
FILE *datei;
WORD a ;
BYTE b;
char
*c,
*d,
*e;
char t[30];

char tmsexcel[75];
char* file;
char* pp;
BOOL merk;
DWORD dwLaenge;
c=SysMalloc(25);
d=SysMalloc(25);
e=SysMalloc(80);
file = SysMalloc(200);
pp = SysMalloc(120);
pp=GetTagChar(ApcProjectPath);
//Projektpfad einlesen – get Project Path
sprintf(file,“%svariablen.txt”,pp);
printf(“%s\r\n”,file);
/*————————————————————————————————————————————————————————SCHREIBEN IN DAS TXT-FILE – Writing Tags to Text-File
————————————————————————————————————————————————————————*/
if(GetTagBitWait(ApcRT_Stat)==1)
//Wenn RT_Anlaufmerker (RT_Stat) gesetzt – if RT_Stat Bit Flag is set
{
printf(“Anlaufmerker gesetzt – Starting-Bit-Flag set\r\n”);
pp=GetTagChar(ApcProjectPath);
//Projektpfad einlesen – get Project Path


datei = fopen( file,
“w”
);
// TXT-File mit Schreibkennung öffnen
if( datei !=
NULL

)
{
a=GetTagWord(ApcTest1);
//Variablen auslesen und in C-Variablen schreiben
b=GetTagByte(ApcTest3);
c=GetTagChar(ApcTest2);
d=GetTagChar(ApcTest4);
e=GetTagChar(ApcMSEXCELPath);
fprintf( datei,“%d\r\n%d\r\n%s\r\n%s\r\n%s\r\n”, a, b, c, d, e);
// Werte in die Datei schreiben
printf(“Variablen in Datei geschrieben – finished writing tags to file \r\n%d\r\n\
%d\r\n%s\r\n%s\r\n%s\r\n “, a, b, c, d, e);
//Kontrolle in GSC-Runtimefenster
fclose( datei );
//close file
return
1;
// Returnwert zur Kontrolle im GSC-Runtimefenster
}
else printf(
“file open error\r\n”
);
// Ausgabe Text, bei Fehler beim öffnen der Datei
return
0;
}
else
// wenn Anlaufmerker nicht gesetzt
{
/*————————————————————————————————————————————————————————

Lesen aus dem TXT-File – Read Tags from Text File
————————————————————————————————————————————————————————*/
datei = fopen(file,
“r”
);
// TXT_File mit Lesekennung öffnen


if
(datei !=NULL)
{
printf(“\r\nVariablen aus der Datei gelesen – finished reading tags from the
file\r\n”);
fgets(t,30,datei);
//Wert 1 aus der TXT lesen und in C-Variable “t” schreiben
printf(“%s\r\n”,t);
//Kontrolle in GSC-Runtimefenster
SetTagWord(ApcTest1,(WORD)atoi(t));
// Variable beschreiben
fgets(t,30,datei);
//Wert 2 aus der TXT lesen und in C-Variable “t” schreiben
printf(“%s\r\n”,t);
//Kontrolle in GSC-Runtimefenster
SetTagByte(ApcTest3,(BYTE)atoi(t));
// Variable beschreiben
fgets(t,30,datei);
// Wert 3 aus der TXT lesen und in die C-Variable “t” schreiben
dwLaenge=strlen(t);
// Länge des gespeicherten Textes ermitteln
strcpy(&t[dwLaenge–2],“”);

//mit wird um 2 Stellen nach links geschoben um den String ohne \r\n zu terminieren
printf(“%s, laenge=%d\r\n”,t,dwLaenge);
//Kontrolle in GSC-Runtimefenster
SetTagChar(ApcTest2,t);
// Variable beschreiben
fgets(t,30,datei);
// Wert 4 aus der TXT lesen und in die C-Variable “t” schreiben
dwLaenge=strlen(t);
// Länge des gespeicherten Textes ermitteln
strcpy(&t[dwLaenge–2],“”);
//mit wird um 2 Stellen nach links geschoben um den String ohne \r\n zu terminieren
printf(“%s, laenge=%d\r\n”,t,dwLaenge);
//Kontrolle in GSC-Runtimefenster
SetTagChar(ApcTest4,t);
// Variable beschreiben
fgets(tmsexcel,75,datei);
// Wert 5 aus der TXT lesen und in die C-Variable “tmsexcel” schreiben
dwLaenge=strlen(tmsexcel);
// Länge des gespeicherten Textes ermitteln
strcpy(&tmsexcel[dwLaenge–2],“”);
//mit wird um 2 Stellen nach links geschoben um den String ohne \r\n zu terminieren
printf(“%s, laenge=%d\r\n”,tmsexcel,dwLaenge);
//Kontrolle in GSC-Runtimefenster
SetTagChar(ApcMSEXCELPath,tmsexcel);


fclose( datei);
//Datei schließen
return
1;

// Returnwert zur Kontrolle im GSC-Runtimefenster
}
else
{
printf(“\r\nfile open error\r\n”
);
// Ausgabe Text, bei Fehler beim öffnen der Datei
return
0;
}
}
}
===============================================================================
log out
#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 <
(n–i); j++)
if
( obj_name[j]
==
‘:’
)
{
obj_name[j]
=
”;
break;
}
SetVisible(pic_name,obj_name,FALSE);
break;

}
}
================
#include “apdefap.h”
void OnClick(char* lpszPictureName,
char* lpszObjectName,
char* lpszPropertyName)
{
SetVisible(lpszPictureName,“@ERROR”,FALSE);
SetOperation(lpszPictureName,“@LoginIn”,TRUE);
SetOperation(lpszPictureName,“@PasswordIn”,TRUE);
SetOperation(lpszPictureName,“@OK”,TRUE);
Set_Focus(lpszPictureName,“@LoginIn”);
SetVisible(lpszPictureName,lpszObjectName,FALSE);
}
===================================================================
#include “apdefap.h”


Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×