The text of a manual · part 14 of 25
Attended Workstations (Catalog Nos. 2708-DH5B2L & -DH5B4L) (Series B) User Manual: 12 - Special Devices in A-B VBASIC, pages 105 to 112
Pages 105 to 112 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 105
Chapter 12 Special Devices in A-B VBASIC
Details of Specific Statements and Functions (cont’d)
CLOSE “HOST” Note: When HOST is CLOSEd, the A-B VBASIC interpreter always tells the network task that no data is available from the QUE, even if data is really present. There may be records remaining in the QUE. If so, they will not be available to the network until HOST is once again made OPEN. If necessary, use the LOF function to determine when the QUE is empty, before CLOSEing HOST. WRITE # If the presence of commas and quotation marks is acceptable to your host, this is the simplest way to send a record. Don’t forget to precede the WRITE with a call to FRE to make sure memory is available. As with all output to the network, the interpreter adds the required record delimiters. PUT to HOST PUT is an excellent way to output a variable which has been defined in a TYPE statement. Just remember that all the elements in the TYPE must be fixed length strings. Numerics are not allowed (as binary quantities) since adherence to the “printable character” restriction is not assured. The data is put into the queue for automatic transmission to the host computer, in order, when possible. PUT to NET If the (network) output buffer is empty (see LOF), the record provided will be the next one taken by the network for transmission to the host. Note: If the output buffer is in use, execution of this statement suspends the A-B VBASIC program until the previous record is taken. So, unless your program is prepared to wait, do not use this statement without first checking LOF on the NET device. Better yet, PUT to HOST. PUT to QUE This statement acts like PUT to HOST. Generally, it is used to create a “batch” of records for the host which will be released at some future time by an OPEN “HOST”. Important distinction: PRINT, and WRITE to the QUE add a record delimiter in the same way as output to HOST. Outputs to regular RAM files do not perform this insertion. PRINT # All PRINT #s to HOST, NET, and QUE are restricted. After every PRINT, the interpreter inserts the carriage return, line feed record delimiter. It is not possible to use multiple PRINTs to make one record.
12–9
Page 106
Chapter 12 Special Devices in A-B VBASIC
Details of Specific Statements LINE INPUT # for HOST and NET GET # for HOST and NET (OPEN with RANDOM) and Functions (cont’d) These statements will read one record which the host computer has sent to this. If there is no record available, the program waits for its arrival. Use the EOF or LOC functions first if waiting is not acceptable. LINE INPUT # for QUE GET # for QUE (OPEN with RANDOM enforced) These statements act as if a file is being accessed because QUE is a file. EOF for HOST and NET EOF returns TRUE when a record is available for reading. When FALSE, nothing is present. LOC for HOST and NET LOC returns the number of characters which can be read from the network input buffer. Example: IF LOC(#1) 0 THEN LINE INPUT #1, INLINE$ ELSE ‘ Do something else END IF
LOF for HOST LOF returns the size of the queue, that is, the number of bytes awaiting transmission to the host. LOF for NET LOF returns the number of bytes free in the network output buffer. When non-zero, a single record of that size may be output without waiting. When 0, output is permitted but the A-B VBASIC program will wait until the previous record is accepted by the network. Note that only one record may be output even though the record is shorter than the buffer. For example, say the function returned 200. It is not possible to output 3 records of 20 bytes without waiting.
12–10
Page 107
Chapter 12 Special Devices in A-B VBASIC
Details of Specific Statements and Functions (cont’d)
IOCTL$ (intrinsic function) for HOST and NET This function returns a string formatted as follows: Byte 0:
‘0’ when the workstation is offline to the network. ‘1’ when the workstation is online. Bytes 1-4: is the workstation’s number (without a minus). Bytes 5-9: is the workstation type (its network role) as NORML CONCN MASTR SUBM ALTM ALTSM IOCTL (statement) for HOST Characters 9 and 10 of all records arriving at the host contain a 2 digit number (“Transaction Code”). Numbers 00, 98, and 99 are reserved. A-B VBASIC programs can change these two digits for records from HOST, from the default of 01. For example, if the statement IOCTL #5, “29” is used where #5 is associated with HOST, digits 9 and 10 of records containing data from this workstation, will be 29. Note: Only numeric digits are valid. IOCTL is not valid in its statement form for the NET device.
Devices: Communication Ports, Primary and Auxiliary
Reserved device names: COM and AUX Opening a com port: Access to the communications ports begins with the statement OPEN “COM” and OPEN “AUX”. On a PC, Visual BASIC allows you to specify baud rate and other parameters in the OPEN “COM” statement. In A-B VBASIC these are NOT valid! Comm parameters are set using the Setup Menus (see Chapter 5 for details). If you are using the ENV/ENVPC collections of subroutines in the BASIC Language Development Kit (Catalog No. 2708-NBD), a call to OpenLINX will automatically open all required comm ports. The primary communication port is dedicated to networking functions in all terminal types except NORMAL. Any attempt to OPEN ’COM” on any workstation which has not been set to a workstation type of NORMAL (using the Setup Menus) will result in a runtime error. Units with a second (“AUX”) port may use that port via OPEN “AUX” regardless of the workstation‘s network role. OPENing a communications port has no effect on the state of the modem control lines DTR and RTS. These are always under the control of the BASIC program using IOCTL, or one of the BASIC Language Development Kit subroutines discussed later. 12–11
Page 108
Chapter 12 Special Devices in A-B VBASIC
Devices: Communication Ports, Primary and Auxiliary (cont’d)
A – Output to a Communication Port The BASIC Language Development Kit (Catalog No. 2708-NBD) contains subroutines SendCom, ReadEvent and Test Event for accessing the COM port when the terminal is configured as a NORMAL workstation type. If you need more immediate control of the port, use the following programming instructions: The PRINT and WRITE statements are available for output to the communications ports. Unless a semicolon is placed at the end of the PRINT statement, a carriage return will be output. When enabled through the menu, a line feed is also output. Each of the communications lines has an output buffer. The LOF function returns the number of bytes free in this buffer. When less than the size of the message, output to the corresponding port will result in a wait until all characters can be enqueued. This wait will be short in a workstation which is able to transmit. However, for a workstation which has received an XOFF, the wait can be long (or even infinite)!
B – Input from a Communication Port All COM and AUX input is performed with the INPUT$ function. If more characters are requested than have been accepted by INPUT$, the program waits until the count is satisfied. LINE INPUT is not valid with the COM or AUX device. The LOC function returns the number of bytes currently in the port’s communication input buffer bytes. A program will never wait if LOC is used to get the byte count, and that count is used in INPUT$. For example: CONST AuxDev = 1 OPEN “AUX” FOR INPUT AS #AuxDev ‘ Cound also be “COM” J$ – INPUT$ (LOC(5), #5 NOTE Receipt of Control-C (or whatever control code was specified in the Setup Menu) will cause the workstation to enter the menu mode. Receipt of Control-R will reboot the workstation.
12–12
Page 109
Chapter 12 Special Devices in A-B VBASIC
Devices: Communication Ports, Primary and Auxiliary (cont’d)
C – Modem Control Lines The primary communication port is equipped with DTR and RTS. These can be set through the IOCTL statements. The character string passed must contain two bytes. There are two valid options for each byte: “0” to turn the line off “1” to turn the line on The first byte controls DTR, the second controls RTS. Thus: IOCTL #5, “01” turns off DTR and turns on RTS.
These modem lines can also be controlled using the BASIC Language Development Kit routines SetDTR and SetRTS. AUX has only one line, DTR. It is controlled in the same way as COM. For future compatibility, always add a second (character) zero, to imply RTS off.
Device: RAM Files
Name: Any name which is not reserved and is within the rules for file names. Description: Data files on a PC are resident on disk. They are RAM resident in the workstation. A-B VBASIC supports the three types of file access provided with Visual BASIC, sequential, binary, and random. File I/O is thoroughly discussed in Microsoft’s “Programming in BASIC”, Chapter 3. Statements and Functions supported:① CLOSE EOF GET INPUT$ KILL LINE INPUT LOC
LOF OPEN PRINT PUT SEEK Statement SEEK function WRITE
CONST DataFile = 1 OPEN “EMPLOYEE” FOR OUTPUT AS #DataFile PRINT #DataFile, “Employee ”;EmpName$ ;“ – ”;TIME$ CLOSE #DateFile
!
ATTENTION: Both Visual BASIC and A-B VBASIC allow a PUT to a record number which is greater than the last record in existence before the PUT. Both BASICs extend the file to the length required to accommodate the request.
① Refer to Appendix M for any restrictions on Syntax.
12–13
Page 110
Chapter 12 Special Devices in A-B VBASIC
Device: RAM Files (cont’d)
For example, in a new file: PUT #X, 1, something PUT #X, 1000, something will result in space being allocated for 1000 records, not 2! Moral: Keep record numbers under control. File Memory Management Files are allocated in blocks of RAM. Every file has at least one free byte. In essence this means that a file with a length of zero is allocated one block. Each block contains 2 bytes of overhead. The remainder contains the file’s contents. The block size is set via the configuration menu, to 256, 512, 1K, 2K, or 4K bytes. In an application with several small files, a block size of 256 is recommended. In an application with one large file, a block size of 4K allows for a slightly larger file and slightly better performance. The maximum file size is limited by a workstation’s memory, not A-B VBASIC. Visual BASIC does not allow you to PUT a variable length string to a RANDOM file. In A-B VBASIC this is also not recommended. However, it can be done. Remember to allow at least 2 bytes of overhead for the carriage return/line feed sequence that accompanies each variable PUT to a record. Integrity of data stored and retrieved in this fashion cannot be maintained or updated with any relative degree of confidence.
Device: Beeper
This device is accessed through the BEEP and the SOUND statements. SOUND requires both a frequency and a tone duration. The correspondence between the frequency and a “true” pitch of that value will be approximate. The duration of the tone is given in units of 1/20 second. Unlike Visual BASIC which pauses until a SOUND is finished, A-B VBASIC initiates a SOUND and continues. A second SOUND or BEEP which is encountered before the first completes, resultls in the truncation of the initial tone.
Device: Front Panel LED’s
Device: Front Panel LED’s Reserved device name: LITE The LEDs on the keyboard are numbered from 1 up. The maximum LED number depends on the keyboard style. PUTting a “0” to record number X, turns off LED number X. PUTting a “1” to record number X, turns it on.
12–14
Page 111
Chapter 12 Special Devices in A-B VBASIC
Device: Front Panel LED’s (cont’d)
The LED in the lower left corner of alphanumeric keyboards is used as a shift lock indicator by the operating system. A-B VBASIC programs should not change it. The BASIC Language Development Kit contains a subroutine SetLED which can be called to turn LEDs on and off. Or use this code example: CONST LiteDev = 1 On$ = “1”: off$ = “0” ‘ Cannot be a CONSTant OPEN “LITE” FOR RANDOM AS #LiteDev FOR X = 1 TO 10 ‘ Do 10 LEDs PUT #LiteDev, X, On$ ‘ Turn LED on. SLEEP .25 PUT #LiteDev, X, Off$ ‘ Turn LED off SLEEP .25 NEXT X CLOSE LiteDev
Device: The #9 User Status Display
Reserved device name: STAT Description: The front panel status displays shows information about the condition of a workstation. The number 9 status display is dedicated to showing status information from the application. Two lines are available with 40 characters each. A summary status character which appears over the 9 on the zero summary status display, is also available. The PUT statement is used to place information in the buffer which is shown when the #9 display is selected. PUT to record number 1 places the string on the top line of the display. Put to record number 2 places the string on the second line of the display. PUT to record 3 places the first character of the string over the 9 on the summary display. OPEN “STAT” FOR RANDOM AS #3 LTOP$ = “Data Corp Inventory” LBOTTOMS$ = “Duncan Street Warehouse” SC$ – “ . ” PUT #3, 1, LTOP$ PUT #3, 2, LBOTTOM$ PUT #3, 3, SC$
If your application must shut down or cannot start up, for example due to a missing file that the host was supposed to download, put an error on the status display before program termination. Remember that these statements do not cause the status display to appear, they only define the display’s contents when invoked by the operator. 12–15
Page 112
Chapter 12 Special Devices in A-B VBASIC
Device: The Egg Timer
Reserved device name: EGG Description: The egg timer is a word of memory which, when non-zero, is decremented by one every 1/100 second. These statements, when used with the file number associated with an OPEN “EGG”, control this timing device: SEEK statement: sets the timer to an integer or long For example: OPEN “EGG” FOR INPUT AS #4 SEEK #4, 1000 sets the timer to reach 0 in ten seconds. SEEK function: returns the current value of the timer as a LONG value. (LONG is used to avoid sign confusion for values over 32767 with an INTEGER). LOF and LOC also return the timer’s current value. EOF returns TRUE (-1) when the timer “goes off” by reaching zero. This device is an easy way to implement delays and timeouts without the midnight rollover problem associated with TIME$ and TIMER.
12–16