gpt4 book ai didi

python - 通过 bash 向 pic18f2550 中继电路发送命令

转载 作者:行者123 更新时间:2023-12-04 18:53:37 25 4
gpt4 key购买 nike

我有一个使用 pic18f2550 的 USB 中继电路,其供应商 ID:0461 和产品 ID:0020 我试图通过 python 通过 pyusb 与此设备通信,我可以连接设备但无法发送任何命令,总是出现忙错误。

如何在 ubuntu 中通过 bash 或 pyusb 向该电路发送命令?

我的python代码是

import usb.core
import usb.util
import struct
dev = usb.core.find(idVendor=0x0461, idProduct=0x0020)
if dev is None:
raise ValueError('Device not found')
cfg = dev[0]
intf = cfg[(0,0)]

ep = usb.util.find_descriptor(
intf,
custom_match = \
lambda e: \
usb.util.endpoint_direction(e.bEndpointAddress) == \
usb.util.ENDPOINT_OUT
)
assert ep is not None

buff = [0x80]
ep.write(buff)

我的 lsusb -v 详细信息;
Bus 003 Device 002: ID 0461:0020 Primax Electronics, Ltd 
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 1.10
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 64
idVendor 0x0461 Primax Electronics, Ltd
idProduct 0x0020
bcdDevice 1.00
iManufacturer 1 SAC
iProduct 2 ----arena----
iSerial 0
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 41
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 0
bmAttributes 0xc0
Self Powered
MaxPower 100mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 2
bInterfaceClass 3 Human Interface Device
bInterfaceSubClass 0 No Subclass
bInterfaceProtocol 0 None
iInterface 0
HID Device Descriptor:
bLength 9
bDescriptorType 33
bcdHID 1.00
bCountryCode 0 Not supported
bNumDescriptors 1
bDescriptorType 34 Report
wDescriptorLength 32
Report Descriptors:
** UNAVAILABLE **
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 1
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x01 EP 1 OUT
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 1
Device Status: 0x0001
Self Powered

最佳答案

尝试在/etc/udev/rules.d 文件中设置如下内容:

子系统 !="usb_device", 操作 !="add", GOTO="device_rules_end"
SYSFS{idVendor} =="1532", SYSFS{idProduct} =="0017", SYMLINK+="mydevice"
模式=“0666”,所有者=“”,组=“根”
LABEL="device_rules_end"

关于python - 通过 bash 向 pic18f2550 中继电路发送命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13884927/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com