User Tools

Site Tools


doc:lua:start

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
doc:lua:start [2011/06/05 17:46] admindoc:lua:start [2013/12/29 16:14] admin
Line 27: Line 27:
  
 In the moment the OOBD interface supports two kinds of interfaces for Lua: Some for creating the menus, and some to talk to the serial line (( this is certainly subject to change in the future, when OOBD becomes more generic and the data links become more abstract)) In the moment the OOBD interface supports two kinds of interfaces for Lua: Some for creating the menus, and some to talk to the serial line (( this is certainly subject to change in the future, when OOBD becomes more generic and the data links become more abstract))
 +
 +
 +**Important** To allow it during debugging to replace the hardcoded extended Lua functions against some own debugging code, normally the hardcoded functions are assigned to some Lua variables first, which then are used in the later script:
 +
 +  local serFlush =serFlushCall
 +  serflush()
 +  
 +  
 +So by naming convention the hardcoded extended functions ends with xxx"Call", while the name used later is without "Call"
 +
 +Please keep this in mind while reading this document or writing own code.
  
  
Line 103: Line 114:
   * Flagset(Integer): This is an integer value, where each bit represents a flag. The meanings of these flags are explained in the [[:dev:clientdesignguide|Client design guide]] (look for System Flags)   * Flagset(Integer): This is an integer value, where each bit represents a flag. The meanings of these flags are explained in the [[:dev:clientdesignguide|Client design guide]] (look for System Flags)
   * id(String): The id is used to add an individual marker to a menu item. This is widely used when one single Lua function should support many menu items. This is descripted in detail in the [[#the_menu_function_call|Menu Function Calls]] below.   * id(String): The id is used to add an individual marker to a menu item. This is widely used when one single Lua function should support many menu items. This is descripted in detail in the [[#the_menu_function_call|Menu Function Calls]] below.
 +
 +=== "advanced" addElement(Description, function, initialValue, Flagset, id, type) === 
 +
 +
 +
 +
  
 === pageDone() === === pageDone() ===
Line 122: Line 139:
   - than that Lua function is called, with two parameters:   - than that Lua function is called, with two parameters:
     * the actual displayed value of that item     * the actual displayed value of that item
-    * and the id with we gave to that menu item during initialisation+    * and the id with we gave to that menu item during initialization
   - than the called Lua function does something, e.g. a calculation or it starts to generate another submenu   - than the called Lua function does something, e.g. a calculation or it starts to generate another submenu
   - when the function is finished, it returns a string value   - when the function is finished, it returns a string value
   - that string value is then displayed as new value of the menu item   - that string value is then displayed as new value of the menu item
  
-That'allready all, that does the job :-)+That'already all, that does the job :-) 
 + 
 + 
 +==== The Communication  Commands ==== 
 + 
 +OOBD uses (actual) serial communication to talk to the diagnostic device. To allow Lua to send and receive data from the serial port, a few extended Lua functions exists: 
 + 
 +=== serFlush() === 
 + 
 +It just clears the input buffer (from anything which was maybe received in the meantime and which is not needed anymore) 
 + 
 + 
 +=== serWrite(String) === 
 + 
 +Sends //String// to the output (which is normally the serial port) 
 + 
 + 
 +=== serSleep(milliseconds) === 
 + 
 +waits //milliseconds// 
 + 
 +=== serReadLn(msTimeout) === 
 + 
 +reads from input until a LF (dez. 10 hex 0x0A) appears and returns that input as String 
 + 
 +=== serWait(OptionString, msTimeout) === 
 + 
 +In case you want to wait for some input strings, of which several could appear, you fill the //Optionstring// with string1|string2|..|stringN. If then one of this string appears at the input, the index of the found string is returned (first string=1). If the string does not appear within //msTimeout//, the function returns 0. 
 + 
 + 
 +====  Miscellaneous  Commands ==== 
 + 
 +=== serDisplayWrite(String) === 
 + 
 + 
 +Writes //String// to the build in output console. 
 + 
 +=== dbLookup(db-File , searchstring) === 
 + 
 +Searches in the //db-file// for all entries with index //searchstring//. The //db-file// needs to be in the same directory as the Lua- script itself. The //db-file// itself is made by [[doc:oodbcreate|oodbCreate]]. 
 + 
 +dbLookup() returns a Lua table 
 +   
 +  myTable = dbLookup("dtc.oodb", "0815"
 + 
 +//myTable.len// tells the success status: 
 +  * if //myTable.len// < 0 then an error has occured 
 +  * if //myTable.len// = 0 then //searchstring// has not been found 
 +  * if //myTable.len// > 0 then //myTable.len// tells the number of entries found 
 + 
 +When something has been found, than //myTable// contains two sections, //header// and //data//. 
 + 
 +The header section is needed in case you don't know in which column your wanted result is stored; you can identify the column by its column header name instead: 
 + 
 +   col= myTable.header["DTC-Text"
 +   print (col) 
 +   2 
 +    
 + //myTable.header.size// tells the number of colums in total **without** the first index column, which is always surpressed. 
 + 
 + 
 +The //data// section then contains the found data itself, arranged as a two dimensional array, sorted by rows and columns.  
 + 
 +    result=myTable.data[row][column] 
 +   
 +**ATTENTION**: Although the row and column indexes are expressed as numbers (1,2,3,4..), they are internally represented as string values ("1","2","3","4"...), so to read the result correctly, numeric row and column counters need to be converted to strings first to address the array correctly 
 + 
 +    column=3 
 +    row=2 
 +    result=myTable.data[tostring(row)][tostring(column)]) 
 +     
 +     
 + Here after all a piece of sample code 
 + 
 +<code lua> 
 +myTable= dbLookupCall("dtc.oodb","005"
 + 
 +print ("header"
 +for k,v in pairs (myTable.header) do 
 +    print (k,"=",v) 
 +end 
 + 
 +nrOfColumns = myTable.header.size 
 +nrOfRows = myTable.len 
 + 
 +print ("Rows x Columns:" ,nrOfRows, nrOfColumns) 
 + 
 + 
 +for row = 1 , nrOfRows , 1 do 
 +  for column = 1 , nrOfColumns, 1 do  
 +   
 +   print (cy, cx, myTable.data[tostring(row)][tostring(column)]) 
 +  end 
 +end 
 +</code>
  
 ===== Some Programming Tricks ===== ===== Some Programming Tricks =====
Line 169: Line 280:
  
 By that it's possible without big efforts to fill a menu  with real data already during initialization, so the actual data is visible straight from the beginning. By that it's possible without big efforts to fill a menu  with real data already during initialization, so the actual data is visible straight from the beginning.
- 
-