Rockwell Automation 1771-DMC_DMC1_DMC4_DXPS Control Coprocessor User Manual User Manual

Page 77

Advertising
background image

This is the BASIC

function number.

See Appendix B.

Chapter 5

Developing Programs

5-17

Sample BASIC Program

The following is a BASIC programming example that illustrates the
interface to various API functions. The program uses CC_ERRSTR to
copy the status of the various functions and display the string to the
terminal—i.e., CC_INIT, DTL_INIT, DTL_CLOCK, and DTL_READ_W.

rem ****************************************************************************
rem * DEMO.BAS - This basic program demonstrates a few AB API functions *
****************************************************************************
procedure DEMO
DIM ret_val : INTEGER
DIM name_id : INTEGER
DIM iostat : INTEGER
DIM avail : INTEGER
DIM rcvbuff : INTEGER
DIM buffer : STRING[81]
rem * CC_INIT - This call must be made before any other API functions are called
RUN AB_BAS (0)
rem * CC_DISPLAY_STR - Display the string -AB- on expander module
RUN AB_BAS (102,ret_val,“-AB-”)
rem * CC_ERRSTR - Get the string for the ret_val - display on terminal
RUN AB_BAS (101,ret_val,ret_val,ADDR(buffer))
print buffer
rem * DTL_INIT - Initialize DTL for 4 definitions
RUN AB_BAS (1,ret_val,4)
rem * CC_ERRSTR - Get the string for the ret_val - display on terminal
RUN AB_BAS (101,ret_val,ret_val,ADDR(buffer))
print buffer
rem * DTL_CLOCK - synchronize our clock with the PLC-5
RUN AB_BAS (18,ret_val)
rem * CC_ERRSTR - Get the string for the ret_val - display on terminal
RUN AB_BAS (101,ret_val,ret_val,ADDR(buffer))
print buffer
rem * DTL_C_DEFINE - Define a data element
RUN AB_BAS (2,ret_val,ADDR(name_id),“n7:0,1,long,MODIFY”)
rem * CC_ERRSTR - Get the string for the ret_val - display on terminal
RUN AB_BAS (101,ret_val,ret_val,ADDR(buffer))
print buffer
rem * DTL_DEF_AVAIL - How many are available now? (4 - 1 = ?)
RUN AB_BAS (4,ret_val,ADDR(avail))
rem * CC_ERRSTR - Get the string for the ret_val - display on terminal
RUN AB_BAS (101,ret_val,ret_val,ADDR(buffer))
print buffer
rem * Print how many definitions are available now
print avail
rem * DTL_READ_W - Read form N7:0 1 word into rcvbuff
RUN AB_BAS (5,ret_val,name_id,ADDR(rcvbuff),ADDR(iostat))
rem * CC_ERRSTR - Get the string for the ret_val - display on terminal
RUN AB_BAS (101,ret_val,ret_val,ADDR(buffer))
print buffer
rem * Print iostat
print iostat
rem * Print the read data
print rcvbuff
rem * CC_DISPLAY_EHEX - Display read data to the expander display
RUN AB_BAS (105,ret_val,rcvbuff)
rem * CC_ERRSTR - Get the string for the ret_val - display on terminal
RUN AB_BAS (101,ret_val,ret_val,ADDR(buffer))
print buffer
end

CC_INIT function

is used; called by

RUN AB_BAS(0)

Advertising