LoginSignup
0
1

More than 1 year has passed since last update.

MacでProductIDからシリアルポートを特定する

Posted at

最近Arduinoなどのデバイスを数種類接続して使うことが多いので、
MacBookProでProductIDからArduinoのシリアルポートの番号を特定したかった
動作確認済みデバイスはArdinoUnoとLeonardoのみ

Macの「システム情報」を取得する

system_profilerコマンドでシステム情報に載っているものが取得できる

$ system_profiler SPUSBDataType

スクリーンショット 2022-11-24 17.17.27.png

「システム情報」からLocationIDを抜き出すシェルスクリプト

system_profilerコマンドで取得した情報を使ってProductIDからLocationIDを取得するシェルスクリプトを書く

port_search_pid.sh
#!/bin/sh
PID="$1"
if [ $# != 1 ] || [[ "$PID" != *0x* ]] || [ ${#PID} != 6 ]; then
    echo "Please enter your ProductID"
    exit 1
fi

ARDUINO_PORT=`system_profiler SPUSBDataType | grep -A 8 "Product ID: ${PID}" | grep -n "Location ID" | grep -o '0x....' | sed -e "s/0x//g"`
ARDUINO_PORT=`ls /dev | grep -e "${ARDUINO_PORT}" | head -n 1 | xargs printf '/dev/%s\n'`
echo $ARDUINO_PORT

使い方

引数にProductID(製品ID)を指定して実行するだけ

$./port_search_pid.sh 0x0043 

スクリーンショット 2022-11-24 17.10.06.png

system_profilerのエラーみたいなものも出るけどよくわからない

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