5
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?

RaspberryPi をUSB OTG機能で仮想COM接続して、ExcelにSequence Makerでデータ取得

5
Posted at

はじめに

日置電機株式会社が無償で提供してくれてる『Sequence Maker』は、計測器統合制御をExcelで実現するアドインですが、データが文字列であれば測定器に限らずデータの授受が可能です(バイナリを扱うコマンドも追加されています)。
そこで、パソコンとRasberryPiをUSBケーブルで接続して仮想COMとして認識できれば、Sequence Makerで通信が行えExcel上にデータを記録できるため、RaspberryPi側でセンサ等からデータ取得すれば色々な測定行えると思います。

Raspberry Piの設定

Raspberry Pi Zero / Zero W / Pi 4を使い、USB OTG機能を利用してPC側に仮想COMポートとして認識させる

1. config.txt に追加

/boot/config.txt
dtoverlay=dwc2

2. cmdline.txt の編集

modules-load=dwc2,g_serialrootwaitの後に追加

追加前:

/boot/cmdline.txt
console=serial0,115200 console=tty1 root=PARTUUID=XXXXXXXX-XX rootfstype=ext4 fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles

追加後:

cmdline.txt
console=serial0,115200 console=tty1 root=PARTUUID= XXXXXXXX-XX rootfstype=ext4 fsck.repair=yes rootwait modules-load=dwc2,g_serial quiet splash plymouth.ignore-serial-consoles

USBケーブル接続

USBケーブルをパソコンのUSBに接続して、片方をRaspberry Pi USB Type-Cポート(USB OTG機能に対応はこのポートのみ)に接続

パソコン側は、デバイスマネージャーのポート(COMとLPT)を確認すると、仮想COMとして認識されている。

Raspberry Pi側では /dev/ttyGS0 が仮想COMポートになるので、Pythonなんかで、serial送受信のプログラムを作れば、SequenceMakerでデータを取得できる。

import serial

ser = serial.Serial('/dev/ttyGS0', 115200)

data = ser.readline()
print(data.decode('utf-8').rstrip('\r\n'))
''''''
ser.write(b'XXXXXXXX XXXXXXX')
''''''
5
0
1

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
5
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?