Please help debug - usage of luars232

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Please help debug - usage of luars232

Jayanth Acharya
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.



Reply | Threaded
Open this post in threaded view
|

Re: Please help debug - usage of luars232

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).  

  -spc


Reply | Threaded
Open this post in threaded view
|

Re: Please help debug - usage of luars232

Steve Litt
In reply to this post by Jayanth Acharya
On Sat, 14 Sep 2013 02:57:11 +0530
Jayanth Acharya <[hidden email]> wrote:

> 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")

assert(rs232, "ERROR: nil rs232")

>
> port_name = "/dev/ttyUSB0"

assert(port_name, "ERROR: nil port_name") --probably needless, but...

>
> local e, p = rs232.open(port_name)

assert(e, "ERROR: nil e")
assert(p, "ERROR: nil p")

> print(e, p)
> [/code]

By doing this, you get a feel for exactly when things start going
south, and you can zero in on the problem.

SteveT

Steve Litt                *  http://www.troubleshooters.com/
Troubleshooting Training  *  Human Performance

Reply | Threaded
Open this post in threaded view
|

Re: Please help debug - usage of luars232

Philipp Janda
In reply to this post by Sean Conner
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

>
>    -spc
>

Philipp




Reply | Threaded
Open this post in threaded view
|

Re: Please help debug - usage of luars232

Jayanth Acharya
In reply to this post by Sean Conner
On Sat, Sep 14, 2013 at 4:11 AM, Sean Conner <[hidden email]> wrote:
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).

Was testing the serial port periodically using picocom / minicom as well. It was definitely there, and I am positive that there was no mistake in the path-name.

Reply | Threaded
Open this post in threaded view
|

Re: Please help debug - usage of luars232

Jayanth Acharya
In reply to this post by Steve Litt
Thanks Steve. I should've mentioned that I'd tried to code in debugger (within Zerobrane Lua IDE), stepping through it, with "watch" enabled for rs232, e, p variables, and it was indeed the rs232.open() that failed with e=2, p=nil.

Understood the point about using assert()'s, but doing that alone gave me no more clue than what I already had, thanks to the debugger. Or, am I missing anything here ?


On Sat, Sep 14, 2013 at 4:21 AM, Steve Litt <[hidden email]> wrote:
On Sat, 14 Sep 2013 02:57:11 +0530
Jayanth Acharya <[hidden email]> wrote:

> 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")

assert(rs232, "ERROR: nil rs232")

>
> port_name = "/dev/ttyUSB0"

assert(port_name, "ERROR: nil port_name") --probably needless, but...

>
> local e, p = rs232.open(port_name)

assert(e, "ERROR: nil e")
assert(p, "ERROR: nil p")

> print(e, p)
> [/code]

By doing this, you get a feel for exactly when things start going
south, and you can zero in on the problem.

SteveT

Steve Litt                *  http://www.troubleshooters.com/
Troubleshooting Training  *  Human Performance


Reply | Threaded
Open this post in threaded view
|

Re: Please help debug - usage of luars232

Jayanth Acharya
In reply to this post by Philipp Janda
On Sat, Sep 14, 2013 at 5:01 AM, Philipp Janda <[hidden email]> 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 ?
Reply | Threaded
Open this post in threaded view
|

Re: Please help debug - usage of luars232

Philipp Janda
Am 14.09.2013 06:55 schröbte Jayanth Acharya:
> 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 ?

If the rock uses the `builtin` build type (like luars232) you can
download the rockspec[1] from the luarocks site[2], modify the rockspec
to include the proper defines, and install the rock via the modified
local rockspec:
     luarocks install luars232-1.0.3-1.rockspec

In your case the modified build section in the rockspec would look like
this:

     ...
     build = {
        type = "builtin",
        platforms = {
           unix = {
              modules = {
                 luars232 = {
                    sources = { "src/rs232.c", "src/rs232_posix.c",
"bindings/lua/luars232.c" },
                    incdirs = { "include" },
                    defines = { "RS232_DEBUG=1", "LUAROCKS_HACK
-std=gnu99" },
                 -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^
                 }
              }
           },
     ...


If the rock in question does *not* use the `builtin` build type I would
download and unpack the corresponding source rock (just a zip archive,
see e.g. [3]), modify the build scripts and/or source files inside, move
the included rockspec file to the top-level source directory and call
from there:
     luarocks make

You could also try this with a clone of git head, but some projects
require a non-trivial packaging step (like generating some source file),
in which case this approach would fail unless you also perform those
packaging steps yourself.

   [1]: http://luarocks.org/repositories/rocks/luars232-1.0.3-1.rockspec
   [2]: http://luarocks.org/repositories/rocks/
   [3]: http://luarocks.org/repositories/rocks/luars232-1.0.3-1.src.rock

In both cases you don't need to uninstall anything, the old files in the
local rocks tree just get replaced.

HTH,
Philipp




Reply | Threaded
Open this post in threaded view
|

Re: Please help debug - usage of luars232

Jayanth Acharya
Thanks a lot @Philpp, helps a lot.


On Sun, Sep 15, 2013 at 12:34 PM, Philipp Janda <[hidden email]> wrote:
Am 14.09.2013 06:55 schröbte Jayanth Acharya:

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 ?

If the rock uses the `builtin` build type (like luars232) you can download the rockspec[1] from the luarocks site[2], modify the rockspec to include the proper defines, and install the rock via the modified local rockspec:
    luarocks install luars232-1.0.3-1.rockspec

In your case the modified build section in the rockspec would look like this:

    ...
    build = {
       type = "builtin",
       platforms = {
          unix = {
             modules = {
                luars232 = {
                   sources = { "src/rs232.c", "src/rs232_posix.c", "bindings/lua/luars232.c" },
                   incdirs = { "include" },
                   defines = { "RS232_DEBUG=1", "LUAROCKS_HACK -std=gnu99" },
                -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^
                }
             }
          },
    ...


If the rock in question does *not* use the `builtin` build type I would download and unpack the corresponding source rock (just a zip archive, see e.g. [3]), modify the build scripts and/or source files inside, move the included rockspec file to the top-level source directory and call from there:
    luarocks make

You could also try this with a clone of git head, but some projects require a non-trivial packaging step (like generating some source file), in which case this approach would fail unless you also perform those packaging steps yourself.

  [1]: http://luarocks.org/repositories/rocks/luars232-1.0.3-1.rockspec
  [2]: http://luarocks.org/repositories/rocks/
  [3]: http://luarocks.org/repositories/rocks/luars232-1.0.3-1.src.rock

In both cases you don't need to uninstall anything, the old files in the local rocks tree just get replaced.

HTH,
Philipp