Você está na página 1de 5

Bi ging tch hp PLC S7 200

Ng Thanh ng

NH NG TRONG WINCC 1. TO NH NG THEO CHIU NGANG: Trong bi ny ta to 1 nt nhn dch tri, 1 nt nhn dch phi, 1 nt nhn dng, 2 tag: tag_dichtrai v tag_dichphai. Khi nhn nt dch tri nh s dch chuyn sang tri, khi nhn nt dch phi nh s dch chuyn sang phi, nhn nt dng nh s dng.

Cc bc vit chng trnh cho hnh trn dch chuyn. Nhn dch tri Nhn dch phi Nhn nt dng settagbit Settagbit Settagbit Tag_dichtrai = 1 Tag_dichphai=0 tag_dichtrai = 0 tag_dichphai = 1 Tag_dichtrai = 0 Tag_dichphai = 0 Vit c action cho ta x ca hnh trn Vi nt nhn dch tri:

Bi ging tch hp PLC S7 200

Ng Thanh ng

Lm tng t cho nt nhn dch phi: Properties / events / mouse / mouse action / C action
2

Bi ging tch hp PLC S7 200


Chng trnh C action ca nt nhn dch phi: #include "apdefap.h"

Ng Thanh ng

void OnClick(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName) { SetTagBit("tag_dichphai",1); SetTagBit("tag_dichtrai",0); } Lm tng t cho nt nhn dng: Properties / events / mouse / mouse action / C action Chng trnh C action ca nt nhn dch phi: #include "apdefap.h" void OnClick(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName) { SetTagBit("tag_dichphai",0); SetTagBit("tag_dichtrai",0); } Vit chng trnh cho hnh trn di chuyn: Kch chut phi ln hnh trn chn properties chn th properties chn Geometry chn Position X C-action: #include "apdefap.h" long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName) { static int a=100; if (GetTagBit("tag_dichtrai")&&a>=100) { a = a - 10; } if (GetTagBit("tag_dichtrai")&&a <=100) a = 150;
3

//Return-Type: BOOL //Return-Type: BOOL

//Return-Type: BOOL //Return-Type: BOOL

Bi ging tch hp PLC S7 200

Ng Thanh ng

if (GetTagBit("tag_dichphai")&&a<=150) { a = a + 10; } if (GetTagBit("tag_dichphai")&&a>=150) a = 100; return a; } 2. TO NH NG THEO NG CHO: Gi s ta cn to 1 hnh trn di chuyn t ta (x,y) = (200,200) n ta (x,y) = (400,300),s bc dch chuyn 10 bc. T yu cu ta c: dch chuyn theo chiu x l: (400-200)/10 = 20. dch chuyn theo chiu y l: (300-200)/10 = 10. Ta mt tag tn tag_dich_xy1 -loi d liu binary tag, mt tag tn tag_dich_xy2 loi d liu unsigned 32 bit, mt nt nhn di chuyn xy, mt nt nhn dng.

Vit chng trnh cho ng trn: Kch chut phi trn ng trn chn properties chn th properties chn Geometry chn Position X C-Action v vit on code nh bn di. (Event name chn trigger 250ms) Postion Y lin kt n tag_dich_xy2, chn Upon change. #include "apdefap.h" long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName) { static int x=200,y=200;
4

Bi ging tch hp PLC S7 200


if(GetTagBit("tag_dich_xy1")&& x<400) { x = x+20; y = y+10; } if(GetTagBit("tag_dich_xy1")&& x>=400) {x = 200; y = 200; } SetTagDWord("tag_dich_xy2",y); return x; }

Ng Thanh ng