2012/1/11 Bill Mania <maniab...@yahoo.com>:
> I have a Happ Fighting UGCI unit connected to my Linux machine.
> I'm using PyUSB 1.0 and attempting to interact with the Happ. I
> can read the events from the joystick and the buttons all day
> long. However, when I attempt to write to the device, on either
> of the two endpoints, the write()s timeout.
>
> Any experience or examples using this device? What are the
> reasons why a write() will timeout?
>
>
> My script appears as follows:
> -------------------------------------------------------------------
>
> import sys
> import usb.core
>
> VENDOR_ID= 0x078b
> PRODUCT_ID = 0x0030
>
> print "Looking for Happ device"
> device = usb.core.find(idVendor=VENDOR_ID, idProduct=PRODUCT_ID)
>
> if device is None:
>    sys.exit("Could not find Happ device")
>
> print "Checking for active kernel driver"
> if device.is_kernel_driver_active(0):
>    try:
>        print "Detaching kernel driver"
>        device.detach_kernel_driver(0)
>        device.detach_kernel_driver(1)
>
>    except usb.core.USBError as e:
>        sys.exit("Could not detach kernel driver: %s" % str(e))
>
> try:
>    print "Setting configuration"
>    device.set_configuration()
>
> except usb.core.USBError as e:
>    sys.exit("Could not set configuration: %s" % str(e))
>
> configurations = []
> interfaces = []
> endpoints = []
> for configuration in device:
>    configurations.append(configuration)
>    for interface in configuration:
>        interfaces.append(interface)
>        for endpoint in interface:
>            endpoints.append(endpoint)
>
> print "Configurations:", len(configurations)
> print "Interfaces:", len(interfaces)
> print "Endpoints:", len(endpoints)
>
> print "Reading data from Happ device, endpoint %d, size %d" % (
>    endpoints[0].bEndpointAddress,
>    endpoints[0].wMaxPacketSize)
>
> on = True
> onSequence = '\x08\x7F\x7F'
> offSequence = '\08\x00\x00'
>
> while True:
>    try:
>        print "Reading"
>        data = device.read(
>            endpoints[0].bEndpointAddress,
>            endpoints[0].wMaxPacketSize,
>            timeout = 0)
>    except usb.core.USBError as e:
>        if e.args == ('Operation timed out',):
>            print "Timed out"
>
>    if len(data) > 0:
>        for i in data:
>            print i, ',',
>        print ' '
>
>    try:
>            if on:
>                on = False
>                device.write(
>                    endpoints[0].bEndpointAddress,
>                    onSequence,
>                    interfaces[0])
>            else:
>                on = True
>                device.write(
>                    endpoints[0].bEndpointAddress,
>                    offSequence,
>                    interfaces[0]
>                    )
>
>    except usb.core.USBError as e:
>        print "Failed to light switch"
>        print str(e)
>
> --

You cannot write and read on the same endpoint. Endpoints are either
configured as IN or OUT, but not both.

-- 
Best Regards,
Wander Lairson Costa

------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual 
desktops for less than the cost of PCs and save 60% on VDI infrastructure 
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
_______________________________________________
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users

Reply via email to