The text of a manual · part 24 of 26
Videx BASIC for DuraTrax, LaserLite, LaserLite Pro, and LaserLite Mx Data Collectors, pages 231 to 240
Pages 231 to 240 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 231
'* '* '* '* '* '* '* evt_delete description: F5 key was pressed or a barcode consisting of 5 spaces was scanned. Delete the current record. The current record may be the last record when appending or the record being viewed when scrolling.
evt_delete: cardcmd M 'get the current record gosub process_cardcmd_error cardresult% = cardstatus(cardreturn$) gosub process_card_error IF cardresult% = 23 THEN sound 2349,250 cls print "There is no data" print "to delete!"; n_times% = 3 gosub kill_time display$ = "" return ENDIF
'23 means no data bar2$ = cardreturn$ 'make the user confirm cls print "Delete data? Y" foo% = len (bar2$) if foo% <= 14 then print bar2$; locate 1,14 print " N"; else print ".."; left$ (bar2$, 12); " N"; endif gosub questiontone
Appendix C Sample BASIC Programs
223
Page 232
do foo% = asc(inkey$()) loop until (foo% = 2) | or (foo% = 4) | or (foo% = 89) | or (foo% = 78) | or (foo% = 132) | or (foo% = 42) | rem up arrow rem down arrow rem 'Y' rem 'N' rem MEM (Y unshifted) rem '*' (N unshifted)
if (foo%=2) or (foo%=89) or (foo%=132) then 'go ahead and delete (hide) the record at pointer cardcmd M, H gosub process_cardcmd_error csvalid% = 0 cardresult% = cardstatus(cardreturn$) gosub process_card_error gosub deletetone cls locate 0,0 print "..record deleted" cardcmd M 'bring up the next record gosub process_cardcmd_error cardresult% = cardstatus(cardreturn$) gosub process_card_error cls 'prepare the display display$ = cardreturn$ IF cardresult% = 23 THEN 'if no more records then its empty display$ = "-DATA FILE EMPTY-" mode = mode_norm% ENDIF full_display$ = display$ 'initialize for scroll left & right shift% = 0 else sound 2349, 250 endif return
224
Appendix C Sample BASIC Programs
Page 233
'* '* check_voltage '* description: Get the current voltage. If it is below '* low_voltage% and has changed, alert the user. '* check_voltage: bar$ = left$(environ$(0), 3) foo% = (val(left$(bar$, 1)) * 10) + val(right$( bar$, 1)) if foo% < low_voltage% then if foo% < voltage% then cls print "Low batteries." print environ$(0) ; " volts" ; gosub ring sleep 10000 voltage% = foo% end if else voltage% = foo% end if return
'* '* '* '* '* '* evt_pfail description: It looks like power was lost when the unit was not asleep. This event is generated once if the unexpected loss of power can be detected.
evt_pfail: cls print "Power loss," print "verify data."; gosub ring sleep 10000 return
Appendix C Sample BASIC Programs
225
Page 234
'* '* ring '* description: Ring to alert the user of an error. '* ring: for ring_i% = 1 to 10 sound 2093, 50 sound 2794, 50 next ring_i% return
'* '* delete tone '* description: Tone that indicates that a record has been '* deleted. '* deletetone: sound 3620,150 sound 2349,250 return '* '* card_error_tone '* description: Tone indicating a card command error. '* card_error_tone: sound 2349, 300 sound 1885, 600 return
'* '* questiontone '* description: Tone used when asking user to confirm if '* data is to be deleted. '* questiontone: sound 2349, 150 sound 3620, 250 return
226
Appendix C Sample BASIC Programs
Page 235
'* '* scroll_info '* description: Display various information when you have '* scrolled down to the bottom of the data file. '* scroll_info: info_index% = info_index% + 1 if 6 < info_index% then info_index% = 0 end if on info_index% gosub os_info, volt_info, time_info,| date_info, mem_info, cardfile_info, cardmem_info return volt_info: 'display battery voltage display$ = environ$(0) + " volts" return os_info: 'display operating system name display$ = environ$(2) return time_info: 'display time display$ = time$() return date_info: 'display current date display$ = date$() return mem_info: 'display available RAM display$ = environ$(1) + " RAM free" return cardfile_info: 'call card memory routine cardcmd C, F gosub process_cardcmd_error cardresult% = cardstatus(cardreturn$) gosub process_card_error total_files$ = mid$ (cardreturn$, 14, 2) '# of files (hex) foo% = bin (total_files$, 2) 'convert hex to integer total_files$ = str$ (foo%) 'convert integer to string cls display$ = total_files$ + " files on card" 'display number of files on card return
Appendix C Sample BASIC Programs
227
Page 236
cardmem_info: 'call card memory routine cardcmd C, F gosub process_cardcmd_error cardresult% = cardstatus(cardreturn$) gosub process_card_error card_space$ = mid$ (cardreturn$, 10, 4) 'available space (hex) foo% = bin (card_space$, 4) 'convert hex to integer card_space$ = str$ (foo%) 'convert integer to string cls display$ = card_space$ + "K available" 'display available space on card return '* '* truncate '* description: Remove nbytes% from the data file (not '* used with Mx data files). '* truncate: if nbytes% <= 0 then 'nbytes% must be positive return end if high% = lofh(0) 'get the size of the file in low% = lof(0) 'high and low words if nbytes% <= low% then low% = low% - nbytes% 'if the low word is >= nbytes%, then 'just subtract nbytes% from low word elseif 0 < high% then high% = high% - 1 low% = ((low% - nbytes%) + 32767) + 1 'otherwise, if the high byte isn't zero, 'subtract one from the high byte and set 'the low byte to low% + 32768 - nbytes% 'otherwise, the file isn't nbytes% long else high% = 0 low% = 0 endif lof(0) = high%, low% 'set the new file length return
228
Appendix C Sample BASIC Programs
Page 237
'* '* kill_time '* description: Delays program operation while information '* is being displayed. '* kill_time: for foo% = 1 to (n_times% * x_delay%) next foo% return '* '* '* '* '* '* '* '* rwloop description: Keeps an increasing number count (starting at 1).Reads system date and time to a memory variable. Writes a record to the memory card. Reads the record out. Displays it on the screen. Escape key exits the loop.
rwloop: sound 1397, 10 'click so user knows we got the key cls locate 0,0 print "Opening file on" print "SSFDC."; gosub questiontone gosub init_card cardcmd O, 2203, I, "rwloop2.txt" 'open the numbers data file gosub process_cardcmd_error IF crderr% THEN return cardresult% = cardstatus(cardreturn$) gosub process_card_error cardcmd C, S 'record the current file handle gosub process_cardcmd_error cardresult% = cardstatus(cardreturn$) gosub process_card_error chandle$ = mid$(cardreturn$,14,2) cardcmd M 'Get the current record gosub process_cardcmd_error cardresult% = cardstatus(cardreturn$) gosub process_card_error IF cardresult% = 23 THEN 'If file is empty, then loopcount% = 1 'we'll start at 1. 'Otherwise we'll increment ELSE 'the last number written loopcount% = | val(left$(cardreturn$,instr(cardreturn$,chr$(09))-1)) + 1 ENDIF
Appendix C Sample BASIC Programs
229
Page 238
WHILE running% and (27 <> ASC(INKEY$())) AND (crderr% = 0) 'set up a loop where escape key exits nowdate$ = left$(DATE$(),5) 'fetch date and time from system and build a record nowtime$ = TIME$() cardrecord$ = str$(loopcount%) + chr$(09) + nowtime$| + chr$(09) + nowdate$ cardcmd A, cardrecord$ 'add it IF crderr% THEN return gosub process_cardcmd_error cardresult% = cardstatus(cardreturn$) gosub process_card_error cardcmd M, -1, F 'move to bottom of file gosub process_cardcmd_error cardresult% = cardstatus(cardreturn$) 'get record gosub process_card_error timewritten$ = cardreturn$ locate 0,0 print "Record Read....." print timewritten$; 'then display it loopcount% = loopcount% + 1 'increment number WEND gosub deletetone 'click so user knows we got the key return '* '* '* '* '* '* '* send_card_cmd description: Go to the routine that initializes the card and updates its status then send the card command string to the card. Clear the card status valid flag before returning.
send_card_cmd: cardcmd crdcmd$ gosub process_cardcmd_error csvalid% = 0 return
230
Appendix C Sample BASIC Programs
Page 239
'* '* '* '* '* '* '* '* '* '* '* init_card description: Figures out what state the card module is in and sets it in the last known state. If the Mx has gone to sleep since the last command issued, then the memory card software must be rebooted. In future releases, this will be handled automatically by the operating system.If the application restarted since the last card command, then it is not necessary to update card status.
init_card: cardcmd V
'The version number tells us what program 'is running (whether the card is booted) gosub process_cardcmd_error cardresult% = cardstatus(buffer_var$) IF "MCF" = mid$(buffer_var$,3,3) THEN 'Firmware is running gosub boot_card ELSEIF "DMS" = mid$(buffer_var$,3,3) THEN 'Card is already booted. No action needed. ELSE 'No response. Reset it. Somebody 'probably pulled the card cardcmd -1 'reset card processor. gosub boot_card ENDIF return
'* '* boot_card '* description: Boots the memory card XRAM code. '* boot_card: cardcmd ASC("B") 'Send boot command to start DMS cardresult% = cardstatus(buffer_var$) 'software in the card. return
Appendix C Sample BASIC Programs
231
Page 240
'* '* '* '* '* '* process_card_error description: Since the cardstatus() function returns an integer error code, it may be quickly analyzed and processed with each call.
process_card_error: IF crderr% THEN 'already handled by cardcmd error processing ELSEIF (cardresult% = 0)THEN ELSEIF (cardresult% = 5)THEN error5% = true% goto evt_badcard ELSEIF (cardresult% = 32) THEN 'This error means 'no file open' gosub card_error_tone 'This routine assumes it was open until cls 'the card was removed. The system restarted locate 0,0 'but didn't have any information to re-open print " Card Process " 'the file and set the pointer. print " interrupted "; n_times% = 1 gosub kill_time cls locate 0,0 print " Restarting " print " application "; sleep 32767 cls goto beginning ELSEIF (cardresult% = 37) | OR (cardresult% = 36) | OR (cardresult% = 23) THEN
'top of file 'bottom of file 'no data
ELSE error_ring: gosub card_error_tone 'otherwise just report error number cls locate 0,0 print "Crd module error" print "# "; str$(cardresult%); n_times% = 3 gosub kill_time ENDIF return
232
Appendix C Sample BASIC Programs