Red Rackham wrote: > Hi. I'm a bit of a novice with ctypes and this is my first post here > so please forgive any detected newbiness. After trying and searching > I hereby give up and appeal to the pros out there who may be more > intimately familiar with DeviceIoControl usage. > > I'm trying use Python to access a USB device based on Cypress FX2 > (EZ-USB) type part. >
First, are you using a driver that supports the Cypress standard ioctls? If you are using one of the standard Cypress drivers, then you are, but if this is a device that has its own driver, you might not. > The first operation I'm attempting is to access a command that is > supposed to return the microcontroller's PORTA value. Here's a > minimal amount of code: > > retCode = k32.DeviceIoControl( > dev.deviceHandle, > IOCTL_EZUSB_VENDOR_OR_CLASS_REQUEST, > byref(vrControl), > sizeof(VENDOR_OR_CLASS_REQUEST_CONTROL), > pBuffer, > c_ushort(255), # READ_LENGTH, > byref(retBytes), > None) > > Where the vrControl is a struct like this: > vrControl = VENDOR_OR_CLASS_REQUEST_CONTROL() > vrControl.direction = VENDOR_REQUEST_DIRECTION_DEVICE2HOST > vrControl.requestType = VENDOR_REQUEST_REQUESTTYPE_VENDOR > vrControl.recipient = VENDOR_REQUEST_RECIPIENT_ENDPOINT > vrControl.reqTypeResdBits = 0 > vrControl.request = VR_PORTS > vrControl.value = VR_PORTS_READ << 8 | value > vrControl.index = port > Are you sure your firmware supports the VR_PORTS request? Is this something you added to your firmware? What does your CreateFile call look like? Technically, this request violates the USB spec. You should be using VENDOR_REQUEST_RECIPIENT_DEVICE; you can't use an endpoint request unless the wIndex value specifies an endpoint number that is currently configured. Before changing that, you'd have to make sure the firmware was also set up for that. I almost hate to suggest it, but you might try writing this same sequence as a short, standalone C program, just to make sure that the Python wrapper isn't interfering. I don't see any reason why it should, but it's one less variable. > kernal32.DeviceIoControl returns a 0, and kernal32.GetLastError() is > returning a 995, which is, "ERROR_OPERATION_ABORTED. The I/O > operation has been aborted because of either a thread exit or an > application request" ... > > The reason for the abort does not make sense to me. Anyone know what > would most commonly cause this? What should be my next step? > ERROR_OPERATION_ABORTED maps to STATUS_CANCELED in the driver world. That's a very specific error, which happens only when a driver has requested that your I/O request be canceled. That can happen if you hit Ctrl-C, or if you unplugged the device. However, it shouldn't happen with ordinary requests, unless your driver is enforcing some kind of a timeout. -- Tim Roberts, t...@probo.com Providenza & Boekelheide, Inc. _______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32