lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Sat, Sep 14, 2013 at 5:01 AM, Philipp Janda <siffiejoe@gmx.net> wrote:
Am 14.09.2013 00:41 schröbte Sean Conner:

It was thus said that the Great Jayanth Acharya once stated:
Presently I am using the library/module "luars232" installed via luarocks.
I am using this on a Debian Linux machine, on the USB-serial port
"/dev/ttyUSB0".

I can access this port perfectly well using tools like picocom or minicom,
i.e. have proper bi-directional communication.

However, when I try this snippet:

[code]
rs232 = require("luars232")

port_name = "/dev/ttyUSB0"

local e, p = rs232.open(port_name)
print(e, p)
[/code]

I get the output:
2    nil

Indicating an error in opening the port. One thing that I am pretty sure
of, is that this isn't a permission issue. Since I have already added my
userid to the "dialout" group, and use the "picocom" tool similarly. Also,
I am sure that the port is not in use by any other app/tool at the time of
running the lua snippet.

However, I am not sure how to debug this further.

   Under Linux, an errno of 2 (and I'm assuming that's what's being return
from rs232.open()) means "No such file or directory" so I would double check
that "/dev/ttyUSB0" does indeed exist (perhaps you need to plug in the
USB-serial device into the computer).

Good idea, but in this case a custom error enum[1] is used where 2 is RS232_ERR_OPEN. Since this is running on Linux the place where the error occurs is probably here[2]. So you could recompile with a suitable definition for the DBG macro to get the errno value and an error string, or use `strace` ...

    strace -o trace.txt -- ./your-lua-script

  [1]: https://github.com/ynezz/librs232/blob/master/include/librs232/rs232.h#L150
  [2]: https://github.com/ynezz/librs232/blob/master/src/rs232_posix.c#L434

Never occurred to me that I could strace on a lua script ! Thanks for suggesting it.  As it turns out, I did do something stupid while testing. After adding my user-id to the dialout group, which would've given it the permission to access /dev/ttyUSB0, I kept testing without doing logout/login on the terminal where I was using the lua script. OTOH, I had done that on the other terminal where I was running picocom.

strace told me this clearly --
open("/dev/ttyUSB0", O_RDWR|O_NOCTTY|O_NONBLOCK) = -1 EACCES (Permission denied)

However, I'd also be quite interested in the other method that you suggested. Since I installed the "luars232" library using luarocks, I am not quite sure if there is a place on this machine where the library sources are there, and I can enable DBG and rebuild it. Or, should I clone the "luars232" module from Git and then do this ? If the latter, do I first uninstall the version installed via luarocks ?