All about Programming

Linux python hid usb find/open/write

민토즈 2020. 10. 6. 14:23
300x250

#리눅스에서 USB 장치 동작 시키기

#For Ubuntu

 

import hid

import os

 

#fill with the proper data 

#장치에서 인식 가능한 데이터를 채워넣음

buf = [0x0, 0xff, 0x00, 0x1 ... ]

 

#찾으려는 장치의 vendor id와 product id 입력 

vendorID = 0x1234

productID = 0x5678

 

#hid device가 연결되어 있으면 "path" 정보로 hid device를 open하고, 

#device를 동작시키기 위한 데이터를 전송한다. (device.write)

dev_infos = hid.enumerate(vendorID, productID)

 

dev_dict = dev_infos[0]

 

path_to_open = dev_dict["path"]

device = hid.device()

 

device.open_path(path_to_open)

 

device.write(buf)

device.close()

 

 

300x250