doc:lua_make-your-own-scripts
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_make-your-own-scripts [2014/05/31 11:39] – [Miscellaneous Commands] admin | doc:lua_make-your-own-scripts [2014/10/13 18:46] – admin | ||
---|---|---|---|
Line 137: | Line 137: | ||
==== The Communication | ==== The Communication | ||
+ | |||
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: | 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() === | ||
+ | |||
It just clears the input buffer (from anything which was maybe received in the meantime and which is not needed anymore) | It just clears the input buffer (from anything which was maybe received in the meantime and which is not needed anymore) | ||
Line 146: | Line 149: | ||
=== serWrite(String) === | === serWrite(String) === | ||
- | |||
- | Sends //String// to the output (which is normally the serial port) | ||
+ | Sends //String// to the output (which is normally the serial port) | ||
=== serSleep(milliseconds) === | === serSleep(milliseconds) === | ||
- | waits // | ||
+ | waits // | ||
=== serReadLn(msTimeout) === | === serReadLn(msTimeout) === | ||
+ | |||
reads from input until a LF (dez. 10 hex 0x0A) appears and returns that input as String | 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 // | In case you want to wait for some input strings, of which several could appear, you fill the // | ||
+ | |||
+ | |||
+ | ==== The IO Commands ==== | ||
+ | |||
+ | |||
+ | FIXME the whole IO command section is in pure experimental state. There' | ||
+ | |||
+ | |||
+ | OOBD uses its own scheme for file IO, mainly driven by the restriction of a remote user and the need of complex data buffer handling. | ||
+ | |||
+ | |||
+ | Similar to the LUA simple IO model, OOBD has always only just input and output file handle. As long as not redirected, these are stdin and stdout. | ||
+ | |||
+ | |||
+ | As OOBD knows more as only one type of data sources, the parameter '' | ||
+ | |||
+ | |||
+ | . | ||
+ | |||
+ | |||
+ | === ioInput(file_name , | ||
+ | |||
+ | |||
+ | Tries to open the file accourding to the following parameter combinations: | ||
+ | |||
+ | |||
+ | ^ filename | ||
+ | |/ | ||
+ | |/ | ||
+ | |URL like '' | ||
+ | |URL like '' | ||
+ | |||
+ | |||
+ | === ioRead(" | ||
+ | |||
+ | |||
+ | Read one line of the input file ending with either %%\%%r%%\%%n or %%\%%n as string without the EOL. In case of input EOF or read errors the function returns nil | ||
+ | |||
+ | |||
+ | === ioRead (" | ||
+ | |||
+ | |||
+ | Read the whole file as string | ||
+ | |||
+ | |||
+ | === ioRead (count) === | ||
+ | |||
+ | |||
+ | Read count number of bytes as string | ||
+ | |||
+ | |||
+ | === ioOutput(URL[, | ||
+ | |||
+ | |||
+ | Try to opens '' | ||
+ | === ioWrite (String) === | ||
+ | |||
+ | |||
+ | Attaches the string content to the output file | ||
+ | |||
+ | |||
+ | |||
+ | === loadbuffer === | ||
+ | len, newfilename= loadbuffer(start , filelen , file_name , file_extension , message) | ||
+ | |||
+ | Reads the file " | ||
+ | |||
+ | The data source can be defined as explained for the ioInput command. | ||
+ | |||
+ | The number of bytes read will be returned in " | ||
+ | |||
+ | The following conditions apply: | ||
+ | * The selected filename will be returned in " | ||
+ | * If filename is 0, the whole file will be read. If the length exceeds the telegram length, an error will be raised. | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | === savebuffer === | ||
+ | len, newfilename = savebuffer(start , filelen , file_name , file_extension , message) | ||
+ | |||
+ | Writes the telegram buffer starting at position " | ||
+ | |||
+ | The number of bytes written will be returned in " | ||
+ | |||
+ | The following conditions apply: | ||
+ | * The selected file name will be returned in " | ||
+ | * If len is 0, the whole telegram buffer will be written. | ||
+ | |||
+ | === setbuffer === | ||
+ | setBuffer(bufferNr , newSize ) | ||
+ | |||
+ | Changes the actual buffer used to buffer number " | ||
+ | |||
+ | If newsize is <> 0, the old buffer is deleted and new memory with size newmem is allocated | ||
+ | |||
+ | |||
+ | === copyBuffer === | ||
+ | copyBuffer(bufferNr ) | ||
+ | |||
+ | Copies the content of buffer | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | === BlitBuffer === | ||
+ | BlitBuffer(frombuffer , startpos , topos , blocklen | ||
+ | |||
+ | Copies a memory block from the buffer " | ||
+ | |||
+ | In case the buffer len needs to be bigger, the buffer len is increased accourdingly. | ||
+ | |||
+ | === SetBufferLen === | ||
+ | |||
+ | |||
+ | | ||
+ | |||
+ | All other buffer commands can increase the ' | ||
+ | |||
+ | SetBufferLen sets the ' | ||
+ | |||
+ | The success of the SetBufferLen - operation is returned as function result as follows: | ||
+ | |||
+ | ^ input value of newSize | ||
+ | | < = 0 | available size of the buffer in bytes. This can be used to read the real allocated memory size of that buffer | ||
+ | | 1.. available size | new available size (= requested size) | | ||
+ | | > available size | available size of the buffer as **negative value ** . This is a fault condition | | ||
+ | |||
+ | As seen, a negative value given back indicates a fault condition, all other returned values are positive. | ||
+ | |||
+ | |||
+ | === SendBuffer === | ||
+ | Sends the actual buffer | ||
+ | |||
doc/lua_make-your-own-scripts.txt · Last modified: 2019/04/08 18:43 by admin