The brand-new PN400 Phase Noise Test System is available for purchase! →

Error When Opening a Device (TG124A).

Forums › TG Series Discussions › Error When Opening a Device (TG124A).

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #159244
    Nazar
    Participant

    I wrote a short program(In c#) that uses the tg_api.dll to control the signal generator. I used the simple example provided by the SDK as a reference, but when invoking

    tgOpenDevice(device)

    I get a ‘-3’ error, which corresponds to tgDeviceInvalidErr

    I am using ‘0’ as the device value. Is this correct? All the drivers are installed and i can run the signal generator from the Spike GUI.

    Is there any more information about what can cause the error?

    #159245
    AndrewAndrew
    Moderator

    Hello Nazar,

    I’m looking at this function right now and there is only one location where this error value (-3) can be returned. The code for this is below.

    if(device < 0 || device >= TG_MAX_DEVICES) {
    return tgDeviceInvalidErr;
    }

    where TG_MAX_DEVICES = 4.

    So if the device integer provided is less than 0 or greater then 3 then this error (-3) is returned. I would look into the interop between your C# application and this function. This integer argument is not being passed properly. You are using DllImport and setting the calling convention to Cdecl?

    Regards,
    Andrew

    • This reply was modified 8 years, 3 months ago by AndrewAndrew.
    #159247
    Nazar
    Participant

    Hello Andrew

    With your information, i was able to fix the problem. I used the bb_api as a guide, so assumed the device id had to be a reference, which was the problem.

    Bad:

    [DllImport(“tg_api.dll”, CallingConvention = CallingConvention.Cdecl)]
    public static extern tgStatus tgOpenDevice(ref int device);

    Good:

    [DllImport(“tg_api.dll”, CallingConvention = CallingConvention.Cdecl)]
    public static extern tgStatus tgOpenDevice(int device);

    Thank you very much
    Nazar

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.