Rockwell Automation 1771-DMC_DMC1_DMC4_DXPS Control Coprocessor User Manual User Manual

Page 80

Advertising
background image

Chapter 5

Developing Programs

5-20

Sample BASIC Program

The following is a BASIC programming example. It uses both
BPI_WRITE and BPI_READ functions to trigger programmable-
controller block-transfer writes and reads.

rem Sample BPI Basic Program
dim retval, rdata(10),wdata(5),loopcnt,timeout,trigmask,i:integer
dim Wlength,rlength:byte
loopcnt=0
rem timeout is number of seconds BPI_BTR or BPI_BTW will be attempted by CO_PRO
timeout=4
rem rlength is BTW length in plc; when CO-PRO does a BPI_BTR, plc does a BTW
rlength=10
rem wlength is BTR length in plc; when CO-PRO does a BPI_BTW, plc does a BTR
wlength=5
rem trigmask is value written to input image table; can be used to trigger BTs
trigmask=0
rem initialze the BPI_BTW data
FOR i=1 to 5
wdata(i)=0
NEXT i
rem initialize coprocessor with CC_INIT, which is AB_BASIC function number 0.
RUN AB_BAS(0)
rem do a clear screen
PRINT CHR$(27);“[2J”
1 rem line #1 used for got to
rem do a logical or of trig mask to set bit 10
trigmask=LOR(256,trigmask)
rem BPI_BTR
RUN AB_BAS(34,retval,rlength,addr(rdata(1)),timeout,trigmask)
IF retval<>0 THEN
PRINT CHR$(27);“[15,0H”
PRINT “BTR retval=”;retval
rem return the first 5 words of the BPI_BTR in the BPI_BTW
ELSE
FOR i = 1 TO 5
wdata(i)=rdata(i)
NEXT i
rem cursor home
PRINT CHR$(27);“[H”
FOR i= 1 TO 10
PRINT “WORD ”;i;“ OF PLC BTW = ”;rdata(i)
NEXT i
rem erase to end of screen
PRINT CHR$(27);“[J”
ENDIF
rem reset bit 10
trigmask=LAND(-257,trigmask)
rem just a screen activity indicator
PRINT CHR$(27);“[13,0H SCREEN REFRESH INDICATOR ”;loopcnt
loopcnt=loopcnt+1
rem do a logical or of trig mask to set bit 11
trigmask=LOR(512,trigmask)
rem BPI_BTW
RUN AB_BAS(33,retval,wlength,addr(wdata(1)),timeout,trigmask)
IF retval<>0 THEN
PRINT CHR$(27);“[16,0H”
PRINT “BTW retval=”;retval
ENDIF
rem reset bit 11
trigmask=LAND(-513,trigmask)
GOTO 1

CC_INIT function

is used; called by

RUN AB_BAS(0)

This is the BASIC

function number.

See Appendix B.

Advertising