The text of a manual · part 17 of 23
DuraTrax/LaserLite, LaserLite Pro/LaserLite Mx Developer's Reference, pages 161 to 170
Pages 161 to 170 of 229
The original document is the PDF (797 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 161
Changing Records in Memory Card Files Because of the characteristics of the flash memory in memory cards, changing a record on the card entails the following steps: 1. 2. 3. 4.
Read the desired record into a memory variable. Make the desired changes to the data in the variable. Delete (hide) the old record. Add a new record with the contents of the memory variable.
This routine demonstrates editing “on-the-go.” The picklist.txt file loaded into the LaserLite Mx is a pick list. Each record has four fields delimited by tabs. The fields are 1) data, 2) description, 3) quantity wanted, and 4) quantity picked. Following is a flowchart that describes the flow of the validation: Scanned Data
Is there a match in the pick list file?
No
Beep and display "Not in pick list"
No
Beep and display "No more needed"
Yes 1. Copy record to memory variable 2. Determine if quantity wanted > quantity picked
Is quantity wanted greater than quantity picked?
Yes 1. Increment quantity picked. 2. Delete current record in pick list 3. Add new record to pick list 4. Open data file 5. Create record with time and date from system. 6. Add new record to data file
DONE
Chapter 5 LaserLite Mx Memory Card Data Management
153
Page 162
The user scans one item at a time until each item in the list is picked. The following program is the corresponding Videx BASIC code for the input routine. (Note: The following program contains program lines that exceed the width of the page; so we will use the pipe character ( | ) to indicate that the program line continues.) 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 gosub open_picklist 'open the pick list file cardcmd F, data$ 'search for data$ in pick file gosub process_cardcmd_error cardresult% = cardstatus(cardreturn$) if (cardresult% = 35) then 'data not found in data file cls 'or if not found in pick list, 'do not accept it locate 0,0 print data$ print "Not in pick list"; gosub card_error_tone sleep 2500 elseif (cardresult% <> 0) then gosub process_card_error else cardcmd M 'copy the record to a memory variable gosub process_cardcmd_error 'so it can be edited. cardresult% = cardstatus(cardreturn$)'sort the fields tabpos1% = instr (cardreturn$, chr$(9)) 'look for tab tabpos2% = instr (tabpos1% + 1, cardreturn$, chr$(9)) desc$ = mid$(cardreturn$, (tabpos1% + 1), (tabpos2%)| (tabpos1% + 1))) tabpos3% = instr (tabpos2% + 1, cardreturn$, chr$(9)) qtywanted% = val(mid$(cardreturn$, (tabpos2% + 1),| ((tabpos3%+1) - tabpos2%))) qtypicked% = val(mid$(cardreturn$, (tabpos3% + 1),| (len(cardreturn$) - tabpos3%)))
154
Chapter 5 LaserLite Mx Memory Card Data Management
Page 163
IF qtypicked% >= qtywanted% THEN cls locate 0,0 print desc$ print "No more needed!"; gosub card_error_tone sleep 2500 gosub open_datafile ELSE cardcmd M,H 'delete record at the move pointer gosub process_cardcmd_error cardresult% = cardstatus(cardreturn$) gosub process_card_error 'create a new record option(258) = 1 'turn on the LED sound 1446, 250 'good beep option(258) = 0 'turn off the LED record$ = data$ + chr$(9) + desc$ + chr$(9) +| str$(qtywanted%) + chr$(9) + str$(qtypicked%+1) cardcmd A, record$ 'add the new record gosub process_cardcmd_error cardresult% = cardstatus(cardreturn$) gosub process_card_error display$ = desc$ 'display description on screen gosub open_datafile record$ = data$ + chr$(9) + date$() + chr$(9) + time$() cardcmd A, record$ gosub process_cardcmd_error cardresult% = cardstatus(cardreturn$) gosub process_card_error lastinput$ = data$ ENDIF mode = mode_dn%
'same as if just scrolled down to 'last line of the file full_display$ = desc$ 'initialize to scroll right & left shift% = 0 endif return
Chapter 5 LaserLite Mx Memory Card Data Management
155
Page 164
LaserLite Mx Error Handling Strategies The LaserLite Mx operating system and memory card software system provide a comprehensive set of error reporting codes and conditions. The errors may be reported in any of three ways: 1. By the LaserLite Mx operating system through events reported by the Videx BASIC INPUTEVT statement. 2. By the Videx BASIC CARDCMD statement as global errors. 3. By the Videx BASIC CARDSTATUS function as integer return values. Examples of error reporting are shown on the following pages. See the Videx BASIC Manual for information on the INPUTEVT statement, CARDCMD statement, and the CARDSTATUS function.
156
Chapter 5 LaserLite Mx Memory Card Data Management
Page 165
Operating System Error Handling The LaserLite Mx operating system checks for error conditions both when it starts an application and when it returns from sleep (0 to 599). The following flowchart illustrates the sequence of steps: Begin Operating System Startup
Keyboard or timer wakes up the processor
Read flags set so far Is there a memory card circuit board?
No
Set "no card module" flag
Yes
Is there a memory card?
No
No
Yes
Is the card bootable?
Yes Is its ID different than the last card booted? Yes
Boot from the memory card
Set event type%=10
IF "no card"
Set event type%=11
IF "card not recognized"
Set event type%=12
IF card ID different than the last card used?
Set event type%=13
Set "no card" flag
Yes
Is the card readable?
IF "no card module"
Set "card not recognized" flag
No
Was memory card status saved before sleep?
No
Set event type%=14
Yes Resume Application
Restart Application
As illustrated, any of the error conditions will cause the operating system to automatically restart an application and set the appropriate event flag.
Chapter 5 LaserLite Mx Memory Card Data Management
157
Page 166
The following two BASIC routines are called by the Videx BASIC INPUTEVT statement in response to event type% = 13 and event type% = 14. They are found in the MX-DEMO.B sample application. evt_card_interrupted: '* '* evt_card_interrupted '* description: Since the sleep routine saves the latest '* status from the memory card software system, it can then '* update the card on the next CARDCMD issued after waking '* from sleep. If there is no valid status available, it '* indicates that an event like a power failure or something '* interrupted the process the status could be saved. '* In either case, the application will automatically be '* restarted. This routine notifies the user. '* cls locate 0,0 print "Communication to" print "card interrupted"; sleep 2000 cls locate 0,0 print "Application" print " restarted "; sleep 2000 cls return evt_cardID: '* '* evt_cardID '* description: Since the last time the OS ran, the card ID '* has changed. The OS automatically restarts the '* application and sets this event. This routine notifies '* the user. '* cls locate 0,0 print "Card ID changed" sleep 2000 cls locate 0,0 print "Application" print " restarted "; sleep 2000 cls return 158
Chapter 5 LaserLite Mx Memory Card Data Management
Page 167
CARDCMD Statement Errors The Videx BASIC CARDCMD statement may generate global errors that indicate that the operating system was unable to send the statement to the memory card software system. It can generate the following global errors: Error Description -1 Communications with the memory card timed out.
Possible Cause The memory card software system is busy processing the last command set it received or it didn’t have enough time to finish processing the current command. In either case, try using the CARDCMD statement with the [!] option on commands that require more time than 800ms to process.
-2
A memory card module was not detected at startup.
CARDCMD reads the system startup flags before attempting to communicate with the memory card software system.
-3
A memory card was not detected at startup.
If a memory card is inserted, the system should be restarted to properly set the flags that a card is present.
-4
The memory card does not have a recognized format.
Unformatted card.
-11
The memory card processor is asleep and cannot receive a command.
Removing the memory card without first turning off the LaserLite Mx can cause this error.
Chapter 5 LaserLite Mx Memory Card Data Management
159
Page 168
The following BASIC routines handle the global errors from CARDCMD and are included in the MX-DEMO.B source code: process_cardcmd_error: '* '* process_cardcmd_error '* description: Look for and report error with CARDCMD. '* crderr% = ERR IF crderr% = 0 THEN
'no error
ELSEIF crderr% = -11 THEN 'Timeout error; perhaps card cls 'was pulled out or the memory locate 0,0 'card was busy when CARDCMD print "No response from" 'tried to issue a command print " memory card! "; 'Remember, pulling out the gosub card_error_tone 'card freezes the memory card sleep 1 'processor. It must be reset 'for it to restart. That's why 'it's best to go to sleep and 'let the system bring it back 'up when it wakes up. ELSEIF crderr% = -2 THEN goto evt_nomodule ELSEIF crderr% = -3 THEN goto evt_nocard_cmd ELSEIF crderr% = -4 THEN goto evt_badcard ELSE cls locate 0,0 print " Cardcmd error " print " # " + str$(crderr%) ; gosub card_error_tone sleep 2500 running = false% ENDIF return
160
Chapter 5 LaserLite Mx Memory Card Data Management
Page 169
evt_nomodule: '* '* evt_nomodule '* description: This event is set when the system starts and '* the monitor determines that there is no response from a '* memory card module. Since this application is designed to '* run with a memory card, it should not be allowed to run '* when this event is encountered. '* cls 'A -2 error is set by the system at start up locate 0,0 'if it determines there is no memory card print " No card module" 'module present. This program 'doesn't do much good on a 'system like that. print " detected "; gosub card_error_tone sleep 3000 running% = false% end return evt_nocard: '* '* evt_nocard '* description: This event is set when the system starts and '* the monitor determines that no memory card is inserted. '* Since this application is designed to run with a memory '* card, it should not be allowed to run when this event is '* encountered. It calls the sleep routine to allow the user '* to insert a card and then restart the application. '* 'After waking up from sleep, the system 'determined that there was no card inserted cls 'and set a global flag to indicate no card. locate 0,0 'The system must wake up from sleep with a print " No card " 'memory card inserted to print " inserted! "; 'clear this flag. gosub card_error_tone sleep 2500 cls locate 0,0 print "Insert card then" print " press a key "; sleep 10 return
Chapter 5 LaserLite Mx Memory Card Data Management
161
Page 170
evt_nocard_cmd: '* '* evt_nocard_cmd '* description: This routine is called when a -3 (no card) '* error is received from CARDCMD. It warns the user then '* exits to the OS. When the memory card is re-inserted, '* then the user may press and hold the scan button. The '* application restart allows the monitor to determine if a '* card has been placed in the slot. Since this application '* is designed to run with a memory card, it should not be '* allowed to run without one inserted. '* cls locate 0,0 print " No card " print " inserted! "; gosub card_error_tone sleep 2000 cls locate 0,0 print "Insert card then" print "hold SCAN button"; sleep 5000 running% = false% return
162
Chapter 5 LaserLite Mx Memory Card Data Management