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 13 of 25

Attended Workstations (Catalog Nos. 2708-DH5B2L & -DH5B4L) (Series B) User Manual: 12 - Special Devices in A-B VBASIC, pages 97 to 104

Pages 97 to 104 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 97

Chapter

A–B

12

Special Devices in A-B VBASIC Introduction

Most I/O in A-B VBASIC is performed by accessing special device names which are unique to the workstation. In A-B VBASIC, as in Visual BASIC, devices are accessed with the same statements as files. For example, access to the workstation’s barcode reader is obtained by an OPEN of the device named “BAR”, followed by GETs or LINE INPUTs. We highly recommend use of the BASIC Language Development Kit (Catalog No. 2708-NBD) of subroutines for faster, easier development of larger programs. Subroutines in that library automatically open the required devices and perform the appropriate timeouts and formatting operations. In addition, debugging can be done on the PC without the need for downloading each time a program change is made. Refer to Appendix M. Most of the following information assumes that you are not using the BASIC Language Development Kit, but are writing a program which directly addresses I/O devices. Here is a list of all reserved filenames which address the special devices. Note that they are different from DOS device names, and that they do not contain colons: Real Devices Name Front panel LCD . . . . . . . . . . . . . . . . . . LCD Keypad . . . . . . . . . . . . . . . . . . . . . . . . . KEYS Comm line - primary . . . . . . . . . . . . . . COM Comm line - auxiliary . . . . . . . . . . . . . AUX Barcode . . . . . . . . . . . . . . . . . . . . . . . . . BAR Lights on keypad . . . . . . . . . . . . . . . . . LITE Timer . . . . . . . . . . . . . . . . . . . . . . . . . . EGG Host computer . . . . . . . . . . . . . . . . . . . HOST and NET Pseudo Devices Name Queue to host computer . . . . . . . . . . . . QUE User status display . . . . . . . . . . . . . . . . STAT RAM files (any non-reserved name, 12 characters per file name max.)

12–1

Page 98

Chapter 12 Special Devices in A-B VBASIC

Introduction (cont’d)

Some statements and intrinsic functions implicitly refer to a specific device. These are: Front panel LCD . . . . . CLS, CSRLIN, LOCATE, POS, PRINT and WRITE (without file numbers) Keypad . . . . . . . . . . . . INKEY$, INPUT$ (without filenumber), LINE INPUT (without filenumber) Beeper . . . . . . . . . . . . . BEEP, SOUND Timer . . . . . . . . . . . . . DATE$, SLEEP, TIME$, TIMER Files . . . . . . . . . . . . . . KILL

Device: LCD Display

Reserved device name: LCD These statements always access the LCD display: PRINT and PRINT USING (without a file number) WRITE (without a file number) CLS CSRLIN LOCATE POS Prompts for LINE INPUT (without a file number) As an alternative, OPEN “LCD” may be used to associate the device with a file number and PRINT # or WRITE # used. Note: Once OPENed, the “LCD” file CANNOT be closed. At program start, the LCD displays the words “BASIC START”. The cursor is at the home position and is on. The LCD is set to clear when the program’s first character is output to it. Thus, the programmer can act as if the LCD were actually already blank. PRINTs to the LCD, ending without a comma or semicolon (, or ;) leave the cursor at the start of the next line. Thus, the next PRINT causes that line to be cleared before data is written. PRINT statements terminated by a comma or semicolon leave the cursor where it was at statement’s end, as shown in the following example.

12–2

Page 99

Chapter 12 Special Devices in A-B VBASIC

Device: LCD Display (cont’d)

Note: See the description of PRINT USING and WRITE for details on other formatting options supported. See also the READ.BAS collection of BASIC Language Development Kit subroutines for useful LCD output subroutines, including automatic formatting of display lines, automatic clearing of the display, and cursor positioning. CLS Name$ = “Fred” PRINT “Please Enter Now!” PRINT “Thank You”; Name$; ‘ Keep cursor on second line. CONST ScreenDev = 1 OPEN “LCD” FOR OUTPUT AS #ScreenDev ‘ Cannot be CLOSEd LineWidth% = LOF (ScreenDev) \ 2 ‘ Width of display. PRINT #ScreenDev, “Please Enter Code:”; ‘ Cursor remains on line. LINE INPUT, Code$

Device: Keypad

Reserved device name: KEYS These statements always access the Keypad: INPUT$ (without a file number) LINE INPUT (without a file number) INKEY$ When a Keypad line is being entered with LINE INPUT, only the enter and backspace keys perform the expected termination and correction functions. As an alternative, INPUT$ and LINE INPUT can be used to access this device using OPEN “KEYS”. The BASIC Language Development Kit (Catalog No. 2708-NBD) modules READ.BAS and MENU.BAS contain several helpful subroutines for obtaining input through the Keypad. CONST KeyDev = 1 OPEN “KEYS” FOR INPUT AS #KeyDev DO WHILE a$ = ” ”: a$ = INKEY$: LOOP LINE INPUT “Enter your name: ”; Name$ b$ – INPUT$ (1)

‘ Assign device a file number ‘ Open device. ‘ Wait for a key stroke. ‘ Must press enter. ‘ Another way to get a key stroke.

12–3

Page 100

Chapter 12 Special Devices in A-B VBASIC

Device: Barcode Scanners

Reserved device name: Open Modes: Statements: Functions:

BAR INPUT LINE INPUT EOF returns TRUE when a complete record has arrived. Once TRUE, a LINE INPUT statement can be used and will immediately return the data when LINE INPUT completes. EOF returns to FALSE. LOF remains 0 until a barcode is read. Then it contains the length of the data record. It must be called before LINE INPUT. Once LINE INPUT has been used, LOF returns 0 until the next barcode is read.

IOCTL$ may be called after LINE INPUT to obtain more information about the type and origin of the data. In general, the string which is returned is of the form: Type/Source When reading barcodes: Type can be: Code 3 of 9, I25, UPC, CBAR, or C128 Source can be WAND or LASER There are two intrinsic functions which may be used before LINE INPUT to determine whether a barcode has been read: EOF, and LOF. For barcodes, “read” means that the operator correctly used a wand, laser, or slot reader to scan one of the barcode types enabled through the barcode menu. For example, an A-B VBASIC program will not be aware that a UPC barcode has been scanned if UPC is not enabled or if another condition such as a check digit has not been satisfied. It also means that the operating system was able to decode the pattern of the barcode because the reader was operated at the correct speed and angle. Unsuccessful attempts to read a barcode are not reported to the BASIC program. Once a read has occurred, the TRUE returned by EOF, the barcode length from LOF, and the data from LINE INPUT, are “latched” until a LINE INPUT is used. Note: Allen-Bradley slot scanners (Catalog No. 2755-B1, -B2) can be used in place of a wand or hand-held scanner.

12–4

Page 101

Chapter 12 Special Devices in A-B VBASIC

Device: Barcode Scanners (cont’d)

This means that: 1. EOF and LOF may be called any number of times before LINE INPUT, and they will return the information for the current barcode. Program structure might make it convenient for one procedure to detect the presence of a barcode with EOF, and another to get its length with LOF, and yet another to place its contents into a string with LINE INPUT. 2. All barcodes must be accepted by LINE INPUT before subsequent barcodes can be read! It is not possible to use LOF to read a barcode, then to ignore it because its length is wrong. 3. Once LINE INPUT is used, EOF and LOF are reset to false and 0 until another barcode arrives. The status returned by IOCTL$ is valid from one transition from EOF TRUE to another. To summarize, if you do not use the BASIC Language Development Kit subroutines (which are a faster and easier way to develop larger programs), the proper programming sequence to read barcodes is: Optional test for EOF and/or LOF Optional IOCTL$ LINE INPUT Optional IOCTL$ CONST BarDev = 2 DO WHILE NOT EOF(BarDev): LOOP ‘Wait for data. SOUND 1200, 1 ‘Give a nice beep. LINE INPUT #BarDev, InputData$ DataLength = LEN(InputData$)

12–5

Page 102

Chapter 12 Special Devices in A-B VBASIC

Device: Host Computer

Reserved device names: HOST, NET, and QUE It is very easy to forward the data collected by a workstation to the host computer attached to the Master Workstation. We recommend the BASIC Language Development Kit subroutines SendQue and Send. However, if you are not using these, the simplest method is to OPEN the “file” named HOST and WRITE # or PRINT # to it. Two important features are that: 1. The data is forwarded to the host computer regardless of the network role played by the unit. Stated differently, output to HOST works the same for a workstation which is a Master, Concentrator, or any other workstation type. 2. Once a record has been written to HOST, no further action by the A-B VBASIC program is required to get the information to the host. If the workstation is offline, the data is stored temporarily in a FIFO queue and forwarded when network conditions permit. This occurs transparently to the application.

Figure 12.1 Data I/O through a Network Three Special Host Communication Defices

OUTPUT TO NET

NETWORK OUTPUT BUFFER

OUTPUT TO HOST OR QUE

INPUT FROM QUE

QUE

TO HOST VIA THE NETWORK

INPUT FROM HOST OR NET

NETWORK INPUT BUFFER

FROM HOST

This diagram shows the various methods which can be used to move data into and out of a workstation through its network. All output operations to HOST enqueue data in a FIFO (first-in-first-out) queue, which is a special form of RAM file. The network task removes records one at a time as it is able to transport them to the host computer. Output operations to the NET device bypass this queue. The record is placed in an output buffer which is checked before the queue. Use this method sparingly for high priority alarms which must bypass queued records. 12–6

Page 103

Chapter 12 Special Devices in A-B VBASIC

Device: Host Computer (cont’d)

Note: There is no queue for data FROM the host, only a single buffer. Input operations from HOST and NET access this buffer. As just mentioned, the FIFO queue is a special file. As such, it can be manipulated as a file, through the reserved file name QUE. IMPORTANT NOTE: Outputs to the QUE device will remain in the queue and will not be sent to the host until the QUE device is closed and the HOST device is opened. Nothing further needs to be done with the HOST device; it only needs to be left open until the entire queue is emptied. If, on the other hand, data should be routed to the host as quickly as possible, do not use the QUE device at all, but rather send everything directly to the HOST device. It will still use the queue, but will not wait to transmit. General restrictions and warnings: 1. Only printable ASCII characters may be moved through the network. Output only characters within this range: Lowest valid: Space, CHR$(32), Hex 20 Highest valid: }(right curly bracket), CHR$(125), Hex 7D Programs which access QUE as a binary file will also encounter carriage return/line feed sequences. These have been inserted by the interpreter. Do not remove them or try to insert them explicitly using CHR$( ). 2. Like any other RAM file, the size of QUE and HOST is limited by physical RAM. Use the FRE function often to prevent out-of-memory conditions which could have disastrous effects on operations. 3. All output operations must contain a complete record in ONE statement. All outputs place a trailing carriage return/line feed sequence after the data provided. It is not possible, for example, to use multiple PRINT statements, terminated by a comma to assembly a HOST or QUE record piecemeal. THIS RESTRICTION IS ENFORCED, see PRINT. 4. Do not allow HOST and QUE to be OPEN at the same time. 5. Input FROM the host computer may not begin with < or > or a numeric digit (0 to 9). Chapter 8 describes the effect which these characters have on the firmware. 6. All output to NET has the potential disadvantage that its data might be classified as a network status or other error message and not application related data. This can happen because, when using the NET device, the “Transaction Code” digits 9 and 10 of the 10 character record header are set to zeroes, and cannot be changed by an IOCTL statement (see IOCTL description later in this chapter). Two zeroes are typically an indication of a status or diagnostic message, BASIC ERROR, or other system generated response.

12–7

Page 104

Chapter 12 Special Devices in A-B VBASIC

Device: Host Computer (cont’d)

For example: PRINT #NETDEV, “BAD INVENTORY NUMBER” may be trapped by the host computer as a BASIC ERROR because the complete record sent to the host will look something like this: 0101000100BAD INVENTORY NUMBER If the host program is testing for zeroes in digits 9 and 10, and is then looking for “BA” to indicate a BASIC ERROR, it will become confused by this error message, and potentially abort the programs. We suggest that, if you must use NET instead of HOST, make your first two bytes something odd like **. 7. A maximum length is imposed on all records moving through the network. Consult Appendix N in this manual. 8. AnyA-B VBASIC program reading from HOST or NET must do so at a rate fast enough to “Keep up” with the host. If a new record arrives before the previous one is input, the “lost” count is incremented on the #5 status display.

Details of Specific Statements and Functions

We highly recommend that you utilize the subroutines contained in the BASIC Language Development Kit (Catalog No. 2708-NBD) to do all I/O in the workstation. These library routines allow you to simulate the workstation on a PC during development, saving you hours of time and headaches. When using the BASIC Language Development Kit, you will only need to call OpenLINX, then execute a ReadEvent and wait for a return. Any data received from the devices (slot reader, COM ports, etc.) will be returned in appropriate variables, and flags will be set to let you know where the data came from. Refer to Appendix M for details. If you must use the devices directly, the following programming examples will show you how: OPEN “HOST” Host should be opened only as a sequential or random access file, in keeping with the record oriented nature of network I/O. QUE may be OPENed for binary access so long as the general restrictions are observed. An OPEN “HOST” has a very important side effect: it allows the network task to deque records from the QUE and forward them to the host. Program initiation CLOSEs HOST. Program termination leaves HOST unchanged.

12–8