Hello
Im fooling around with lufa and pythonusb and cant get communication
to the uC to work (endpoint out). I can read from the uC (endpoint
in).
Does anyone have any ideas.
I'll post releveant (i hope =) ) parts of the code below. The code was
originally a lufa example that i have modified.
Configuration
/** Endpoint number of the USBMISSILE data OUT endpoint. */
#define USBMISSILE_DATA_OUT_EPNUM 2
/** Endpoint number of the USBMISSILE data IN endpoint. */
#define USBMISSILE_DATA_IN_EPNUM 2
/** Size in bytes of the USBMISSILE data endpoint. */
#define USBMISSILE_DATA_IN_EPSIZE 1
#define USBMISSILE_DATA_OUT_EPSIZE 1
The actual use of the code
I cant get into the If that checks the OUT endpoint
[code]
void USBMissile_Task(void) {
/* Device must be connected and configured for the task to run */
if (USB_DeviceState != DEVICE_STATE_Configured)
return;
Endpoint_SelectEndpoint(USBMISSILE_DATA_OUT_EPNUM);
Endpoint_SetEndpointDirection(ENDPOINT_DIR_OUT);
LEDs_SetAllLEDs(LEDMASK_BUSY);
if (Endpoint_IsOUTReceived()) {
data = Endpoint_Read_8();
MotorModelCmd(data);<--- I cant get in here.
Endpoint_ClearOUT();
//Cant seem to get here
}
Endpoint_SelectEndpoint(USBMISSILE_DATA_IN_EPNUM);
Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);
if (Endpoint_IsINReady()) {
Endpoint_Write_8(recbytes[1]);
recbytes[1]=recbytes[1]+1;
//Endpoint_Write_8(MotorModelGetEndswitchState());
Endpoint_ClearIN();
}
LEDs_SetAllLEDs(LEDMASK_USB_READY);
}[/code]
Python code to read write
[code]
import usb
class MissileDevice:
def __init__(self):
self.dev=UsbDevice(0x03eb, 0x2040)
self.dev.open()
self.dev.handle.reset()
self.dev.open()
self.GO_LEFT=0x01
self.GO_RIGHT=0x02
self.GO_UP=0x04
self.GO_DOWN=0x08
self.FIRE=0x10
self.STOP=0x00
self.LEFT_ENDSWITCH=0x01
self.RIGHT_ENDSWITCH=0x02
self.UP_ENDSWITCH=0x04
self.DOWN_ENDSWITCH=0x08
def write(self, msg):
return self.dev.handle.bulkWrite(0x02,bytes(chr(msg)))
def read(self,length):
return self.dev.handle.bulkRead(0x82,length)
class UsbDevice:
def __init__(self, vendor_id, product_id):
busses = usb.busses()
self.handle = None
for bus in busses:
devices = bus.devices
for dev in devices:
if dev.idVendor==vendor_id and
dev.idProduct==product_id:
self.dev = dev
self.conf = self.dev.configurations[0]
self.intf = self.conf.interfaces[0][0]
self.endpoints = []
for endpoint in self.intf.endpoints:
self.endpoints.append(endpoint)
return
def open(self):
if self.handle:
self.handle = None
self.handle = self.dev.open()
self.handle.setConfiguration(self.conf)
self.handle.claimInterface(self.intf)
self.handle.setAltInterface(self.intf)
md=MissileDevice()
md.write(0x01)
md.write(0x02)
[/code]
Any ideas?
BR
Anders