2012-12-14 33 views
1

我有一個usb繼電器電路,使用pic18f2550,這是供應商id:0461和產品id:0020我試圖通過python通過python通信此設備,我可以連接設備,但不能發送任何命令,總是出現錯誤。通過bash發送命令到pic18f2550繼電器電路

如何通過bash或pyusb發送命令到這個電路在Ubuntu?

我的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) 

我-v的lsusb細節;

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

您是否嘗試過使用Sudo運行,如果是這樣的話,那麼它可能是您在/etc/udev/rules.d中的UDEV規則 – ServerMonkey

回答

0

嘗試在你的/etc/udev/rules.d中的文件設置類似下面:

子系統= 「USB_DEVICE」,ACTION = 「添加」,GOTO = 「device_rules_end」 SYSFS! {idVendor} == 「1532」,SYSFS {idProduct} == 「0017」,SYMLINK + = 「mydevice在」 MODE = 「0666」,OWNER = 「」,GROUP = 「根」 LABEL = 「device_rules_end」

+0

我試過了,但仍然沒有運氣。 –

+0

您是否檢查過日誌以確認系統是否具有預期的設備詳細信息? – ServerMonkey

+0

lsusb -v出口; https://docs.google.com/document/d/1Vv64TrDVdGdXhpxmbv2wMi8fwPia1wep5cDUr0krdwA/edit –