An <anuj.tanksali@gmail.com> [2010-12-18 05:47:17]:
I wanted a program by which is wanted to read each byte received on serial
port by beagle board.
Hi,
maybe it's not exactly what are you looking for, but there are recipes for
librs232(C library) and lua-rs232(Lua bindings) in OpenEmbeedded(Angstrom), so
building/using it on Beagle should be easy, you just need to build the
package on your host PC:
bitbake lua-rs232
then just transfer the packages(librs232 and lua-rs232) to Beagle, install them
with opkg and then you just need some small Lua test script which will
read/echo every received byte:
root@beagle$: cat test.lua
rs232 = require("luars232")
port = "/dev/ttyUSB0"
read_timeout = 200
read_len = 1
function ts() return os.date('[%d.%m.%Y %H:%M:%S] ') end
function log(...) io.stdout:write(ts(), string.format(...):gsub('\r\n', ''), '\n') end
function hex(s) return string.gsub(s, ".", function(x) return string.format('%02x', string.byte(x)) end) end
function main()
local ret, p = rs232.open(port)
if ret ~= rs232.RS232_ERR_NOERROR then
log("[!] error open() : '%s' (%d)", rs232.error_tostring(ret), ret)
return
end
p:set_baud_rate(rs232.RS232_BAUD_115200)
log("[*] port open...")
local i = 1
while true do
local ret, data, len = p:read(read_len, read_timeout)
if len > 0 then
log("[*] read: '%s'(%s) len: %d", data, hex(data), len)
end
end
end
main()
Believe me, for prototyping it's always faster and easier to do it in some
scripting language. Anyway, the same code can be written in C with librs232
easily also. The source code of librs232[1] is available on GitHub and it's MIT
licensed.
1. https://github.com/ynezz/librs232
-- ynezz