Forums › TG Series Discussions › Error When Opening a Device (TG124A).
- This topic has 2 replies, 2 voices, and was last updated 6 years, 9 months ago by
Nazar.
- AuthorPosts
NazarParticipantI 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?
AndrewModerator- This reply was modified 6 years, 9 months ago by
Andrew.
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
NazarParticipantHello 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- This reply was modified 6 years, 9 months ago by
- AuthorPosts
You must be logged in to reply to this topic.