LoginSignup
1
0

More than 1 year has passed since last update.

DD-wrt で usbio を python で動かす

Last updated at Posted at 2023-05-07

背景

dd-wrt から io を制御したかったので、usbio なるものを1000円で入手して試してみた。
WXR-1900DHP は 1300円でゲットして dd-wrt化、USB memory を挿して program (/opt)領域を作ってある。

結果

dd-wrt から python で制御できる。
hid と pyusb を使う方法で確認できたが、すんなりとは行かなかったので、メモしておく

hid 版 install

  • opkg で basic な環境(python3, gcc, etc... )は insatall しておく
opkg install autoconf automake cmake pkg-config hidapi libudev-zero libusb-1.0 libusb-compat
git clone https://github.com/libusb/libusb.git
cd libusb
cp libusb*.h /opt/include
cd ..
git clone https://github.com/trezor/cython-hidapi.git
cd cython-hidapi
git submodule update --init
python setup.py bdist
cd dist
tar xzf hidapi-0.13.1.linux-armv7l.tar.gz -C /

動作サンプルは

pyusb 版 install

pip install pyusb pyusbio 

これで install は終わりますが、動かないので修正版 up しておきます。github の issue には上げてありますが、良く理解しているわけでないので、PR はしてないのです。

/opt/lib/python3.10/site-packages/pyusbio/__init__.py 

を↓これに入れ替えます。
https://github.com/yukkeorg/pyusbio/files/11414034/__init__.zip

動作サンプルは

  • これは、USB-IO2.0をコントロールする ためのライブラリです https://github.com/yukkeorg/pyusbio
  • export PYUSBIO_LOGLEVEL=DEBUG で debug log が出ます。
root@sea-urc19:/opt/home/admin# cat pytest.py
import pyusbio as usbio
usbio = usbio.USBIO()
if usbio.find_and_init():
    port0, port1 = usbio.send2read([0x01, 0x0c])
    print("{0:x}, {1:x}".format(port0, port1))
else:
    print("init error.")

root@sea-urc19:/opt/home/admin# export PYUSBIO_LOGLEVEL=DEBUG
root@sea-urc19:/opt/home/admin# python pytest.py
2023-05-07 15:15:40,727 INFO:PyUSBIO:USB-IO(0x1352, 0x121) is found.
2023-05-07 15:15:40,730 DEBUG:PyUSBIO:IN endpoint address of interface 0 : 0x81
2023-05-07 15:15:40,732 DEBUG:PyUSBIO:OUT endpoint address of interface 0 : 0x1
2023-05-07 15:15:40,734 DEBUG:PyUSBIO:wr:[1, 12]  cmd:[32, 1, 1, 2, 12]
2023-05-07 15:15:40,742 DEBUG:PyUSBIO:rd:array('B', [32, 1, 15])
1, f
  • 補足:同様に Windows 10/cygwin64 環境でも動きました。

usbio モジュール

dd-wrt

  • Router Model: Buffalo WXR-1900DHP
  • Firmware Version: DD-WRT v3.0-r44715 std (11/03/20)
  • Kernel Version: Linux 4.4.241 #1322 SMP Mon Nov 2 06:39:27 GMT 2020 armv7l

Bufferlo WXR-1900DHP

1
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
1
0