• No results found

Accessing the PCM’s LEDs

Section 3: MegaBasic Programming Examples

There are two examples in this section, one showing the steps to develop a simple MegaBasic program and the second showing how to get the example program SAMPLE.PGM running on the PCM. These examples assume the PCM has been configured using Logicmaster 90 for BASIC mode or by PCOP for BASIC operation.

Program development is begun by connecting the programming cable from the

programmer to the PCM, setting the default directory to \PCOP\EXAMPLES.PCM, and typing TERMF to start up the TERMF terminal emulation program. Then, press the PCM Restart/Reset pushbutton for 10 seconds to place the PCM in PROGRAM mode.

The MegaBasic banner is displayed on the screen, followed by the “Ready” prompt.

MegaBasic Version 5.602, under PCM VTOS v2.50 IEEE/Software floating point on an 80186/88 CPU Copyright (C)1985-1990 by Christopher Cochran MegaBasic Support BBS: 415-459-0896, PO Box 723 Fairfax, CA. USA 94930 -- Serial #0000

Ready

Now, enter the single line of the program shown below. After typing the line, save the program to the RAM Disk as BASIC.PGM using the SAVE command. Answer Y to the program creation prompt:

Ready

10 print “hello, world”

Ready

save basic.pgm

RAM:BASIC.PGM file not found, create it? y 2 lines 20 code bytes

Ready

When a soft reset is initiated, the MegaBasic banner is displayed and the program is executed:

MegaBasic Version 5.602, under PCM VTOS v2.50 IEEE/Software floating point on an 80186/88 CPU Copyright (C)1985-1990 by Christopher Cochran MegaBasic Support BBS: 415-459-0896, PO Box 723 Fairfax, CA. USA 94930 -- Serial #0000

hello, world

After pressing the PCM Restart/Reset pushbutton again for 10 seconds to place the PCM in PROGRAM mode, the example program distributed with TERMF and PCOP can be transferred to the PCM. Because this is a large program, there is a long delay after executing the LOAD command before the PCM again displays the “Ready” prompt.

Note that the LOAD command must specify PC: as the source since the program is being loaded from the programmer.

MegaBasic Version 5.602, under PCM VTOS v2.50 IEEE/Software floating point on an 80186/88 CPU Copyright (C)1985-1990 by Christopher Cochran MegaBasic Support BBS: 415-459-0896, PO Box 723 Fairfax, CA. USA 94930 -- Serial #0000

Ready

load pc:sample.pgm

405 lines 15,529 code bytes Ready

Now save this program as BASIC.PGM. Since the old copy of BASIC.PGM still exists on the RAM Disk, the PCM prompts as to whether to overwrite the old copy.

Ready

save ram:basic.pgm

RAM:BASIC.PGM file already exists, OK? y 405 lines 15,529 code bytes Ready

This example program accesses one of the utility packages, VT100_5.PGM, included with the PCM programming software. VT100_5.PGM contains routines for writing to a VT100 compatible screen. Since VT100_5.PGM must be available to the main program following a reset, it is loaded from the EXAMPLES.PCM directory into the PCM RAM Disk.

Ready

load pc:vt100_5.pgm Into a new workspace? n 150 lines 3930 code bytes Ready

save ram:

RAM:VT100_5.PGM file not found, create it? y 150 lines 3930 code bytes

Ready

The DIR command shows that the RAM Disk contains three files: BASIC.PGM,

VT100_5.PGM, and HARDEXEC.BAT. HARDEXEC.BAT is the startup program used by the PCM after a hard reset.

Ready dir

VT100_5.pgm BASIC.pgm HARDEXEC.bat Ready

If a soft reset is initiated, the PCM comes up executing the example program. By following the displayed instructions, this program can be used to monitor and change references in the PLC ’s %R, %I, and %Q tables.

10 Rem *** EXAMPLE MEGABASIC PROGRAM FOR PCM ***

20 Rem

30 Rem This program implements a simple operator interface, which can 40 Rem be easily modified for a particular application. This program 50 Rem provides examples of the most commonly used MegaBasic commands 60 Rem and extensions. It can be run using either port of the PCM and 70 Rem assumes that a VT100, OIT or PC running Termf is connected.

80 Rem

90 Rem First, access the MegaBasic subroutine package which handles 100 Rem screen formating. It must have been previously loaded into RAM.

110 Rem

120 Access “RAM:VT100_5.PGM”

130 Rem Now assign MegaBasic channel number #5 to whatever port is 140 Rem is being used for the display. The screen formatting package 150 Rem accessed above assumes that #5 is the output device

160 Rem

170 Open #5,“COM1:”

180 Rem Disable control-C processing so that it doesn’t interfere with 190 Rem the keyboard handling routines. Since automatic control-C 200 Rem detection will be disabled, the program must do its own 210 Rem checking, if a control-C stop is desired.

220 Rem 230 Param(1)=1

240 Rem Assign each menu a number, for switching between the menus.

250 Rem

260 Def integer MAIN_MENU 270 Def integer REG_MENU 280 Def integer INPUT_MENU 290 Def integer OUTPUT_MENU 300 MAIN_MENU = 1

310 REG_MENU = 2 320 INPUT_MENU = 3 330 OUTPUT_MENU = 4

340 Rem All of the menus are implemented as subroutines and are called 350 Rem from the main loop below. A variable called NEXT_MENU is used to 360 Rem keep track of the next menu to display. When the user wants to 370 Rem change menus, the active menu subroutine sets the NEXT_MENU 380 Rem variable and returns to the main loop. To add a new menu, define 390 Rem a new number for it, as above, write a subroutine to implement 400 Rem the menu, and add another case statement in the loop below.

410 Rem

420 Def integer NEXT_MENU

430 NEXT_MENU = MAIN_MENU; Rem Run the main menu first

560 Rem This is the main menu subroutine. It displays the various

810 Rem The following loop continuously checks for user input 820 Rem

1030 Rem This is the register display subroutine. It displays a block 1040 Rem of eight registers at a time. The user can change the value of 1050 Rem a register or display a different group of registers. No error 1060 Rem checking is done, and the display freezes while the operator 1070 Rem is entering data.

1080 Rem

1090 Def proc DO_REG_MENU 1100 Rem

1180 Rem

1190 Rem The following few lines draw the static part of the register 1200 Rem menu screen, using the same format as the main menu

1210 Rem 1220 CLS 1230 ATTR 1240 CUR 4,10

1250 Print #5, DW_DH_TOP$, 1260 Print #5,“REGISTER DISPLAY”, 1270 CUR 5,10

1280 Print #5, DW_DH_BOT$, 1290 Print #5,“REGISTER DISPLAY”, 1300 CUR 20,20

1310 Print #5,“1 - DISPLAY NEW REGISTERS”, 1320 CUR 21, 20

1400 Rem Build some strings for handling the command line 1410 Rem

1420 CMD_LINE$ = ATTR$(BLINK)+“*** ENTER NUMBER ***”+ATTR$(ATTR_OFF) 1430 CLR_CMD_LINE$ = CUR$(24,24)+(” ”*32)+CUR$(24,24)

1440 Rem SYSLINK the REG_ARRAY variable with %R1 in the PLC.

1450 Rem The SYSREAD command below will then copy the 8 registers 1460 Rem starting at %R1 to REG_ARRAY.

1470 Rem

1480 SYSLINK REG_ARRAY, “%R1”, UINT 1490 BASE_REG% = 1

1500 Rem This is the main processing loop for the register menu 1510 Rem

1520 Repeat

1530 SYSREAD REG_ARRAY; Rem Read PLC registers and display them 1540 For I% = 0 to 7 1640 Rem operator input using the inchr$ statement, or with NOWAIT_READs 1650 Rem of the keyboard, however, a fairly complicated state machine 1660 Rem would have to be used to figure out what to do when each key

1720 Rem To display new registers, first UNLINK with

2040 Rem This is the input display subroutine. It displays a block 2050 Rem of sixty four inputs at a time. The user can change the value of 2060 Rem an input or display a different group of inputs. No error 2070 Rem checking is done, and the display freezes while the operator 2080 Rem is entering data.

2090 Rem

2100 Def proc DO_INPUT_MENU 2110 Rem

2120 Local BASE_INPUT%; Rem Sets which inputs to display

2200 Rem The following few lines draw the static part of the input 2210 Rem menu screen, using the same format as the main menu 2220 Rem

2230 CLS 2240 ATTR 2250 CUR 4,9

2260 Print #5, DW_DH_TOP$,

2270 Print #5,“INPUT TABLE DISPLAY”, 2280 CUR 5,9

2290 Print #5, DW_DH_BOT$,

2300 Print #5,”INPUT TABLE DISPLAY”,

2410 Rem Build some strings for handling the command line 2420 Rem

2430 CMD_LINE$ = ATTR$(BLINK)+“*** ENTER NUMBER ***”+ATTR$(ATTR_OFF) 2440 CLR_CMD_LINE$ = CUR$(24,24)+(” ”32)+CUR$(24,24)

2450 Rem SYSLINK the INPUT_ARRAY variable with %I1 in the PLC.

2460 Rem The SYSREAD command below will then copy the 64 inputs 2470 Rem starting at %I1 to INPUT_ARRAY.

2480 Rem

2490 SYSLINK INPUT_ARRAY, “%I1”, BYTE 2500 BASE_INPUT% = 1

2510 Rem This is the main processing loop for the input menu 2520 Rem

2530 Repeat

2540 SYSREAD INPUT_ARRAY; Rem Read PLC inputs and display them 2550 For I% = 0 to 7 2650 Rem operator input using the inchr$ statement, or with NOWAIT_READs 2660 Rem of the keyboard, however, a fairly complicated state machine 2670 Rem would have to be used to figure out what to do when each key

2850 Rem To write an input, SYSLINK with the input

3050 Rem This is the output display subroutine. It displays a block

3060 Rem of sixty four outputs at a time. The user can change the value of 3070 Rem an output or display a different group of outputs. No error 3080 Rem checking is done, and the display freezes while the operator 3090 Rem is entering data.

3100 Rem

3110 Def proc DO_OUTPUT_MENU 3120 Rem

3210 Rem The following few lines draw the static part of the input 3220 Rem menu screen, using the same format as the main menu 3230 Rem

3240 CLS 3250 ATTR 3260 CUR 4,8

3270 Print #5, DW_DH_TOP$,

3280 Print #5,“OUTPUT TABLE DISPLAY”, 3290 CUR 5,10

3300 Print #5, DW_DH_BOT$,

3310 Print #5,“OUTPUT TABLE DISPLAY”, 3320 CUR 20,20

3420 Rem Build some strings for handling the command line 3430 Rem

3440 CMD_LINE$ = ATTR$(BLINK)+“*** ENTER NUMBER ***”+ATTR$(ATTR_OFF) 3450 CLR_CMD_LINE$ = CUR$(24,24)+(“ ”*32)+CUR$(24,24)

3460 Rem SYSLINK the OUTPUT_ARRAY variable with %Q1 in the PLC.

3470 Rem The SYSREAD command below will then copy the 64 outputs 3480 Rem starting at %Q1 to OUTPUT_ARRAY.

3490 Rem

3500 SYSLINK OUTPUT_ARRAY, “%Q1”, BYTE 3510 BASE_OUTPUT% = 1

3520 Rem This is the main processing loop 3530 Rem

3540 Repeat

3550 SYSREAD OUTPUT_ARRAY; Rem Read PLC outputs and display them 3560 For I% = 0 to 7 3660 Rem operator input using the inchr$ statement, or with NOWAIT_READs 3670 Rem of the keyboard, however, a fairly complicated state machine 3680 Rem would have to be used to figure out what to do when each key

5

figure bi level 1 table_big level 1

MegaBasic is a powerful implementation of the BASIC language which runs under twelve different operating systems and a host of different hardware configurations.

One of the strengths of MegaBasic is that the language can be “extended” to support the underlying hardware. This chapter describes the additions, called extensions, that GE has made to MegaBasic. These additions or extensions allow MegaBasic to take full advantage of the special capabilities of the PCM and the Series 90 system.

This chapter contains the following sections:

Section Title Description Page

1 MegaBasic Error

Codes Section 1 lists common error codes from the PCM

extensions to MegaBasic. 5-3

2 Screen Formatting

Commands Section 2 describes predefined control sequences for manipulating a VT100 compatible display. These functions and procedures are located in VT100.PGM.

5-5

3 Accessing %P, %L, and Password-Protected Data

Section 3 describes definitions and procedures used to access user references not directly supported by the PCM backplane driver and to access data protected by a user password. These procedures are found in GENERIC.PGM.

5-16

4 Access to PLC Fault Tables and PLC Status

Section 4 describes how to access the PLC and I/O fault tables from a MegaBasic program, using RD_FLT.PGM. 5-21

5 Gathering PLC Information from MegaBasic Programs

Section 5 describes how to use UTILITY.PGM to

obtain a variety of PLC CPU data. 5-34

6 Loading and Storing PCM Data Files Using TERMF

Section 6 describes how to load MegaBasic data files and utility packages in binary form to the PCM using TERMF and the PCM command interpreter.

5-50

7 Serial Port Setup with IOCTL and PORT_CTL.BIN

Section 7 describes how to change the PCM serial port configuration, send and detect serial breaks, and use the modem control and status signals of the serial ports in MegaBasic programs.

5-52

8 Timers and Logical

Interrupts Section 8 describes timer and backplane interrupts. 5-57

9 COMMREQs and

Other Backplane Messages

Section 9 describes the processing of messages from

COMMREQ function blocks and other sources. 5-64

Section Title Description Page 10 Asynchronous Serial

Input and Output Section 10 describes the the NOWAIT I/O commands that support asynchronous serial communications.

These commands include:

S NOWAIT_OPEN. S NOWAIT_CLOSE. S NOWAIT_READ. S NOWAIT_WRITE. S NOWAIT_SEEK. S NOWAIT_READ_ABORT. S NOWAIT_WRITE_ABORT.

5-91

11 VME Functions Section 11 describes the use of Series 90-70 VME functions as alternatives for communicating with a Series 90-70 PCM.

5-100

12 PCM Programming Example using MegaBasic

Section 12 provides a complete programming example containing PLC VME functions and EXAM and FILL MegaBasic statements.

5-110

13 Optimizing Backplane Communication

Section 13 describes how to maximize data throughput

between the PCM and the PLC CPU. 5-114