giz.mo
Newbie level 4
Hello all,
I have a PIC18F87J50 PIM communicating with a PC running Windows 8.1. I just want to send data with bulk endpoints.
I have written the code for device in C based on the demo project "Device - WinUSB - Generic Dempo Project".
I have written the application in VS2013 professional (C++) based on the tutorial below:
The device is recognized and configured by the PC and the application gets all the descriptors and pipe information without any problem. Everything works fine until the WinUSB_ReadPipe request is sent. As a response to that request I get the Last Error Code:31 which means "A device attached to the system is not functioning." I have no idea what is wrong.
Here is my configuration descriptors:
The code to send the data:
The function to initialize the endpoints;
WINDOWS APPLICATION
I keep getting the error code 31 ffrom this function. What is wrong with these codes? Any help would be appreciated very much!
Thank you!
I have a PIC18F87J50 PIM communicating with a PC running Windows 8.1. I just want to send data with bulk endpoints.
I have written the code for device in C based on the demo project "Device - WinUSB - Generic Dempo Project".
I have written the application in VS2013 professional (C++) based on the tutorial below:
The device is recognized and configured by the PC and the application gets all the descriptors and pipe information without any problem. Everything works fine until the WinUSB_ReadPipe request is sent. As a response to that request I get the Last Error Code:31 which means "A device attached to the system is not functioning." I have no idea what is wrong.
Here is my configuration descriptors:
Code:
/* Configuration 1 Descriptor */
ROM BYTE configDescriptor1[]={
/* Configuration Descriptor */
0x09, //sizeof(USB_CFG_DSC), // Size of this descriptor in bytes
0x02, // CONFIGURATION descriptor type
0x19,0x00, // Total length of data for this cfg
1, // Number of interfaces in this cfg
1, // Index value of this configuration
0, // Configuration string index
_DEFAULT | _SELF, // Attributes, see usb_device.h
50, // Max power consumption (2X mA)
/* Interface Descriptor */
0x09, //sizeof(USB_INTF_DSC), // Size of this descriptor in bytes
0x04, // INTERFACE descriptor type
0, // Interface Number
0, // Alternate Setting Number
1, // Number of endpoints in this intf
0xFF, // Class code
0xFF, // Subclass code
0xFF, // Protocol code
0, // Interface string index
0x07, /*sizeof(USB_EP_DSC)*/
0x05, //Endpoint Descriptor
_EP01_IN, //EndpointAddress
_BULK, //Attributes
USBGEN_EP_SIZE,0x00, //size
1 //Interval
};
The code to send the data:
Code:
void myApp(void)
{
if(blinkStatusValid)
{
BlinkUSBStatus();
}
if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) return;
if(!USBHandleBusy(USBGenericInHandle))
{
INPacket[0] = 0xab;
USBGenericInHandle = USBGenWrite(USBGEN_EP_NUM,(BYTE*)&INPacket[0],64);
}
}
The function to initialize the endpoints;
Code:
void USBCBInitEP(void)
{
//Enable the appplication data endpoint(s)
USBEnableEndpoint(USBGEN_EP_NUM,USB_OUT_ENABLED|USB_IN_ENABLED|USB_HANDSHAKE_ENABLED|USB_DISALLOW_SETUP);
}
WINDOWS APPLICATION
Code:
BOOL ReadFromBulkEndpoint(WINUSB_INTERFACE_HANDLE hDeviceHandle, UCHAR* pID)
{
if (hDeviceHandle == INVALID_HANDLE_VALUE)
{
return FALSE;
}
BOOL bResult = TRUE;
UCHAR* szBuffer = (UCHAR*)LocalAlloc(LPTR, 64);
ULONG cbRead = 0;
bResult = WinUsb_ReadPipe(hDeviceHandle, *pID, szBuffer, 64, &cbRead, 0);
if (FALSE == bResult ) {
printf(_T("Error among LastError %d \n"),
FALSE == bResult ? GetLastError() : 0);
}
printf("Read from pipe %04X: %s \nActual data read: %d.\n", *pID, szBuffer, cbRead);
LocalFree(szBuffer);
return bResult;
}
I keep getting the error code 31 ffrom this function. What is wrong with these codes? Any help would be appreciated very much!
Thank you!