【问题标题】:Reading from input device in ruby从 ruby​​ 中的输入设备读取
【发布时间】:2014-06-28 19:07:45
【问题描述】:

我正在尝试从 ruby​​ 中的输入设备读取事件。

然而

File.open('/dev/input/event9').read 16

返回异常:

Errno::EINVAL: Invalid argument @ io_fread - /dev/input/event9
from (pry):1:in `read'

IOdocumentation中read方法的签名解释了对fread方法的引用(ruby中的read调用C中对应的fread)。

但是,EINVAL 错误似乎是指发送到输入设备的错误建议,但我不太明白。

为了理解这个问题,我已经提交文件给用户组权限,但没有任何运气。

我的问题是:在我的情况下,“无效参数”错误意味着什么?

【问题讨论】:

  • 顺便在 Arch 上使用 ruby​​ 2.1.2

标签: ruby linux io linux-device-driver


【解决方案1】:

请参考man 2 read,这是fread后面的系统调用失败了。

   EINVAL fd is attached to an object which is unsuitable for reading;  or
          the  file  was  opened  with  the  O_DIRECT flag, and either the
          address specified in buf, the value specified in count,  or  the
          current file offset is not suitably aligned.

这基本上意味着附加到/dev/input/event9 的驱动程序对请求的操作不满意。在您的情况下,这可能是由于对齐问题(读取大小错误),有关事件协议以及应如何读取事件设备的详细信息,请参阅https://www.kernel.org/doc/Documentation/input/input.txt

【讨论】:

  • 输入文档确实提供了有关大小的任何建议。然而,对可能大小的简单循环显示 24 及其倍数。我想我需要使用那个。谢谢!
  • 24 对于包含 2 个 int 时间、2 个短代码 + 类型和 1 个 int 值的事件结构来说似乎很奇怪。读取大小应为 16
猜你喜欢
  • 2016-09-12
  • 2016-03-25
  • 2011-04-08
  • 2011-12-19
  • 2016-11-05
  • 1970-01-01
  • 2011-09-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多