The text of a manual · part 21 of 26
Videx BASIC for DuraTrax, LaserLite, LaserLite Pro, and LaserLite Mx Data Collectors, pages 201 to 210
Pages 201 to 210 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 201
Appendix A BASIC Reserved Words The following is a list of BASIC reserved words: ABS AND APPEND AS ASC BEEP BIN CARDCMD CARDSTATUS CHR$ CLOSE CLS COMMCLOSE COMMINPUT COMMOPEN COMMPRINT CONST DATE$ DIM DO ELSE ELSEIF END ENDIF ENVIRON$ EOF ERR EXIT FOR GOSUB GOTO
HEX$ IF INKEY$ INPUT$ INPUTEVT INSTR LCASE$ LEFT$ LEN LET LOCATE LOF LOFH LOOK$ LOOKUP LOOP LTRIM$ MID$ MOD NEXT NOT ON OPEN OPTION OR PATTERN PRINT REM RETURN RIGHT$ RTRIM$
SEEK SEEKH SLEEP SGN SOUND STEP STR$ SWAP THEN TIME$ TOKEN$ UCASE$ UNTIL VAL WEND WHILE
Appendix A BASIC Reserved Words
193
Page 202
Notes:
194
Appendix A BASIC Reserved Words
Page 203
Appendix B LaserLite Mx Modulus Information (Notes about hashed indexes on the LaserLite Mx) Hash tables differ from other tables or arrays because they provide the LaserLite Mx system a fast way to seek data in an ASCII data file. They provide nonsequential access to data elements through the use of a hash function that converts the key field into an integer and divides it by the size (modulus) of the hash table. The remainder becomes the “key,” “lookup value,” or “bin” that indexes where to find the data element. The LaserLite Mx system provides a built-in hash function for distributing data elements into a hash table. While the actual hash algorithm for the LaserLite Mx is written in 8051 assembler, it is based on the following C language code example which is based on Allen Holub’s portable adaptation of Peter Weinberger’s generic hashing algorithm. /*---Hash PJW--------------------------------------/*An adaptation of Peter Weinberger’s (PJW) generic /*hashing algorithm based on Allen Holub’s version. /*Accepts a pointer to a datum to be hashed and /*returns an unsigned integer. /*--------------------------------------------------*/ #include <limits.h> #define BITS_IN_int ( sizeof(int) * CHAR_BIT ) #define THREE_QUARTERS ((int)((BITS_IN_int * 3) / 4)) #define ONE_EIGHTH ((int)(BITS_IN_int / 8)) #define HIGH_BITS ( ~((unsigned int)(~0) >> ONE_EIGHTH )) unsigned int HashPJW ( const char * datum ) { unsigned int hash_value, i; for ( hash_value = 0; *datum; ++datum ) { hash_value = ( hash_value << ONE_EIGHTH ) + *datum; if (( I = hash_value & HIGH_BITS ) ! = 0 ) hash_value = ( hash_value ^ ( I >> THREE_QUARTERS 00 & ~HIGH_BITS; } return 9 hash_value ); }
Appendix B LaserLite Mx Modulus Information 195
Page 204
What Modulus should be used when creating an Indexed File? Use the following guidelines to select a modulus for LaserLite Mx indexed files: •= Optimal trade-off between performance and space efficiency is achieved when the anticipated number of records is less than twice the modulus. •= A prime number modulus provide the best distribution of data. The following prime numbers selections can provide optimal distribution: 13, 17, 19, 31, 61, 89, 107, 127, 521, 607, 1279, 2203, 2281, 3217, 4253, 4423, 9689, 9941, 11213, 21701, 23209, 44497. •= The LaserLite Mx can support a modulus up to 65535.
196
Appendix B LaserLite Mx Modulus Information
Page 205
Appendix C BASIC Sample Programs This appendix contains two BASIC programs: Default.b and DEMOMX.b. Default.b is the default application that is loaded with the operating system if another application is not specified. DEMOMX.b is a demo application for the LaserLite Mx. It contains the subroutines process_cardcmd_error and process_card_error that are referred to in the CARDCMD statement examples.
Default.b '* This is the default application which is loaded with the '* operating system unless another application is specified. ' const false% = 0 'define constants const true% = not false% const backward% = true% const forward% = false% const mode_norm% = 0 'defines scrolling behavior const mode_up% = 1 const mode_dn% = 2 const delimiter$ = chr$(13) + chr$(10) 'delimits data file lines with a carriage return/line feed const low_voltage% = 45 'voltage which triggers warnings const x_delay% = 150 'define delay time dim data$ * 64 'dimension strings dim display$ * 64 dim full_display$ * 64 dim bar$ * 64 dim bar2$ * 64 dim voltage% dim info_index% dim shift% dim running% dim mode% dim n_times%
Appendix C Sample BASIC Programs
197
Page 206
sound 2793, 250 sound 2637, 250 sound 2793, 250
'startup beep open "data.txt" for append as #0 'open and name data file if err then gosub file_error data$ = "" 'initialize variables display$ = "" mode% = mode_norm% running% = true% voltage% = 60 info_index% = 0 shift% = 0 while running% 'event loop gosub check_voltage 'check battery voltage cls print left$(display$, 16) 'display a prompt print "Scan: " ; inputevt 6, 1, 16, 2, type%, symbol%, device%, data$ 'get an event on type% gosub fn_null, fn_input, fn_exit,| evt_delete, fn_up, fn_down, fn_power, evt_pfail,| evt_esc, fn_null, fn_null, fn_null, fn_null,| fn_null, fn_null, fn_null, fn_null, fn_null,| fn_left, fn_right, evt_mem, evt_bat, evt_f1,| evt_f2, evt_f3, evt_f4, evt_delete 'process the event wend sound 1760, 250 'exit beep sound 1568, 250 sound 1397, 250 end 'return to command line '* '* fn_null '* description: Do nothing function. '* fn_null: return
198
Appendix C Sample BASIC Programs
Page 207
'* '* '* '* '* '* '* fn_input description: Respond to a user input event. Beeps and blinks the valid scan LED, and then appends the input to the end of the data file, along with the current date and time.
fn_input: if device% = 1 then if len(data$) = 0 then 'it's an ENTER key, with no data sound 698, 250 'sound a low beep return endif endif option(258) = 1 sound 1446, 250 option(258) = 0
'turn on the LED 'good beep 'turn off the LED seek #0, 0, e 'set file position to end of file print #0, date$ ; " " ; time$ ; " " ; data$ 'write input, time & date to the file if err then gosub file_error display$ = data$ mode = mode_dn% full_display$ = data$
'display input on screen 'same as scrolling down to 'last line of file 'initialize for scroll right '& left shift% = 0 return '* '* '* '* '* '* '* fn_exit description: Respond to an exit event. Exit events are generated when an unlock command is sent to the unit during an INPUTEVT statement. The typical response is to end the program, returning to the command line.
fn_exit: running% = false% return
Appendix C Sample BASIC Programs
199
Page 208
'* '* '* '* '* '* '* fn_up description: Respond to a scroll-up event. These events are generated when the scroll-up key is pressed. Respond by getting an input token from the data file, and displaying it on the screen.
fn_up: 'skip the last token displayed, if 'we were scrolling down or scanning if mode% = mode_dn% then bar$ = token$(0, delimiter$, backward%) endif display$ = token$(0, delimiter$, backward%) 'get next line if display$ = "" then display$ = "-TOP OF DATA-" mode = mode_norm% else display$ = mid$(display$, 21) 'remove date and time mode% = mode_up% endif sound 1397, 10
'notify user that we got the key press full_display$ = display$ shift% = 0 return
200
'initialize scroll right & left
Appendix C Sample BASIC Programs
Page 209
'* '* '* '* '* '* '* fn_down description: Respond to a scroll-down event. These events are generated when the scroll-down key is pressed. Respond by getting an input token from the data file, and displaying it on the screen.
fn_down: 'skip the last token displayed, if we were scrolling up if mode% = mode_up% then bar$ = token$(0, delimiter$, forward%) endif display$ = token$(0, delimiter$, forward%) 'get the next line if we're already at the bottom 'of the file, display system information if display$ = "" then gosub scroll_info mode% = mode_norm% else 'remove the date and time display$ = mid$(display$, 21) mode% = mode_dn% endif sound 1397, 10 'notify user that we got the keypress full_display$ = display$ 'initialize for scroll right & left shift% = 0 return '* '* fn_left '* description: Scroll left key was pressed (LaserLite '* Pro/Mx). Scroll to the left to display a long entry. '* fn_left: sound 1397, 10 'click so the user knows we got the key 'check whether we have scrolled all the way 'off the display otherwise, increment position if shift% < len (full_display$) then shift% = shift% + 1 endif display$ = "" 'build display one character at a time for foo% = 1 to 16 if len (full_display$) >= (foo% + shift%) then display$ = display$ + mid$(full_display$, foo%+shift%, 1) endif next foo% return
Appendix C Sample BASIC Programs
201
Page 210
'* '* fn_right '* description: Scroll right key was pressed (LaserLite '* Pro/Mx only). Scroll right to display a long entry. '* fn_right: sound 1397, 10 'click so the user knows we got the key if shift% > 0 then 'check if we have scrolled back to shift% = shift% - 1 'the beginning of the display, endif 'otherwise decrement position 'build display one character at a time display$ = "" for foo% = 1 to 16 if len (full_display$) >= (foo% + shift%) then display$ = display$ + mid$(full_display$, foo%+shift%, 1) endif next foo% return '* '* '* '* '* '* '* fn_power description: Respond to a power event. These events are generated when the power switch is moved to the off position. Respond by setting the hardware into a low-power state.
fn_power: option(256) = 0 sleep 0 option(256) = 1 return
'turn off the LCD 'sleep indefinitely 'turn the LCD back on
'* '* file_error '* description: There was an error opening or writing to a '* file. Alert the user. '* file_error: gosub ring cls print "Error accessing" print "data file!"; sleep 10 return
202
Appendix C Sample BASIC Programs