- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
time ago I 've posted a discussion Why BeginDataXfer and FinishDataXfer accept Byte array instead of OVERLAPPED struct like WaitForXfer...
and I check answer as correct ...
But I believe that if CyUSB.dll has a BeginDataXfer and FinishDataXfer that accept OVERALAPPED structure reference as last parameter instead of byte array reference
user program will be less complex because of using unsafe/fixed keywords or Marshall class ... this complexity arise because WaitForXfer accept hEvent member of
OVERALAPPED struct.
Yesterday I downloaded CyAPI from site (http://www.cypress.com/documentation/software-and-drivers/ez-usb-fx3-software-development-kit)
then I analyze CyUSBEndPoint::BeginDataXfer method and CyUSBEndPoint::FinishDataXfer respectively at line 295 and 374 ...
I believe that if you add this two overloads (in the snippet below) in CyUSBEndPoint class ... you can implement (for all endpoint types except isochronous) what I discuss in Why BeginDataXfer and FinishDataXfer accept Byte array instead of OVERLAPPED struct like WaitForXfer...
public unsafe bool BeginDataXfer(ref byte[] singleXfer, ref byte[] buffer, ref int len, ref OVERLAPPED ov)
{
fixed(OVERLAPPED* pov = &ov)
{
byte[] barray = new byte[sizeof(OVERLAPPED)];
Marshal.Copy((IntPtr)pov, barray,0,sizeof(OVERLAPPED));
return BeginDataXfer(ref singleXfer, ref buffer, ref len, ref barray);
}
}
public unsafe bool FinishDataXfer(ref byte[] singleXfer, ref byte[] buffer, ref int len, ref OVERLAPPED ov)
{
fixed (OVERLAPPED* pov = &ov)
{
byte[] barray = new byte[sizeof(OVERLAPPED)];
Marshal.Copy((IntPtr)pov, barray, 0, sizeof(OVERLAPPED));
return FinishDataXfer(ref singleXfer, ref buffer, ref len, ref barray);
}
}
Please give me feedback ...
Solved! Go to Solution.
- Tags:
- overlapped
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Yes you can implement it in this way but I am not able to see any benefit of doing it. Could you please elaborate on it.
One potential problem I can identify is that you are pinning the memory but as soon as the function call returns, the memory will be unpinned and the reference looses.
Thanks & Regards
Abhinav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Yes you can implement it in this way but I am not able to see any benefit of doing it. Could you please elaborate on it.
One potential problem I can identify is that you are pinning the memory but as soon as the function call returns, the memory will be unpinned and the reference looses.
Thanks & Regards
Abhinav