Hi all,
I'm very new to this list, so hello all!
I'm just starting out using python, my background is lamp.
I have a Prolific Technologies bridged usb cable that I wish to talk to
using pyusb and libusb, I've tried following examples and compiling my
own code but I'm really struggling getting it to work.
I'm trying to send a sequence of letters to the cable, for them to
reappear on the other side. I've been trying to use bulkWrite and
bulkRead methods but I'm not sure I'm using them right. There's also
controlMethod, but I'm not sure what that is used for.
Can anyone help get me started, I'm concerned mostly with the
communication, I reckon I could actually get somewhere if I can just
nail the first bit, here's my code so far:
* Cheers in advance, Mike.
import usb
import sys
import os
import time
from array import array
class DeviceDescriptor:
def __init__(self, vendor_id, product_id, interface_id) :
self.vendor_id = vendor_id
self.product_id = product_id
self.interface_id = interface_id
def get_device(self) :
buses = usb.busses()
for bus in buses :
for device in bus.devices :
if device.idVendor == self.vendor_id :
if device.idProduct == self.product_id :
return device
return None
class XFPS():
VENDOR_ID = 0x067B #: Vendor Id
PRODUCT_ID = 0x0000 #: Product Id for the bridged usb cable
INTERFACE_ID = 0 #: The interface we use to talk to the device
BULK_IN_EP = 0x83 #: Endpoint for Bulk reads
BULK_OUT_EP = 0x02 #: Endpoint for Bulk writes
PACKET_LENGTH = 0x40 #: 64 bytes
device_descriptor = DeviceDescriptor(VENDOR_ID, \
PRODUCT_ID, INTERFACE_ID)
def __init__(self,) :
# The actual device (PyUSB object)
self.device = self.device_descriptor.get_device()
# Handle that is used to communicate with device. Setup in L{open}
self.handle = None
def open(self) :
self.device = self.device_descriptor.get_device()
if not self.device:
print >> sys.stderr, "Cable isn't plugged in"
try:
self.handle = self.device.open()
self.handle.claimInterface(self.device_descriptor.interface_id)
except usb.USBError, err:
print >> sys.stderr, err
def close(self):
""" Release device interface """
try:
self.handle.reset()
self.handle.releaseInterface()
except Exception, err:
print >> sys.stderr, err
self.handle, self.device = None, None
def my_bulk_write(self):
A = chr(0x75) # u
B = chr(0x69) # i
X = chr(0x6F) # o
Y = chr(0x70) # p
LB = chr(0x6C) # l
RB = chr(0x6B) # k
LT = chr(0x68) # h
RT = chr(0x6A) # j
S = chr(0x32)
s = chr(0x73)
self.close()
self.open()
msg = [A,B,A,B,A,B,A,B]
#help(self.handle.bulkWrite)
help(self.handle.interruptWrite)
sent_bytes = self.handle.interruptWrite(XFPS.BULK_OUT_EP,msg,1000)
print sent_bytes
if sent_bytes:
read_bytes = self.handle.interruptRead(0x81,sent_bytes);
print read_bytes
xfps = XFPS()
xfps.open()
xfps.my_bulk_write()
Device info:
------------
Full Speed device @ 3 (0x1D100000):
............................................. Composite device from
Prolific Technology, Inc.
Device Descriptor
Descriptor Version Number: 0x0100
Device Class: 0 (Composite)
Device Subclass: 0
Device Protocol: 0
Device MaxPacketSize: 8
Device VendorID/ProductID: 0x067B/0x0000 (Prolific
Technology, Inc.)
Device Version Number: 0x0000
Number of Configurations: 1
Manufacturer String: 1 "Prolific Technology Inc."
Product String: 0 (none)
Serial Number String: 0 (none)
Configuration Descriptor
Length (and contents): 39
Raw Descriptor (hex) 0000: 09 02 27 00 01 01 00 A0 32
09 04 00 00 03 FF 00
Raw Descriptor (hex) 0010: 00 00 07 05 81 03 01 00 01
07 05 02 02 40 00 00
Raw Descriptor (hex) 0020: 07 05 83 02 40 00 00
Number of Interfaces: 1
Configuration Value: 1
Attributes: 0xA0 (bus-powered, remote wakeup)
MaxPower: 100 ma
Interface #0 - Vendor-specific
Alternate Setting 0
Number of Endpoints 3
Interface Class: 255 (Vendor-specific)
Interface Subclass; 0 (Vendor-specific)
Interface Protocol: 0
Endpoint 0x81 - Interrupt Input
Address: 0x81 (IN)
Attributes: 0x03 (Interrupt no synchronization data
endpoint)
Max Packet Size: 1
Polling Interval: 1 ms
Endpoint 0x02 - Bulk Output
Address: 0x02 (OUT)
Attributes: 0x02 (Bulk no synchronization data endpoint)
Max Packet Size: 64
Polling Interval: 0 ms
Endpoint 0x83 - Bulk Input
Address: 0x83 (IN)
Attributes: 0x02 (Bulk no synchronization data endpoint)
Max Packet Size: 64
Polling Interval: 0 ms
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Pyusb-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyusb-users