Programming example – BECKHOFF BC8000 User Manual

Page 29

Advertising
background image

Appendix

BC8000

29


Programming Example

Local variables in program
MAIN

PROGRAM MAIN
(* Program description

*)

(* The BC8000 sends a word of output data every 500ms to a BK8000 *)
(* at that time the low byte is always incremented by one

*)

(* The BK8000 then returns a word of input data

*)

(* The BC8000 analyzes this, shifts the byte one bit to the left and

*)

(* again outputs it on its output terminals. Required hard/software:

*)

(* 1 x BC8000,1 x KL1104, 2 x KL2114, 1x 9010, 1 x BK8000,

*)

(* 2 x KL1104, 2 x KL2112, 1 x KL9010

*)

(* Communications Lib, serial cable with two D-sub plugs

*)

VAR

ComControl : KL6Control5B; (* function bloc for automatic *)

(* communication *)

Receive: ReceiveByte; (* function bloc for receiving data *)

Send: SendByte

(* function bloc for sending data *)

Sb: BYTE;

Senden:ARRAY[0..6] OF BYTE;

start: BOOL; (* auxiliary variable set to FALSE for the first cycle *)

i2: USINT;

i3: USINT;

Summe: BYTE;

(* checksum *)

Timer1: TON;

(* starts transmission every 500 ms*)

Starten: BOOL;

(* set TRUE every 500ms until all *)

(* data have been sent *)

J0: UINT;

t1: INT;

byAusgang1:ARRAY[0..20] OF BYTE;

EingWorte: USINT;

END_VAR

MAIN program











ComControl




Sending









IF NOT start THEN (* Initialization of the array for the BK8000 protocol *)

senden[0]:=16#50;

(* start marker *)

senden[1]:=16#01;

(* number of words to be sent *)

senden[2]:=16#11;

(* message ident *)

senden[3]:=16#0B;

(* coupler address *)

senden[4]:=16#FF;

(* DO *)

senden[5]:=16#FF;

(* D1 *)

senden[6]:=16#6B;

(* checksum *)

Start:=TRUE;

END_IF
(*++++++++++++++++++++++++++++++++++++++++++++++++++++++*)
(* Handshake with the terminal or terminal emulation *)
ComControl(

COMin:=KL6InData ,

COMout:=KL6OutData ,
TxBuffer:=TxBuffer ,
RxBuffer:=RxBuffer );


(*-------------------------------- TRANSMISSION --------------------------------------*)
Timer1(IN:=NOT Timer1.Q,PT:=t#100ms); (* a protocol is transmitted *)

(* every 0.5 seconds *)


IF Timer1.Q THEN

Starten:=TRUE;

END_IF

IF Starten THEN
(*------------------------- calculate CHECKSUM --------------------------------------*)

Summe:=0;

Advertising
This manual is related to the following products: