Hi Jan,
Thanks for your support all the way in improving my application development.
I am confused and bit stuck at one point now.
I have designed a PC utility based on the USB HID demonstrator available from ST Microelectronics.
Here instead of writing the bytes that are needed to be send to device in the Output Report box, I have written a code and designed a select binary button. Once this button is clicked it allows to select the binary files located on the local drive to be uploaded.
This works fine.
But the problem is once the write button is clicked which actually goes through the routine defined in demonstrator.cpp file it only writes to device the last 256 bytes of the total bytes within the selected file send.
Here
I have mentioned 256 bytes because that is the report count I have set up in the device side descriptor members.
Below is attached the view of demonstrator and the code that it is writting to device.
fp = fopen(PathName,"rb");//opens the file after the select binary button is clicked
for(i=0;i<even;i++)// even is the number total file size divided by 256
{
fread(pData,sizeof(char),256,fp);
memcpy(&OutputReport, pData, OutSize); //send to device
OutputReport[0] = 0x04;
UpdateData(FALSE);
WRITE_ROPRT = TRUE;
}
fclose(fp);
Once when WRITE_RPORT == TRUE
then
it calls the write handle
and
DWORD WINAPI CUsbHidDemonstratorDlg::WriteReport(void*)
{
DWORD BytesWritten = 0;
INT Index =0;
//OutputReport[0] = 0x04;
BOOL Result = TRUE;
while(TRUE)
{
if(WRITE_ROPRT)
{
if (HidDeviceObject != INVALID_HANDLE_VALUE)
{
CancelIo(HidDeviceObject);
if(Use_Setxxx == 1 )
{
//OutputReport[0] = 0x04;
Result = HidD_SetFeature
(HidDeviceObject,
OutputReport,
Capabilities.FeatureReportByteLength);
}
else
{
Result = WriteFile
(HidDeviceObject,
&OutputReport,
Capabilities.OutputReportByteLength,
&NumberOfBytesWriten,
(LPOVERLAPPED) &HIDOverlapped);
}
/*if(InputReport[2] == 0x01)
WaitForSingleObject(ReadThread, INFINITE);*/
WRITE_ROPRT = FALSE;
}
}
_sleep(25);
}
What I want to do is that when first 256 bytes are read in the Output report and the WRITE_RPORT is made true the host should write this bytes to device and wait for acknowledge which is what I have writtin in my device application code.
I am checking whether the Buffer array count is reached 256 or not.
If yes it writes BufferFull = 1
and this value I send as Input report's second byte to host.
I want the host to wait untill it receives this signal and only then it should send the next 256 bytes and so on.
I tried to search on net but was not successful.
Sorry for such long post.
Please need help.
Thanks in advance
Vikram