Why don't add BeginDataXfer(ref byte[] singleXfer, ref byte[] buffer, ref int len, ref OVERLAPPED ov) overload in CyUSB.dll ?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
MaFa_974161
Level 5
Level 5
100 sign-ins 50 replies posted 50 questions asked

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 ...

0 Likes
1 Solution
abhinavg_21
Moderator
Moderator
Moderator
50 likes received 25 likes received 10 likes received

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

View solution in original post

0 Likes
1 Reply
abhinavg_21
Moderator
Moderator
Moderator
50 likes received 25 likes received 10 likes received

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

0 Likes