0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

EV3DEVでドライバで使うセンサーのIDを取得する

Posted at

やること

EV3DEVのドライバで直接参照できるIDを取得する。

方法

/sys/class/lego-sensor内の各ディレクトリのaddressファイルを読み取り、それを物理ポートと照合する。

実装例

main.py
def sensor_port_to_id(port: int) -> int:
    dirs = os.listdir('/sys/class/lego-sensor')
    for _dir in dirs:
        address_file = open('/sys/class/lego-sensor/' + _dir + '/address')
        address = address_file.read()
        address_file.close()
        if address == 'in' + str(port):
            return int(_dir.replace('sensor', ''))
        return 0

参考文献

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?