doc:lua:start
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
doc:lua:start [2011/06/13 19:29] – admin | doc:lua:start [2012/07/24 09:26] – admin | ||
---|---|---|---|
Line 143: | Line 143: | ||
==== The Communication | ==== The Communication | ||
- | FIXME under construction :-) | + | 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() === | === 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 // | ||
+ | |||
=== serReadLn(msTimeout) === | === serReadLn(msTimeout) === | ||
+ | |||
+ | reads from input until a LF (dez. 10 hex 0x0A) appears and returns that input as String | ||
+ | |||
=== serWait(OptionString, | === serWait(OptionString, | ||
+ | In case you want to wait for some input strings, of which several could appear, you fill the // | ||
Line 160: | Line 171: | ||
=== 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 // | ||
+ | |||
+ | dbLookup() returns a Lua table | ||
+ | | ||
+ | myTable = dbLookup(" | ||
+ | |||
+ | // | ||
+ | * if // | ||
+ | * if // | ||
+ | * if // | ||
+ | |||
+ | 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[" | ||
+ | print (col) | ||
+ | 2 | ||
+ | |||
+ | // | ||
+ | |||
+ | |||
+ | 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**: | ||
+ | |||
+ | column=3 | ||
+ | row=2 | ||
+ | result=myTable.data[tostring(row)][tostring(column)]) | ||
+ | | ||
+ | | ||
+ | Here after all a piece of sample code | ||
+ | |||
+ | <code lua> | ||
+ | myTable= dbLookupCall(" | ||
+ | |||
+ | print (" | ||
+ | for k,v in pairs (myTable.header) do | ||
+ | print (k," | ||
+ | end | ||
+ | |||
+ | nrOfColumns = myTable.header.size | ||
+ | nrOfRows = myTable.len | ||
+ | |||
+ | print ("Rows x Columns:" | ||
+ | |||
+ | |||
+ | for row = 1 , nrOfRows , 1 do | ||
+ | for column = 1 , nrOfColumns, | ||
+ | | ||
+ | print (cy, cx, myTable.data[tostring(row)][tostring(column)]) | ||
+ | end | ||
+ | end | ||
+ | </ | ||
===== Some Programming Tricks ===== | ===== Some Programming Tricks ===== | ||
Line 201: | Line 274: | ||
By that it's possible without big efforts to fill a menu with real data already during initialization, | By that it's possible without big efforts to fill a menu with real data already during initialization, | ||
- | |||
- |