User Tools

Site Tools


**The OOBD Book** Download as [[epub|eBook]] \\ Download as [[|PDF / Mobi]] * [[start|Documentation]] * Installation * [[startup_javame|OOBD-ME (Mobile Phones)]] * [[startup_android|OOBD-Android]] * [[startup_windows|Windows OOBDesk]] * [[startup_embedded|Raspi & Co]] * [[startup_usage|Start the programs]] * [[startup_oobdscript|First Success: Run the OOBD script]] * [[lua_start|Lua in OOBD]] * [[tools_quickscript|Click your Script: Quick Script]] * [[lua_make-your-own-scripts|Make your own OOBD Scripts]] * [[lua_tutorial|The OOBD Lua Tutorial]] * [[lua_make|Lua Build Enviroment]] * Web UI * [[:de:doc:webui_tutorial|Web User Interface Tutorial(German)]] * [[webui_guide|Web UI Package structure]] * [[:de:doc:webui_simulator|UI Emulator for development(German)]] * [[hw_start|The OOBD Hardware]] * [[hw_quickstart|OOBD Cup Quick Start]] * [[hw_assembly-cupv5|Build your own Dongle]] * [[hw_busswitch|Add a second Bus to DXM]] * [[hw_bootloader|Flash the Bootloader]] * [[hw_firmware|Flash the Firmware]] * [[hw_flash-from-usb-stick|Flash the Firmware from USB-Stick]] * [[hw_commands|The Firmware Commands]] * [[tools_start|The OOBD Utilities]] * [[tools_kadaver|Kadaver]] * [[tools_quickscript|Quick Script]] * [[tools_cortex-crc32|Cortex-CRC32]] * [[tools_filelist|Filelist]] * [[tools_olp|OLP]] * [[tools_oobdcopyshop|OOBDCopyShop]] * [[tools_oobdtemple|oobdtemple]] * [[tools_oodbcreate|OODBCreate]] * [[tools_opendiagx|OpenDiagX]] * [[tools_oobdcmd|OOBDcmd]] * [[tools_oobdflash|OOBDFlash]] * PGP * [[pgp_setup|Install PGP Keys]] * [[dev_start|Development]] * [[dev_googlesetup|Join the News]] * Setup your Developer Environment * [[dev_cygwininstall|CygWin Environment]] * [[dev_setupswing|Java Swing]] * [[dev_setupme|Java ME]] * [[dev_setupandroid|Android]] * [[dev_androidlivecd|The Android Debug Live CD]] * [[dev_setupfirmware|Firmware]] * [[dev_clientdesignguide|User Interface Design Guide]] * [[dev_systemspec|The OOBD System Spec]] * [[dev_readotherformats|Import XML files]] * [[dev_links|Link Collection]] * [[dev_roadmap|Road Map]] * [[rfc_start|Specifications (RFC)]] * [[rfc_firmware_syntax|OOBD Firmware: General Command Syntax]] * [[rfc_canuds-mode|OOBD Firmware: Protocol : UDS (P 6 ..)]] * [[rfc_canraw-mode|OOBD Firmware: Protocol : CANraw (P 6 ..)]] * [[rfc_rtd-real-time-data-protocol-for-the-oobd-firmware|OOBD Firmware: Protocol : Real Time Data (RTD) (P 6 ..)]] * [[rfc_pgp-encrypting-sensible-data-with-pgp|PGP Principle]] * [[rfc_onion|The ONION Message Format]] * [[faq|Frequently Asked Questions]]


The OOBD Lua Tutorial

While the page Lua scripts in OOBD tells you the basics about how Lua works inside OOBD, this tutorial will show you how to use Lua to realize your own ideas.

In this tutorial we'll read the VIN number from a vehicle. While doing that, we'll create a menu, identify the hardware, use the OOBD Lua function library, talk to the vehicle and show the result.

First we'll need a Menu on the screen to be able to start anything at all. That we'll do with the following code sequence

function Start(oldvalue,id)
	openPage("VIN Test")
	addElement("VIN Number", "vin","-",0x2, "")
	return oldvalue
----------------- Do the initial settings --------------

So what happens here? When the Lua interpreter runs through the script, it finally finds the


command at the end. This is one of the naming conventions in OOBD: The function, which initializes everything, must be called “Start”.

When we looking into the Start function, we'll find


This a function out of the serial_dxm.lua support library. In there you can find several needful functions, which are used by more or less all OOBD scripts, so we've put these functions into a common file.

identifyOOBDInterface evaluates, which OBD hardware dongle is connected to make the further dongle commands inside the library more hardware independent.

The command sequence openPage(“VIN Test”), addElement(“VIN Number”, “vin”,“-”,0x2, “”) and pageDone() create and show a menu, containing the only list entry “VIN Number”. The addElement() command assigns the lua function vin to this menu entry:

function vin(oldvalue,id)
	if udsLen>0 then
		if udsBuffer[1]==73 then
			local pos=4
			local res=""
			while pos <= udsLen and pos < 36 do
				if udsBuffer[pos]>31 then
				pos= pos +1
			return res
			return "Error"
		return "NO DATA"

This function is called when the user selects the Menu entry “VIN Number”. Inside this function first the command


sends the text “0902” as hexadecimal data string to the OBD dongle, which is the OBD standard command to request the vehicle Identification Number (VIN) from a vehicle. The dongle itself forwards this data sequence as binary telegram onto the vehicle diagnostics bus and waits for an answer from the vehicle module.

The command


picks up the module answer from the OBD dongle. When udsLen is greater than 0, it means that something is received. The received bytes themself are stored in the byte array udsBuffer[].

As we are expect an ASCII VIN number in the received data, we run through the udsBuffer[] and join all bytes found as their ASCII values together to the string res. This string res we than finally return

return res

as the result of this function.

This is also important to know: All Lua functions which are called from a menu entry must return a string value, as this string is than displayed in the menu as actual value, so it represents the result of the call as feedback to the user.

And that's already the whole magic… Based on this scheme all wanted functionality can be realized in OOBD with Lua

  • create a menu entry
  • link a function to it
  • do the wanted stuff inside the function
  • return the result as string
This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information
doc/lua_tutorial.txt · Last modified: 2014/03/02 07:26 by admin