Browse
(440) 299-7778
Menu
(440) 299-7778
One-year parts and labor warranty30-day money-back guaranteeEnglishEspañolContact

The text of a manual · part 15 of 25

Attended Workstations (Catalog Nos. 2708-DH5B2L & -DH5B4L) (Series B) User Manual: 13 - A-B VBASIC Application Library

Pages 113 to 121 of 186, from Attended Workstations (Catalog Nos. 2708-DH5B2L & -DH5B4L) (Series B) User Manual

The original document is the PDF (513 KB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.

For the Allen-Bradley 2708

Page 113

Chapter

A–B

13

A-B VBASIC Application Library Introduction

The BASIC Language Development Kit (Catalog No. 2708-NBD) consists of a set of BASIC source files which you may use to decrease your development time and enhance the quality of your A-B VBASIC applications. Note: Subroutines for the A-B VBASIC Application Library can be found in Appendix M of this manual. The core of the library is the module ENV.BAS. ENV.BAS provides a set of I/O routines for access to the workstation devices such as the bar code port, comm ports, network, and so on. Since virtually all workstation applications are driven by external events from multiple devices, ENV provides a simple mechanism for reading from more than one I/O device at once with timeouts. In order to speed developoment on IBM PC compatible computers, we have provided a second library of subroutines (ENVPC.BAS) with names identical to those in ENV.BAS, but which use standard PC devices to emulate 2708-DH5B2L or -DH5B4L workstations. This allows testing of A-B VBASIC applications under MicroSoft’s Visual BASIC. ENVPC allows you to simulate input from slot readers, comm ports, and the network all on your development PC without needing an actual workstation. READ.BAS provides a library of field oriented I/O subroutines. You may read string fields, autoexit fields, numeric fields, secured (password) fields, and fields with default values using the routines. The FORMEX.BAS example program demonstrates forms style entry using READ.BAS. MENU.BAS subroutines allow you to create visually oriented selection menus for easy-to-use application programs. This is also demonstrated by the example program FORMEX.BAS. The IOTEST directory contains examples for A-B VBASIC Low Level I/O. Scientific math support for process control applications is provided with MATH.BAS, TRIG.BAS, and HYP.BAS.

13–1

Page 114

Chapter 13 A-B VBASIC Application Library

Using the Library

Installation consists of installing the diskette in drive A: and typing: A: INSTALIB d: Where d is the destination drive. You must first set up Visual BASIC, see Microsoft manual “Learning to Use Microsoft Visual BASIC” for installation procedures (manual is provided with the software). Also, make sure that the commands VB and LXBC are available from the installed directory “ \ LIB”. The A-B VBASIC compiler requires that all of your program reside in a single file. (It does not support a LINK step which would combine multiple independent object files into a single run file.) Since the BASIC Language Development Kit is made up of multiple files, the normal way to use it is to append all of the desired modules together and then load the resultant file under Visual BASIC or compile it with the A-B VBASIC Compiler. The only required module of the library when testing on the PC is ENVPC.BAS. Suppose you have the following program: DEFINT A–Z ’ Recommend default variable type OpenLINX ’ REQUIRED library initialization TIMEOUT% = 1000 ’ Set a 10 second timeout DO CLD PRINT “Library Test” PRINT “Do something” ; ’ 2nd line MUST have; or scrolls e = ReadEvent% (2) ’ The mask (the 2) means read SELECT CASE e ’ from keyboard/bdg with timeout. CASE TimeoutEvent ’ The 10 seconds expired so make CLS: PRINT “ *Timeout* ” ’ this obvious. BEEP : SLEEP 2 CASE BadgeEvent : CLS ’ The event that occurred was a PRINT “Badge read” ’ Bar code badge. PRINT InBuf$; ’ The badge contents is in InBuf$ BEEP : SLEEP 2 ’ Make some noise, and show badge. CASE ELSE : CLS ’ Case Else required in LinxBASIC!! PRINT “Key = ” ;e; ’ Display ASCII code for the key SLEEP 2 ’ or negative code if its special. END SELECT LOOP ’ Do this test forever

13–2

Page 115

Chapter 13 A-B VBASIC Application Library

Using the Library (cont’d)

If you don’t want to type this in, you will find this sample program under ENVEX1.BAS. Now, assuming that the VB command (Visual BASIC) is in your directory or is set up in your DOS PATH for you to access it, you could enter the following DOS commands: TYPE ENVPC.BAS > MAIN.BAS TYPE ENVEX1.BAS > > MAIN.BAS VB/RUN MAIN.BAS

The first TYPE command copies the ENVPC library source file into MAIN.BAS. The second type command appends your test program to MAIN.BAS. Finally, the command VB/RUN MAIN.BAS tells Visual BASIC to run and start executing MAIN.BAS. A batch file is provided which you can use to do the DOS commands which were shown above. This batch file is supplied on the distribution diskette. To use it, type: LVB ENVEX1 You will note that LVB.BAT also includes READ.BAS and MENU.BAS into the MAIN.BAS which it creates. If you do not need these modules, remove the TYPE lines for them from the batch file. When you type the VB command, the Visual BASIC screen should be displayed and the bottom line will display “Loading and parsing” for a few seconds. Then it will say “Binding”, and then the I/O environment emulator will be running, with your program executing. Type ALT X or TAB then X to stop the Emulation.

Writing Programs

After examining the example BASIC programs and running them under the emulator, you should be ready to write your own. The subroutines are listed in Appendix M, along with the required arguments and returned values. Start with a small application and refer to the source code of the following files: FORMEX.BAS, ENV.BAS, READ.BAS and MENU.BAS for info about how to use each routine. Also print copies; of any BASIC files which interest you, as these will provide insight into various ways to use A-B VBASIC. When you are ready to test your program on the workstation, you should first compile it using the A-B VBASIC Cross-compiler LXB. The LLXB.BAT batch file has the same syntax as LVB, except it starts with ENV.BAS instead of ENVPC.BAS. When having subtle syntax problems, try examining MAIN.BAS or using LXBC to create a listing of MAIN.BAS.

13–3

Page 116

Chapter 13 A-B VBASIC Application Library

Using the ENVPC Simulator

Figure 13.1 ENVPC Main Screen (Running ENVEX1)

Library Test Do something

Timeout of 1000 has 900 left.

123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789

1

^

2

3

4

5

6

7

BDGE RX : HOST RX : NET TX : QUE RX : COM RX : COM TX : AUX RX : AUX TX : Rts1=Off Dtr1=Off Dsr1=Off Rts2=Off Dtr2=Off Dsr2=Off Line=Off 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 Press TAB or ALT(A...Z) to receive a record from another device

TAB X or ALT X: CTRL-BREAK: TAB S or ALT S: TAB B or ALT B: TAB H or ALT H:

TERMINATES emulation. Pauses program and enters Visual BASIC environment. Slot reader manual input. You key in a record which will be read as slot reader input. Same as above (B is for Badge reader input). Host manual input. You key in a record which simulates a record from the host computer. Leave the station number off of the record.

If your actual host would send: “1-23:REJECT/Bad lot number” To workstation 23 attached to Master 1, you should just enter: “REJECT/Bad lot number”

13–4

Page 117

Chapter 13 A-B VBASIC Application Library

Using the ENVPC Simulator (cont’d)

Since that is all that your BASIC program would input. TAB C or ALT C:

TAB A or ALT A: TAB D or ALT D:

TAB L or ALT L:

TAB F or ALT F:

TAB N or ALT N:

Com port manual input. You key in a record which simulates an input record from your RS-232 or RS-422 com port. Note that Master, Submaster, and Concentrator workstations cannot use the com port since it is in use by the network. Aux port manual input. A manual input record from RS-232 or AUX port. Puts the display in 40 column mode (FOR COLOR MONITORS ONLY!). The next TAB or ALT command will switch back to 80 column mode. Starts or stops logging. When logging is enabled, all output to all devices (except the display and front panel LEDs), and all input (except from the keyboard) is recorded in a file (usually named LINXIO.LOG). The log file contains a timestamp and device name for each I/O record. Opens a device input file. The Barcode, Host, Com, and Aux devices may each have an open device input file. Each time you press ALT N, the next record can be input from that file instead of keying in the records by hand. This can be a big time saver when simulating a complex application. You will be asked for the device that you want to input for (BC, H, C, or A) and you select the letter. You are then asked for a file name to input from. Make sure you enter the correct name or the emulator will terminate. If only a single device input file is open, then this will perform a device read from that file. If more than one device input file is open, then you will be prompted for the device which you want to input for (BC, H, C, or A).

A – Predefined Constants Predefined constants are available in Env.BAS and EnvPC.BAS. TRUE and FALSE may be assigned to integer variables which are used as boolean variables.

13–5

Page 118

Chapter 13 A-B VBASIC Application Library

Using the ENVPC Simulator (cont’d)

The lower ASCII characters from 0 to 31 and 127 are named. These are: NUL = 0 SOH = 1 STX = 2 ETX = 3 EOT = 4 ENQ = 5 ACK = 6 BEL = 7 DEL = 27

BS = 8 HT = 9 LF = 10 VT = 11 FF = 12 CR = 13 SO = 14 SI = 15

DLE = 16 DC1 = 17 XON = 18 XON = 19 XOFF = 20 NAK = 21 SYN = 22 ETB = 23

CAN = 24 EM = 25 SB = 26 ESC = 27 FS = 28 GS = 39 RS = 30 VS = 31

The function keys are named F1..F10. The SHIFTED and ALT function keys are available as ShiftF1..ShiftF10 and AltF1..AltF10. Alt letters are available as AltA..AltZ. Note that ENVPC uses the Alt keys for control. Special key equates are: ClearKey, ExitKey, EnterKey, Up, Left, InKey, OutKey, Right, and Down Note: Left is identical to BS (backspace) on the workstation.

B – Global Variables InBuf$: . . . . . . . . . . . . Filled when SlotEvent WandEvent occurs InCom$: . . . . . . . . . . . Filled when ComEvent or AuxEvent occurs InNet$: . . . . . . . . . . . . Filled when NetEvent occurs DSPWIDTH%: . . . . . . Width of the display in characters (40/16) (set in OpenLINX) ONLINE%: . . . . . . . . . Set to TRUE when Master is polling (set by TestEvent%) MEMFULL%: . . . . . . Set to TRUE when File or QUE memory is almost gone PENDING%: . . . . . . . Set to TRUE when a Send will pause COMOPEN%: . . . . . . TRUE if this is a normal workstation (set in OpenLINX) TERMNUM%: . . . . . . Number of this workstation (set in OpenLINX) TERMTYPE$: . . . . . . Type of workstation (set in OpenLINX) EXITEVENT%: . . . . . Event code of the last event from a Read% EXITOFFSET%: . . . . Offset in a menu or string from ReadStrField% and Menu%

13–6

Page 119

Chapter 13 A-B VBASIC Application Library

Using the ENVPC Simulator (cont’d)

MODIFIED%: . . . . . . True when a read changes the default value TIMEOUT%: . . . . . . . YOU set to 100th seconds before a timeout for reads BLOBALMASK%: . . YOU set mask used for ReadStr%, ReadStrField%, ReadInt% etc. GLOBALATTR%: . . . YOU set attributes use for ReadStr%, ReadInt%, etc. INSERTMODE%: . . . YOU set FALSE to disable insert mode on Read...

C – BASIC Language Development Kit Limitations The BASIC Language Development Kit (Catalog No. 2708-NBD) subroutines provide access to all of the devices supported by the workstation. The following are some of the I/O methods that they do not support. If ENV is unable to provide exactly the kind of support you require, MODIFY BOTH ENV.BAS AND ENVPC.BAS to add the special support you need. This way you can continue to debug your program under the Visual BASIC Environment before you download it to the workstation. You don’t have to use ENV or any part of it. We recommend it because it greatly speeds development and provides a common base for many workstation applications.

D – PC Simulation Constants and Variables Note: Device numbers #20 and up are reserved for use by ENV.BAS. PcMode . . . . . . . . . . . . is TRUE when running under the emulator (ENVPC.BAS) DSPWIDTH% . . . . . . is set to 40 EmAltAccess is TRUE. Set it to FALSE to allow your program to access ALT keys. These are normally trapped by the emulator for device I/O access. Bar code data is collected with the subroutine TestEvent%. The subroutine will return a BadgeEvent when the data has been read into InBuf$. Examine BadgeType for barcode inputs to get the bar code type (“Code 3 of 9”, “I25”, “UPC”, “CBAR”, or “C128”).

13–7

Page 120

Chapter 13 A-B VBASIC Application Library

Using the ENVPC Simulator (cont’d)

Display and Keyboard You may use the full range of PRINT, LOCATE, etc. functions to write to the display. Do not use the cursor size arguments to LOCATE, but you can turn the cursor on and off using the third argument. Reading from the keyboard should only be done using TestEvent% or one of the functions which use it such as ReadEvent%, ReadStr%, ReadInt%, Menu%, etc. The keys are returned as the ASCII value of the key. Special keys such as function keys and cursor keys, will return a negative event code. All special keys have named constants in ENV.BAS which MUST be used to test for a key value. Network I/O Only LINE INPUT and LINE OUTPUT are supported via TestEvent% as a NetEvent. The data is left in InNet$. Output to NET is supported with the Send subroutine. (Note that, as with any output to NET, you must first test to make sure the previous output to NET has completed, or you will get an error. This means the host must be online. If you need to send data while the workstation might be offline from the host, use SendQue instead.) Output to the network through the queue is supported via SendQue. No support is provided for opening the QUE device and accessing it as a file. No support is provided for PRINT # USING to the network. COM and AUX Only LINE INPUT is supported for input via TestEvent%. The events are ComEvent and AuxEvent, and the data is left in InCom$. For OUTPUT you build a string which is output in exactly the form you provided it (Line-Feeds are added to Carriage Returns when that option is enabled). No support is provided for PRINT # USING to the COM or AUX ports. Support for the control lines is provided with SetDTR and SetRTS. Support for the status line is via GetDSR%. No event support is provided for DSR state changes. Note: While the BASIC Language Development Kit subroutines will accept the AUX port as a target for DTR, RTS, and DSR commands, the WORKSTATION DOES NOT HAVE THESE LINES on the AUX port, and the results are unpredictable!

13–8

Page 121

Chapter 13 A-B VBASIC Application Library

Using the ENVPC Simulator (cont’d)

Status Display The application status display (one of the special status displays described in Chapter 4) is not accessible through any subroutines in ENV, and is not emulated in ENVPC. Use a section of code which is conditional on the value of PcMode to set the status display. Printing Reports and Forms Since PRINT # USING.. is not supported, we recommend that you format reports by first printing the report to a scratch file, then copying the file to the device. Example: listfile$ = “SCRATCH” OPEN listfile$ FOR OUTPUT AS #1 PRINT #1, USING ” . . . . . . . . . . build your report, form, or complex response here . . . PRINT #1, USING ” . . . . . . . CLOSE #1 OPEN listfile$ FOR INPUT AS #1 DO WHILE NOT EOF(1) LINE INPUT #1, s$ SendQue s$ ‘ This could be SendQue, Send, or SendCom LOOP CLOSE #1 KILL listfile$

13–9