The text of a manual · part 20 of 26
Videx BASIC for DuraTrax, LaserLite, LaserLite Pro, and LaserLite Mx Data Collectors, pages 191 to 200
Pages 191 to 200 of 252
The original document is the PDF (765 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 Videx DuraTrax, Videx LaserLite, Videx LaserLite Mx and Videx LaserLite Pro
Page 191
One additional use of STATUS_VAR% is to indicate when null characters are encountered while reading ASCII data. The high byte of STATUS_VAR% is usually zero, but if nulls are encountered, each one increments the high byte of STATUS_VAR%. See the following paragraph for more information. Since Videx BASIC strings are null-terminated, they cannot contain a character with an ASCII value of zero. In order to work with binary data in Touch Memory buttons, the mode specification includes a bit that specifies that the data strings will represent a series of bytes in hexadecimal format. In addition, if any null bytes are encountered in a read operation in ASCII mode, the null is converted to the character with ASCII value 172 (AC hex) before it is stored in DATA$. This character is “¼” in the standard PC character set and is “¬” in most Windows fonts, and is unlikely to occur in most text. As an indication of this substitution, the high byte of STATUS_VAR% is incremented by 1 for each such byte read. The total number of data bytes in the DDS is returned in BYTES_VAR%. Hexadecimal mode must be used to read such data exactly. STATUS_VAR% also contains the continuation byte, as usual, if this is a DDS read, so the two bytes must be separated. First, take the modulo of STATUS_VAR% divided by 256, to get the continuation byte. (Note: Modulo arithmetic provides the remainder of an integer division, rather than the quotient. See page 18 for information on modulo arithmetic.) Subtract the modulo from STATUS_VAR%, and divide the result by 256 to get the number of nulls. The table on the following page lists the possible error conditions and other configurations of the return variables. Error -10 (button not responding) can be activated by inappropriately by an ASCII mode read of a button that has only unwritten (FF hex) bytes in the range requested. This is because this valid non-error situation cannot be distinguished from the non-response of a button different from the one whose ID is being given. If this is a possibility in your system, you must either ignore this error or devise a system solution that insures that all buttons have some information stored. See also HEX$ and BIN.
Chapter 4 Statement & Function Reference
183
Page 192
Error Codes Mode
STATUS_VAR%
BYTES_VAR%
Condition
All
0
# read or written
Success.
DDS* read
0 to 255 (con’t)
0 to 511
Success.
All
-1
0
No button or button lost contact.
All
-2
0
ID contains an illegal (non-hex) character.
All
-3
0
Button family does not support operation.
All
-4
0
Address does not exist for this family code.
All
-5
0
Some bytes out of range for family.
Hex write
-6
(# written)
Illegal hex digit in data to be written.
All read
-7
(# read)
Not enough room in destination string.
DDS read
-8
0
Bad CRC16.
All write
-9
(# written)
Unsuccessful write; retries exhausted.
All
-10
0
Button not responding; possible wrong ID.
DDS write
-11
0
String too big for DDS packet.
ASCII DDS read
Nulls/continue†
(DDS data length)
Good DDS, but null byte encountered in data.
Other ASCII read
Nulls * 256†
(# read)
Good read, but null byte encountered in data.
* Default Data Structure, a page-oriented packet protocol for Touch Memory buttons. † Count of nulls in high byte, continuation byte (if applicable) in low byte.
184
Chapter 4 Statement & Function Reference
Page 193
• Example REM TOUCH Statement 'Read the data in a Dallas Semiconductor Touch Memory button.
DIM data$ * 64, button_data$ * 100 DIM running% DIM ibytes%, status% running% = 1 read_mode% = 2
'we will be reading ASCII strings using 'the Default Data Structure event loop
WHILE running% CLS PRINT "Touch a button:" ; 'display a prompt INPUTEVT 0, 0, 0, 0, type%, symbol%, device%, data$ 'get an event IF (((type% = 1) and (device% = 48)) and (left$(data$, 3) = "04:")) 'check if event was read of a 1994 button THEN status% = -1 'initialize error code ibytes% = 0 'initialize # of bytes read 'data$ now contains the button ID, which 'we will use in the TOUCH statement to 'read the button data. TOUCH read_mode%, data$, 0, ibytes%, status%, button_data$ IF status% >= 0 THEN 'successful read of button data OPTION(258) = 1 'turn on the LED SOUND 1446, 250 'good beep OPTION(258) = 0 'turn off the LED CLS PRINT button_data$ PRINT str$(ibytes%); " bytes read"; SLEEP 2 ELSE CLS PRINT "Button read" PRINT "failed!"; SOUND 698, 250 'sound a low beep SLEEP 2 ENDIF ENDIF WEND
Chapter 4 Statement & Function Reference
185
Page 194
UCASE$ Function • Action Returns a string identical to the parameter string, but with all letters converted to uppercase. • Syntax word$ = UCASE$ ( stringexpression$ ) • Parameters Argument stringexpression$
Description The string to convert to uppercase. This can be a string variable, string constant, or string expression.
• Remarks The UCASE$ and LCASE$ statements are helpful in making string comparisons case insensitive. See also LCASE$. • Returns The string in uppercase letters. • Example REM UCASE$() Function word$ = "UpPercAse" PRINT word$ word$ = UCASE$(word$) PRINT word$; SLEEP 0
Output: UpPercAse UPPERCASE
186
Chapter 4 Statement & Function Reference
Page 195
VAL Function • Action Returns the numeric value of a string of digits. • Syntax theNum% = VAL ( stringexpression$ ) • Parameters Argument stringexpression$
Description Any sequence of characters that can be interpreted as a numeric value.
• Remarks The VAL function searches stringexpression$ for the first digit or minus sign, and then interprets the remaining consecutive digits as the integer. The VAL function stops reading the string when it encounters a character that it does not recognize as a number. The STR$ function complements VAL. • Returns The numeric value of the string.
Chapter 4 Statement & Function Reference
187
Page 196
• Example REM VAL() Function startRAM$ = ENVIRON$(1) PRINT "Using RAM..." PRINT "Wait!"; OPEN "data.txt" FOR APPEND as #0 FOR i% = 0 TO 2000 'fill the array and eat up RAM PRINT #0, "12345678901234567890" NEXT i% EndRAM$ = ENVIRON$(1) usedRAM% = VAL(startRAM$) - VAL(endRAM$) 'convert strings to numbers and subtract CLS msg$ = "USED " + STR$(usedRAM%) + " K" PRINT startRAM$; " - "; endRAM$ PRINT msg$; SLEEP 5 'pause display for 5 seconds or keypress
188
Chapter 4 Statement & Function Reference
Page 197
WHILE…WEND Statement • Action Executes a series of statements in a loop, as long as a given condition is true. • Syntax WHILE condition . . .
WEND • Parameters Argument condition
Description An integer expression that can be translated as true (nonzero) or false (0).
• Remarks If the condition argument is true (that is, if it does not equal zero), then any intervening statements are executed until the WEND statement is encountered. BASIC then returns to the WHILE statement and checks the condition argument. If it is still true, the process is repeated. If it is not true (or if it equals zero), execution resumes with the statement following the WEND statement. Note: The DO…LOOP statement provides a more powerful and flexible loop control structure. WHILE…WEND loops may be nested to any level. Each WEND matches the most recent WHILE. An unmatched WHILE or WEND statement causes an error message. See also DO…LOOP and FOR...NEXT.
Chapter 4 Statement & Function Reference
189
Page 198
• Example REM WHILE...WEND Statement '* '* Monitors data collector events and exits the program if '* the power switch is turned off. '* CONST false = 0, true = Not false, NL$ = CHR$(13) + CHR$(10) DIM display$ * 34 running% = true 'set running% to true display$ = "Waiting on you..." + NL$ + "P switch = exit" WHILE running% 'event loop CLS PRINT display$; 'display a prompt INPUTEVT 0, 0, 0, 0, type%, symbol%, device%, data$ 'get an event IF type% = 6 THEN 'if type% event is 6 then power switch was turned off running% = false 'set running% to false ELSE BEEP ENDIF WEND END
190
Chapter 4 Statement & Function Reference
Page 199
Chapter 5 BASIC Compilers BASIC compiler programs are available for three operating platforms: Windows 95/98/NT, DOS, and Macintosh. Both the Windows and Macintosh compilers provide a drag-and-drop interface. The DOS version is a command line program with parameters. The compiler program for Windows is Vxbasicw.exe. The compiler program for DOS is Vxbasic.exe. The compiler program for Macintosh is Videx BASIC.
Vxbasicw.exe Overview for Windows The compiler program for Windows 95/98/NT is Vxbasicw.exe. Vxbasicw.exe for Windows is an executable program. It was developed to demonstrate the functionality of Vxbasic.dll. You may use the Run command from the Windows Start menu to pass parameters to Vxbasicw.exe. Parameters and defaults are identical to the DOS Vxbasic.exe program. Alternatively, you may start the program by dragging-and-dropping a source code file onto the Vxbasicw.exe icon. To execute, Vxbasicw.exe requires the Vxbasic.dll file. The file may be installed either in the directory with Vxbasicw.exe or in the system path for DLL’s.
Windows DLL A 32-bit dynamically linked library (DLL) for compiling your BASIC source code is included with the Application Builder software. The header file, Vxbasic.h, documents the calling convention.
Chapter 5 BASIC Compilers
191
Page 200
Vxbasic.exe Overview for DOS The compiler program for DOS computers is Vxbasic.exe. This is a command line program with parameters. Vxbasic.exe has the following syntax: vxbasic <input filename.ext>
By convention, you should use .B as the input file extension and .S as the output file extension. If there are any errors in the code, the compiler quits at the first error encountered and displays the error and source code line on the screen.
Videx BASIC Overview for Macintosh The compiler program for Macintosh computers is Videx BASIC. Videx BASIC is an AppleScript server that can accept Open Document events. If there are any errors in the code, the compiler quits at the first error encountered and displays the error and source code line on the screen.
192
Chapter 5 BASIC Compilers