Announcement

Collapse
No announcement yet.

USB2 Test Plug API - C# Problem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • USB2 Test Plug API - C# Problem

    Hi Board,

    I've a little problem with the USB2 test plug SDK. I have 3 plugs connected to my test system, USB2NumPlugsConnected() detects all 3 and USB2GgetDeviceInfo() returns the correct serial numbers.

    I use USB2GetConnectedPlugs() to get the connected plugs for testing, but when I have a look inside the returned bool array, I can see that only the first [0] ist set to true. When I call USB2StartTest() only the first plug is tested.
    If I set [1] and [2] also to true, no plug were tested.

    Somebody an Idea what's wrong? Maybe my invoke deklaration?

    Thanks!

    PHP Code:
    [DllImport("USB2DLL.dll"EntryPoint "USB2SetTestParameters")]
    public static 
    extern bool USB2SetTestParameters([InBoolean[] useplugint modeuint durationDATA_PATTERN dataPatternulong patternStartbool verifyData); 
    PHP Code:
    bool[] bUSBDevs = new bool[Libs.PCTestLibUSB2Plug.MAX_USB_DEV_NUMBER];

    if (!
    Libs.PCTestLibUSB2Plug.USB2GetConnectedPlugs(bUSBDevs))
    {
        ...
    }
    else
    {
        
    Libs.PCTestLibUSB2Plug.USB2SetTestParameters(bUSBDevsLibs.PCTestLibUSB2Plug.LOOPBACK60Libs.PCTestLibUSB2Plug.DATA_PATTERN.CONSTANTBYTE0true);
        
    Libs.PCTestLibUSB2Plug.USB2StartTest();

        ... 

  • #2
    Some changes need to be made to adapt the DLL for use with C#, as arrays of some types (like bool) are passed differently than in C++. By changing the array to a byte array and making the same changes in the declaration to byte[] the function should return the correct data.

    For example;
    Code:
    [DllImport("USB2DLL.dll")]
     static extern bool USB2SetTestParameters([In] byte[] useplug, int mode, uint duration, DATA_PATTERN dataPattern, ulong patternStart, bool verifyData);
          
     [DllImport("USB2DLL.dll")]
     static extern bool USB2GetConnectedPlugs([Out] byte[] bDeviceArray);
    Code:
    byte[] bUSBDevs = new byte[MAX_USB_DEV_NUMBER];
    USB2GetConnectedPlugs(bUSBDevs);
    USB2SetTestParameters(bUSBDevs, LOOPBACK, 60, DATA_PATTERN.CONSTANTBYTE, 0, true);

    Comment


    • #3
      Thanks a lot TimR, byte[] works fine!

      Comment


      • #4
        Hello,

        I am experiencing a similar issue with the USB2.0 API and C#. I have written a suitable C# wrapper for the API library and I am successfully getting a number of the functions to work with no problem. However, having created a suitable hardware arrangement to trigger bus errors (using the C++ demo code as a reference) my calls to USB2GetBusErros is always returning zero count via the integer return value.

        When run with the demo program it consistently returns an increasing error count as the timer cycles during Loopback testing. I have adapted my wrapper code to many variations. With and without marshalling on both return value and input argument. Other functions in the library that return an integer are working including USB2GetDeviceInfo. I have tried duplicating the wrapper syntax for this function and still no success with the call to USB2GetBusErrors.

        The code below is current WIP but as I said I have tried with and without marshalling and even with and without calling convention defined.

        Code:
        [FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] 
        [/SIZE][/FONT][DllImport("USB2Dll.dll"/*, CallingConvention = CallingConvention.Cdecl*/)]
        
        [return: MarshalAs(UnmanagedType.I4)]
              
        
        internal static extern int USB2GetBusErrors([In] [MarshalAs(UnmanagedType.I4)] int iDeviceNum);
        
        [/SIZE][/FONT]
        This is the context in which I'm using the function


        Code:
         private int _totalBUSErrors = 0;
         private int _totalOperations = 0;
         private int _totalErrors = 0;
        [FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]while (PMUSB2.USB2TestIsRunning())
                    {
                        if (PMUSB2.USB2GetLoopbackResults(operations, errors))
                        {
                            _totalOperations = operations[instance._id];
                            _totalErrors = errors[instance._id];
                            _totalBUSErrors = PMUSB2.USB2GetBusErrors(instance._id);
                        }
                     }
        [/COLOR][/SIZE][/FONT] 
        [/COLOR][/SIZE][/FONT] 
        [/COLOR][/SIZE][/FONT]
        I'm running out of ideas of places to look. Any suggestions you might have would be welcomed.

        Many Thanks.

        Comment

        Working...
        X