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/13 19:29] admindoc:lua:start [2013/12/29 16:14] admin
Line 114: 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 143: Line 149:
 ==== The Communication  Commands ==== ==== The Communication  Commands ====
  
-FIXME under construction :-)+OOBD uses (actualserial 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() === === serFlush() ===
  
-Simple, it just clears the the+It just clears the input buffer (from anything which was maybe received in the meantime and which is not needed anymore)
  
  
 === serWrite(String) === === serWrite(String) ===
 +
 +Sends //String// to the output (which is normally the serial port)
 +
 +
 === serSleep(milliseconds) === === serSleep(milliseconds) ===
 +
 +waits //milliseconds//
 +
 === serReadLn(msTimeout) === === serReadLn(msTimeout) ===
 +
 +reads from input until a LF (dez. 10 hex 0x0A) appears and returns that input as String
 +
 === serWait(OptionString, msTimeout) === === 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.
  
  
Line 160: Line 177:
  
 === serDisplayWrite(String) === === 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 201: 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.
- 
-