Skip to content

Sensor.commands throws IOError with EPERM instead of EOPNOTSUPP as said in the docs. #66

Closed

Description

@ensonic
s = ev3dev.TouchSensor(ev3dev.INPUT_1)
s.commands
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build/bdist.linux-armv5tejl/egg/ev3dev/core.py", line 1183, in commands
  File "build/bdist.linux-armv5tejl/egg/ev3dev/core.py", line 187, in get_attr_set
  File "build/bdist.linux-armv5tejl/egg/ev3dev/core.py", line 184, in get_attr_line
  File "build/bdist.linux-armv5tejl/egg/ev3dev/core.py", line 165, in _get_attribute
  File "build/bdist.linux-armv5tejl/egg/ev3dev/core.py", line 79, in read
  File "build/bdist.linux-armv5tejl/egg/ev3dev/core.py", line 65, in file_handle
IOError: [Errno 13] Permission denied: '/sys/class/lego-sensor/sensor1/commands'

While the docs
http://python-ev3dev.readthedocs.org/en/latest/#ev3dev.Sensor.commands
say 'EOPNOTSUPP, this seems to not hold for python.

cat /sys/class/lego-sensor/sensor1/commands
cat: /sys/class/lego-sensor/sensor1/commands: Operation not supported

Activity

  1. ddemidov commented on Nov 5, 2015

    @ddemidov
    Member

    The problem is this code in FileCache.file_handle() method:

            try:
                f.seek(0)
                value = f.readline()
            except IOError:
                f = self.file_handle(path, 'w+', reopen=True)
                value = f.readline()

    When commands attribute of TouchSensor is opened for reading, an exception is thrown: IOError: [Errno 95] Operation not supported. The current code assumes an IOException was thrown because file needs to be reopened in read-write mode, and tries to do that. Then IOError: [Errno 13] Permission denied is thrown and reaches user code. I guess we only need to catch not writable exception, but I am not yet sure how to do this in python.

    EDIT: referenced wrong piece of code initially.

  2. dlech commented on Nov 5, 2015

    @dlech
    Member

    I'm not sure why there is stuff in here for re-opening files. Doesn't the spec tell you if a file is read-only, write-only or read/write? You can just tell files to open with the correct mode in the first place, "r", "w" or "r+".

  3. ddemidov commented on Nov 5, 2015

    @ddemidov
    Member

    The attribute IO happens in generic Device class, which knows nothing about the spec. But I guess we could change the implementation without touching the user-facing API.

  4. ddemidov commented on Nov 5, 2015

    @ddemidov
    Member

    And by the way, spec says that Sensor.commands is read-only. TouchSensor is an exception not covered by the spec.

  5. dlech commented on Nov 5, 2015

    @dlech
    Member

    Why is TouchSensor different?

  6. rhempel commented on Nov 5, 2015

    @rhempel
    Member

    One option (that does not change the user API) is that the attribute getter/setter passes the attribute mode string every time the attribute is accessed - on the other hand, the re-open happens rarely, and I think it's better to get that right than to pass tramp data from the attribute specific get/set to the generic routine...

    Other option is to always open R/W and if there's an error, try R or W until success :-)

  7. ddemidov commented on Nov 6, 2015

    @ddemidov
    Member

    Why is TouchSensor different?

    I was thinking about ev3dev/ev3dev#387 when I wrote this, but I was wrong.

  8. rhempel commented on Nov 7, 2015

    @rhempel
    Member

    @ensonic - if this fixes your issue, please close

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions