Click here to Skip to main content
15,914,225 members

Comments by pravin29 (Top 9 by date)

pravin29 4-Apr-12 2:31am View    
Right now i can receive single byte by calling ReadFile.
pravin29 4-Apr-12 1:59am View    
We are using Endpoint OUT - 81 and IN - 2 (Bulk USB transfer)
pravin29 4-Apr-12 1:27am View    
1. The event being signaled alerts that data has arrived. You can create your own DataReceived event.
>> Let's assume device sent 1 byte of data on USB port. Now how could application software signaled this event. In VC++, For serial, communication there is EV_RXCHAR event. When this event signaled then we call ReadFile. In C# direct event provided from Serial class.

Serial _serialVP = new SerialPort("COM7");

_serialVP.BaudRate = 115200;
_serialVP.Parity = Parity.None;
_serialVP.StopBits = StopBits.One;
_serialVP.DataBits = 8;
_serialVP.Handshake = Handshake.None;

_serialVP.DataReceived += new SerialDataReceivedEventHandler(DataReceviedHandler);

private void DataReceviedHandler(
object sender,
SerialDataReceivedEventArgs e)
{
SerialPort sp = (SerialPort)sender;
int inData = sp.ReadByte();

}

This example is for serial. i wish same implementation for USB.
pravin29 3-Apr-12 10:05am View    
Thank you for your reply.
I did this. Here is code -

Collapse | Copy Code


g_hw_USBWrite = CreateFile (UsbWritePipe,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, // no SECURITY_ATTRIBUTES structure
OPEN_EXISTING, // No special create flags
0, // No special attributes
NULL); // No template file

hEventObject = CreateEvent((LPSECURITY_ATTRIBUTES)NULL,FALSE,TRUE,"");
HIDOverlapped.hEvent = hEventObject;
HIDOverlapped.Offset = 0;
HIDOverlapped.OffsetHigh = 0;

InputReportBuffer[0] = 0;

int s_i_NoOfBytes = 1;
Result = ReadFile(g_hw_USBRead,InputReportBuffer,s_i_NoOfBytes,&BytesRead,(LPOVERLAPPED) &HIDOverlapped);
Result = WaitForSingleObject(hEventObject,1000);

switch (Result)
{
case WAIT_OBJECT_0:
{
// Success;
// Use the report data;
break;
}
case WAIT_TIMEOUT:
{
// Timeout error;
//Cancel the read operation.
CancelIo(g_hw_USBRead);
break;
}
default:
{
// Undefined error;
//Cancel the read operation.
CancelIo(g_hw_USBRead);
break;
}
}


Actually problem is, application software doesn't know how much data (or bytes) to receive from device. In overlapped IO there is necessity to call ReadFile first and then wait for signaling. I just want DataReceived event similar to serial (which invoke by OS)
pravin29 12-Jan-11 0:03am View    
Everything works in ideal condition.