You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Sensor.commands throws IOError with EPERM instead of EOPNOTSUPP as said in the docs. #66
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'
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.
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+".
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.
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 :-)
Activity
ddemidov commentedon Nov 5, 2015
The problem is this code in
FileCache.file_handle()method:When
commandsattribute ofTouchSensoris 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. ThenIOError: [Errno 13] Permission deniedis thrown and reaches user code. I guess we only need to catchnot writableexception, but I am not yet sure how to do this in python.EDIT: referenced wrong piece of code initially.
dlech commentedon Nov 5, 2015
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+".
ddemidov commentedon Nov 5, 2015
The attribute IO happens in generic
Deviceclass, which knows nothing about the spec. But I guess we could change the implementation without touching the user-facing API.ddemidov commentedon Nov 5, 2015
And by the way, spec says that
Sensor.commandsis read-only.TouchSensoris an exception not covered by the spec.dlech commentedon Nov 5, 2015
Why is
TouchSensordifferent?rhempel commentedon Nov 5, 2015
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 :-)
ddemidov commentedon Nov 6, 2015
I was thinking about ev3dev/ev3dev#387 when I wrote this, but I was wrong.
rhempel commentedon Nov 7, 2015
@ensonic - if this fixes your issue, please close