Simple iso code isn't sending any data at all (not even a request)?
Chris E <[email protected]> Sat, 6 Jun 2015 16:42:09 +1000
| Newsgroups | gmane.comp.lib.libusb.devel.windows |
|---|---|
| Message-ID | <CALmGtgQMiJBKFA=oOuYRPhHfK+mCUg-DNetB1rJZygLA2zTEHA@mail.gmail.com> |
Basically just using a slightly altered version of the example iso code to
try and communicate to a USB device I'm making. It works absolutely fine
when I send a control tranfsfer.
However, when I try an iso transfer it fails. Firstly, the pipe doesn't
reset (returns error 57h), and then the wait ans release fails (returns
error 490h). Absolutely nothing, IN or OUT, is visible in the packet
sniffer (USBPcap).
To be honest, I don't fully understand why this is the case and have almost
zero experience programming with Windows (or any OS at all - I'm an
electrical engineer and most of the stuff I do is "barebones" programming
on FPGAs or microcontrollers).
Attempt to reset the pipe is done through UsbK_ResetPipe(handle, pipeID);
Reading the iso pipe is attempted through UsbK_IsoReadPipe(handle, pipeID,
isoBuffer, sizeof(isoBuffer), ovlkHandle, isoCtx);
In both occasions, I can't see why any input would be considered dodgy.
The handle works fine for control transfers and the pipeID is checked
by Usb.QueryPipe.
Is this a simple noob mistake or something more serious?
Thanks,
~Chris
P.S. Yes, the application requires that I use iso. It's a USB oscilloscope!
Full output from CMD is:
Looking for device vid/pid 03EB/A000..
Using 03EB:A000 (5&15D9C317&0&4): USBGobindar Dummy Device - Atmel Corp.
Device opened successfully!
Pipe Information:
PipeId=0x81 PipeType=0x01 Interval=1 MaximumPacketSize=256
READING ISO PACKET
&ovlPool= 1702336
&ovlkHandle= 1702348
UsbK_ResetPipe failed. ErrorCode: 00000057h
IsoReadPipe failed. ErrorCode: 00000490h
Full code is:
#include "examples.h"
#include <string.h>
#define mode 1 //0 for control test, 1 for iso test
#define ISO_PACKETS_TO_READ 4
#define ISO_PACKET_SIZE 256
KUSB_DRIVER_API Usb;
DWORD __cdecl main(int argc, char* argv[])
{
KLST_HANDLE deviceList = NULL;
KLST_DEVINFO_HANDLE deviceInfo = NULL;
KUSB_HANDLE handle = NULL;
DWORD ec = ERROR_SUCCESS;
UCHAR pipeIndex = 0;
WINUSB_PIPE_INFORMATION pipeInfo;
WINUSB_SETUP_PACKET setupPacket;
//ISO only
PKISO_CONTEXT isoCtx = NULL;
KOVL_HANDLE ovlkHandle = NULL;
KOVL_POOL_HANDLE ovlPool = NULL;
unsigned char isoBuffer[32 * 256];
BOOL success;
UCHAR pipeID = 0x81;
ULONG transferred = 0;
DWORD errorCode = ERROR_SUCCESS;
BOOL controlSuccess;
unsigned char controlBuffer[64];
UINT bytesTransferred = 0;
ULONG VIDin, PIDin;
int command;
ULONG deviceCount = 0;
//Read in parameters from CMD
strcpy(controlBuffer, argv[1]);
sscanf(argv[2], "%d", &command);
sscanf(argv[3], "%4x", &VIDin);
sscanf(argv[4], "%04x", &PIDin);
//Commands to send to device
switch (command){
case 1: //Print to LCD
setupPacket.RequestType = 0x40;
setupPacket.Request = 0xa0;
setupPacket.Value = 0x00;
setupPacket.Index = 0x00;
setupPacket.Length = 64;
break;
case 2: //Backlight off
setupPacket.RequestType = 0x40;
setupPacket.Request = 0xa1;
setupPacket.Value = 0x00;
setupPacket.Index = 0x00;
setupPacket.Length = 0;
break;
case 3: //Backlight on
setupPacket.RequestType = 0x40;
setupPacket.Request = 0xa1;
setupPacket.Value = 0x01;
setupPacket.Index = 0x00;
setupPacket.Length = 0;
break;
default:
printf("Yeah Nah");
goto Done;
}
//Init device list!
if (!LstK_Init(&deviceList, 0)) {
printf("Error initializing device list.\n");
return 0;
}
//Check if device list is empty
LstK_Count(deviceList, &deviceCount);
if (!deviceCount) {
printf("Device list empty.\n");
LstK_Free(deviceList); // If LstK_Init returns TRUE, the list must be freed.
return 0;
}
printf("Looking for device vid/pid %04X/%04X..\n", VIDin, PIDin);
//Set device info to the info specified by the INF that belongs to said
VID/PID pair
LstK_FindByVidPid(deviceList, VIDin, PIDin, &deviceInfo);
if (deviceInfo){
printf("Using %04X:%04X (%s): %s - %s\n",
deviceInfo->Common.Vid,
deviceInfo->Common.Pid,
deviceInfo->Common.InstanceID,
deviceInfo->DeviceDesc,
deviceInfo->Mfg);
}
else printf("Yeah nah kent couldn't find the device aye\n");
//Tell LibusbK to intercept everything related to this device
LibK_LoadDriverAPI(&Usb, deviceInfo->DriverID);
// Initialize the device
if (!Usb.Init(&handle, deviceInfo)){
ec = GetLastError();
printf("Usb.Init failed. ErrorCode: %08Xh\n", ec);
goto Done;
}
printf("Device opened successfully!\n");
// while the device is opened, query information on the endpoints
// of the first alternate setting of the current interface.
printf("Pipe Information:\n");
while (Usb.QueryPipe(handle, 0, pipeIndex++, &pipeInfo)){
printf(" PipeId=0x%02X PipeType=0x%02X Interval=%u MaximumPacketSize=%u\n",
pipeInfo.PipeId, pipeInfo.PipeType, pipeInfo.Interval,
pipeInfo.MaximumPacketSize);
}
#if mode == 0
//Send Control Packet
printf("SENDING CONTROL PACKET\n");
controlSuccess = Usb.ControlTransfer(handle, setupPacket, controlBuffer,
setupPacket.Length, &bytesTransferred, NULL);
if (controlSuccess) printf("%d BYTES TRANSFERRED", bytesTransferred);
else printf("ERROR");
#elif mode == 1
printf("READING ISO PACKET\n");
//Define Iso Context
IsoK_Init(&isoCtx, ISO_PACKETS_TO_READ, 0);
IsoK_SetPackets(isoCtx, ISO_PACKET_SIZE);
//What is this overlapped pool? Virtual Addresses for I/O? Black magic?
The source of my errors.
OvlK_Init(&ovlPool, handle, 4, 0);
printf("&ovlPool= %d\n", &ovlPool);
OvlK_Acquire(&ovlkHandle, ovlPool);
printf("&ovlkHandle= %d\n", &ovlkHandle);
//Reset Pipe fails!
success = UsbK_ResetPipe(handle, pipeID);
if (~success){
errorCode = GetLastError();
printf("UsbK_ResetPipe failed. ErrorCode: %08Xh\n", errorCode);
}
//Set up iso pipe for n reads.
UsbK_IsoReadPipe(handle, pipeID, isoBuffer, sizeof(isoBuffer), ovlkHandle,
isoCtx);
//Wait for it all to finish!
success = OvlK_WaitAndRelease(ovlkHandle, 1000, &transferred);
if (!success) {
errorCode = GetLastError();
printf("IsoReadPipe failed. ErrorCode: %08Xh\n", errorCode);
goto Done;
}
#endif
Done:
// Close the device handle
// if handle is invalid (NULL), has no effect
Usb.Free(handle);
// Free the device list
// if deviceList is invalid (NULL), has no effect
LstK_Free(deviceList);
// Free the iso context.
IsoK_Free(isoCtx);
// Free the overlapped pool.
OvlK_Free(ovlPool);
return ec;
}
------------------------------------------------------------------------------
_______________________________________________
Libusb-win32-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libusb-win32-devel