SuiteUSB using .NET API for PassMark USB 3.0 plug

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

cross mob
MaSy_4695346
Level 2
Level 2
10 sign-ins 10 replies posted 5 replies posted

Dear all,

My company has purchased a few PassMark USB 3.0 Loopback plugs.

The company has an API for C++ for using this plug, but since we mostly develop in C# I asked them if they supplied their API for .NET which they don't.

However their hardware uses Cypress hardware (they link to Cypress EZ-USB FX3 SDK) so I thought of using the Cypress SDK in conjunction with SuiteUSB 3.4.

So far I've managed to establish a connection and send data back and forth, using SuiteUSB 3.4, over USB and this works fine.

However, there are a few vendor specific (PassMark) commands that I would like to send to the plug.

I've looked into how this is done in PassMarks C++ console implementation and it works fine.

My idea is to mimic this behaviour using SuiteUSB3.4.

For instance they perform

double Voltage = 0;

SendVendorCommand(CurUSBDevice, VENDOR_REQ_READ, GET_VOLTAGE, (UCHAR*)&Voltage, sizeof(Voltage));

bool SendVendorCommand(CCyUSBDevice *USBDevice, USB30_VENDOR RequestType, WORD wValue, UCHAR *buf, LONG buflen)

{

CCyControlEndPoint *ept;

if (USBDevice->IsOpen() == false)

return false;

ept = USBDevice->ControlEndPt;

ept->Target = TGT_DEVICE;

ept->ReqType = REQ_VENDOR;

ept->ReqCode = 0x00;

ept->Value = wValue;

ept->Index = 0;

if (RequestType == VENDOR_REQ_READ)

ept->Read(buf, buflen);

else

ept->Write(buf, buflen);

return true;

}

which is fairly straight forward for reading the voltage for the device.

I want to perform the same in C#

ReadVendorCommand(device, GET_VOLTAGE, sizeof(double));

        private byte[] ReadVendorCommand(CyUSBDevice device, ushort wValue, int lengthToRead)

        {

            var controlEndPoint = device.ControlEndPt;

            controlEndPoint.Target = TGT_DEVICE;

            controlEndPoint.ReqType = REQ_VENDOR;

            controlEndPoint.ReqCode = 0x00;

            controlEndPoint.Value = wValue;

            controlEndPoint.Index = 0;

            controlEndPoint.Direction = 1;

            byte[] data = new byte[lengthToRead];

            var result = controlEndPoint.Read(ref data, ref lengthToRead);

            if (result) return data;

            return null;

        }

However, the data returned is all zeros (8 of them to be exact) and the lengthToRead (which was 8 when calling controlEndPoint.Read) is now only two bytes.

I've checked and the data and all patterns up to the call seem exactly the same as in the C++ code.

Since SuiteUSB 3.4 has not been updated for some quite some time (9 years) I was wondering if anyone else has any leads or tip that could point me in the right direction to resolve the issue.

Thanks a lot in advance,

Magnus Sydoff

0 Likes
1 Solution

Hello,

Looks like there is a problem setting the configuration or in passing the arguments.

Please use the code below without changing inside your function:

var controlEndPoint = device.ControlEndPt;

CyControlEndPoint ctrlEpt = controlEndPoint as CyControlEndPoint;

if (ctrlEpt is null) throw new Exception("Endpoint is not available");

else

{

ctrlEpt .Direction = CyConst.DIR_FROM_DEVICE;

ctrlEpt .Target = CyConst.TGT_DEVICE;

ctrlEpt .ReqType = CyConst.REQ_VENDOR;

ctrlEpt .ReqCode = 0x00;

ctrlEpt .Value = 0x0007;

ctrlEpt .Index = 0;

ctrlEpt .TimeOut = 3000;

int len = 8;

byte[] data = new byte[len];

bool result = controlEndPoint.XferData(ref data, ref len );

if (result)

return data;

return null;

}

Please let me know if this works, and the value returned by the XferData function.

Thanks,

Yatheesh

View solution in original post

13 Replies