🪪

Raspberry PiでRS-C380を使うメモ

に公開

使ったもの

  • Raspberry Pi Zero W
  • SONY RS-C380

Raspberry Piのセットアップ

ここではPythonのライブラリであるnfcpyを使うので公式ドキュメントに従ってインストールします。
Python3やpip、nfcpyなどはこの記事と同じなのでそちらを参照して入れてください。
https://zenn.dev/ichidomisssuru/articles/9b1abbd47839c3

RC-S380を接続

Raspberry PiにRC-S380を接続します。
そしたら以下のコマンドを入力

bash
~$ python3 -m nfc
This is the 1.0.4 version of nfcpy run in Python 3.9.2
on Linux-6.1.21+-armv6l-with-glibc2.31
I'm now searching your system for contactless devices
** found usb:054c:06c3 at usb:001:003 but access is denied
-- the device is owned by 'root' but you are 'user'
-- also members of the 'root' group would be permitted
-- you could use 'sudo' but this is not recommended
-- better assign the device to the 'plugdev' group
   sudo sh -c 'echo SUBSYSTEM==\"usb\", ACTION==\"add\", ATTRS{idVendor}==\"054c\", ATTRS{idProduct}==\"06c3\", GROUP=\"plugdev\" >> /etc/udev/rules.d/nfcdev.rules'
   sudo udevadm control -R # then re-attach device
I'm not trying serial devices because you haven't told me
-- add the option '--search-tty' to have me looking
-- but beware that this may break other serial devs
Sorry, but I couldn't find any contactless device

いつものやつですね。
ひとまず、実行しろと言われているコマンドを実行します。

bash
~$ sudo sh -c 'echo SUBSYSTEM==\"usb\", ACTION==\"add\", ATTRS{idVendor}==\"054c\", ATTRS{idProduct}==\"06c3\", GROUP=\"plugdev\" >> /etc/udev/rules.d/nfcdev.rules'
~$ sudo udevadm control -R # then re-attach device

呪文を入力したらRS-C380を抜き差ししましょう。
そしたらさっきのコマンドを打ち直しましょう。

bash
~$ python3 -m nfc
This is the 1.0.4 version of nfcpy run in Python 3.9.2
on Linux-6.1.21+-armv6l-with-glibc2.31
I'm now searching your system for contactless devices
** found SONY RC-S380/P NFC Port-100 v1.11 at usb:001:004
I'm not trying serial devices because you haven't told me
-- add the option '--search-tty' to have me looking
-- but beware that this may break other serial devs

問題なく動きました。

プログラム

card_dump.py
import nfc

def on_connect(tag):
    print(tag)
    print(('  \n  '.join(tag.dump())))
    
    return True  # 1枚だけ読み取って終了

def main():
    try:
        #使うポートによって変更する
        #clf = nfc.ContactlessFrontend('tty:S0')
        #clf = nfc.ContactlessFrontend('tty:AMA0')
        clf = nfc.ContactlessFrontend('usb')
        clf.connect(rdwr={'on-connect': on_connect})
    finally:
        if clf:
            clf.close()

if __name__ == "__main__":
    main()

これで、カードの内容を無事読み取れました。

余談

悲しいかな、Raspberry PiではRS-C330の動作はかないませんでした。
ですがRS-C380は問題なく動いていることを考えると、RS-C380はnfcpyととても相性がいいことがうかがえます。
ライブラリ選びも大事ですが、ハード選びも大事ですね。
だから声を大にして言います。
nfcpyを使いたい人は高くてもRC-S380を買え!!!!!
以上です。
ちなみに新型のRC-S300は対応していないそうです。

Discussion