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?

「連続出力」コマンドで Lチカ

USB-IO2.0連続出力コマンドを使って Lチカさせてみた。

R内蔵LED の アノード を ポート1 の ピン1 に、カソード を GND に接続。

IMG_3456.png

システム設定で、ポート1 の ピン1 を出力ポートに設定しておくこと。

連続出力コマンド

フォーマットは次のとおり。

conti_out.png

「連続出力」コマンドは USB-IO2.0(AKI)では使えない

バイト1から4バイトごとのブロックで、
出力ポート出力値833.3μs単位の待ち時間8.3μs単位の待ち時間 を指定し、最大15ブロックまで指定できる。

data = [0x22, #連続出力コマンド
    0x01,0x02,0xFF,0x00, #1  On
    0x01,0x00,0xFF,0x00, #2   Off
    0x01,0x02,0xFF,0x00, #3  On
    0x01,0x00,0xFF,0x00, #4   Off
    0x01,0x02,0xFF,0x00, #5  On
    0x01,0x00,0xFF,0x00, #6   Off
    0x01,0x02,0xFF,0x00, #7  On
    0x01,0x00,0xFF,0x00, #8   Off
    0x01,0x02,0xFF,0x00, #9  On
    0x01,0x00,0xFF,0x00, #10  Off
    0x01,0x02,0xFF,0x00, #11 On
    0x01,0x00,0xFF,0x00, #12  Off
    0x01,0x02,0xFF,0x00, #13 On
    0x01,0x00,0xFF,0x00, #14  Off
    0x00,0x00,0x00,0x00, #15 -
    0x00,0x00,0x00]

↑ このコマンドで、点滅周期 約0.4秒(833.3μs × 255 × 2)で7回点滅する。

コード全体

「連続出力」コマンドで Lチカ
import hid

VENDOR_ID = 0x1352   # Km2Net
PRODUCT_ID = 0x0120  # USB-IO2.0

CMD_CONTI_OUTPUT = 0x22 # 連続出力コマンド
MAX_CMD_LENGTH = 64

h = hid.device()
h.open(VENDOR_ID, PRODUCT_ID)

data = [CMD_CONTI_OUTPUT,
    0x01,0x02,0xFF,0x00, #1  On
    0x01,0x00,0xFF,0x00, #2   Off
    0x01,0x02,0xFF,0x00, #3  On
    0x01,0x00,0xFF,0x00, #4   Off
    0x01,0x02,0xFF,0x00, #5  On
    0x01,0x00,0xFF,0x00, #6   Off
    0x01,0x02,0xFF,0x00, #7  On
    0x01,0x00,0xFF,0x00, #8   Off
    0x01,0x02,0xFF,0x00, #9  On
    0x01,0x00,0xFF,0x00, #10  Off
    0x01,0x02,0xFF,0x00, #11 On
    0x01,0x00,0xFF,0x00, #12  Off
    0x01,0x02,0xFF,0x00, #13 On
    0x01,0x00,0xFF,0x00, #14  Off
    0x00,0x00,0x00,0x00, #15 -
    0x00,0x00,0x00]
h.write(data)

print(h.read(MAX_CMD_LENGTH))

h.close()

環境

M1 Mac
macOS 14.5

hidapi 0.14.0
Cython 3.0.10

hidapiインストール方法

  • コマンドのみ
$ pip install Cython

$ git clone https://github.com/gbishop/cython-hidapi.git
$ cd cython-hidapi

$ python setup-mac.py build
$ python setup-mac.py install
  • インストール確認
$ python
Python 3.11.9 (main, Apr  2 2024, 08:25:04) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import hid
>>> hid.__version__
'0.14.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?