As the title says... Chat on...

User avatar
By markaren1
#54155 Hello all,

Just dipping my toes into LUA, but having a frustrating time getting simple serial I/O via the UART running. All that is needed is to be able to print strings (without terminating newline), and receive strings, terminated by whitespace, or newline. Both calls should block until ready, or complete.

Something like:
uart.setup(0, 9600, 8, 0, 1, 1)
uart.write(0, "Hello, world\n")
str = uart.read(0, '*l', uart.INF_TIMEOUT)
uart.write(0, str)

Which throws up the message
Hello, world
io_test.lua:5: attempt to call field 'read' (a nil value)

I would be perfectly happy to use stdin and stdout (if they do attach to the UART), but am unable to find the correct incantation to prefix an io.write (or io.read call for that matter) with.

Any help appreciated.

Thanks, Mark
User avatar
By devsaurus
#54369 There's no uart.read() function because this would block code execution and break the asynchronous approach of the firmware.
You're better off with uart.on() to provide a callback function that is triggered once bytes have been received over UART.