浜松ホトニクスc12880maをRaspberry Pi Pico、MicroPythonで使う(3)

世の中Windowsを使用している人が多いわけで、しかも、Pythonや動作に必要なライブラリをインストールしてまで使ってくれる人は稀だろうから、USBのプラグを挿し込めば動くようにしなければならないわけである。

platformと言うライブラリでOSの種類やシリアルポートをスキャンすることが出来るようである。その後、接続したPicoに合言葉を送って正しい返信が来たらO.K.

という事をしてみたいわけである。

シリアルポートのmanufacturerにMicroPythonがあるポートに対して合言葉を送って返答を待つようにすれば良さそうである。

import platform
import serial.tools.list_ports

class ident_PC():

    def __init__(self):

        self.OS = platform.system()
        self.Version = platform.version()
        self.Platform = platform.platform()

    def scan(self):

        self.ports = serial.tools.list_ports.comports()
        
        for p in self.ports:

                print(": %s" % p)
                print("device: %s" % p.device)
                print("name: %s" % p.name)
                print("description: %s" % p.description)
                print("hwid: %s" % p.hwid)
                print("vid: %s" % p.vid)
                print("pid: %s" % p.pid)
                print("serial Number: %s" % p.serial_number)
                print("location: %s" % p.location)
                print("manufacturer: %s" % p.manufacturer)
                print("product: %s" % p.product)
                print("interface: %s" % p.interface)
    
    def chk_12880ma(self):

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA