LUA

Lua is a small but powerful scripting langage. Here are some of our works and how to use them in your own project. Lua is used for our project GATES and installed both on PC computer and MIPSEL systems.

What you can find on this page


How to use file system for serial communications on Linux
How to use Lua for serial communications on Linux

How to use file system for serial communications on Linux

This is a short example on how to use file system with LUA for serial comunications.

wserial=io.open("/dev/ttyS0","w")
wserial:write("Serial Port OK")
wserial:flush()
rserial=io.open("/dev/ttyS0","r")
while chaine==nil do
        chaine=rserial:read()
        rserial:flush()
end
print(chaine)

How to use Lua for serial communications on Linux

A module called Serial is integrated in LuaX and can be used for serial communications. Written by Asko Kauppi, it seems to be used by a lot of people. My goal was to use this module on embedded systems but Icould not recompile it correctly on MIPSEL chips. So Idecided to write a new module from scratch. This is the description of this module. Called RS232 it can be used both on Linux computer and on Linux embedded systems with MIPSEL chips. This module is written for LUA 5.1.

Which library do you need ?

The RS232 LUA extension uses the EZ24Lib. This library is a shared library wich is simpler to use than the traditional POSIX system for serial port. First you have to install this library on your computer.

This is the compiled version of libezV24. Untar the files is the /usr/lib folder of your computer.

If Ubuntu is used on your computer, you can just install Libezv24 with the Synaptic tool.

The rs232 extension module for LUA

Now it's time to install the extension module for LUA.
This is the gzip file. rs232lua


This file contains 2 files.
rs232.so is the object file. You must put it in the /usr/local/lib/lua/5.1/ folder.
rs232.lua is the loader. You must put it in the /usr/local/share/lua/5.1/ folder.

Now it's time to test the extension module

This is a little test file for our rs232 extension module:

fd=require("rs232")

B9600=13        --  9600 bauds
V24_8BIT=3        -- 8 bits
NO_PARITY=0        -- no parity

-- Open the serial port
-- /dev/ttyS0,V24_STANDARD

-------------------------------------

print("open port /dev/ttyS0")
result=fd.V24OpenPort("/dev/ttyS0",0,0)
print(result)

-- Define serial parameters
---------------------------------------------
print("9600 bauds, 8 bits , no parity")
result=fd.V24SetParameters(B9600,V24_8BIT,NO_PARITY)
print(result)

-- Timeout 5 seconds
------------------------
print("Receive Timeout is 5 seconds")
result=fd.V24SetTimeouts(50)
print(result)

-- Wait a character on the serial port
----------------------------------------------
print("Waiting.......")
result=fd.V24Getc()
print(result)

-- Send 'A'
-------------------------
print("sending 'A'")
result=fd.V24Putc(65)
print(result)

-- Send the string "hello"
-----------------------------

print("sending string 'hello'")
result=fd.V24Write("hello\n\r")
print(result)

-- Close the serial port
--------------------
print("Close serial port")
result=fd.V24ClosePort()
print(result)

For a complete description of the communications parameters, you must read the source of the rs232 extension module.

Have fun.............