2205A C# ps2000_set_sig_gen_built_in() not working

Post your .Net discussions here
Post Reply
wengao
Newbie
Posts: 0
Joined: Thu May 12, 2016 5:45 pm

2205A C# ps2000_set_sig_gen_built_in() not working

Post by wengao » Thu May 12, 2016 6:17 pm

I have trouble to implement this API in VS2012 C#. I always got "pinvokestackimbalance was detected" message.

Here is the code

Code: Select all

 [DllImport(_DRIVER_FILENAME, EntryPoint = "ps2000_set_sig_gen_built_in")]    
        public static extern short ps2000_set_sig_gen_built_in(
                                                                short handle,
                                                                long offsetVoltage,
                                                                uint pkToPk,
                                                                WaveType waveType,
                                                                float startFrequency,
                                                                float stopFrequency,
                                                                float increment,
                                                                float dwellTime,
                                                                SweepType sweepType,
                                                                uint sweeps);

Code: Select all

 private void tsbtnSignalG_Click(object sender, EventArgs e)
        {        
            long offsetVoltage = 0;
            uint pkToPk = 1000000;
            float startFrequency = 1000;
            float stopFrequency = 1000;
            float increment = 0;
            float dwellTime = 0;     
            uint sweeps = 0;
            
            short rcode = Imports.ps2000_set_sig_gen_built_in(_handle,
                                                            offsetVoltage,
                                                            pkToPk,
                                                            Imports.WaveType.SINE, //WaveType waveType,
                                                            startFrequency,
                                                            stopFrequency,
                                                            increment,
                                                            dwellTime,
                                                            Imports.SweepType.UPDOWN, //SweepType sweepType,
                                                            sweeps);
            Console.WriteLine("rcode: " + rcode.ToString());
        }
The function always returns 0. Can anyone help me? Thanks

Wengao
Attachments
snapshot.png
screen shot

Martyn
Site Admin
Site Admin
Posts: 3376
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: 2205A C# ps2000_set_sig_gen_built_in() not working

Post by Martyn » Fri May 13, 2016 6:34 am

I believe offset_voltage should be an int not a long

Code: Select all

[DllImport(_DRIVER_FILENAME, EntryPoint = "ps2000_set_sig_gen_built_in")]    
        public static extern short ps2000_set_sig_gen_built_in(
                                                                short handle,
                                                                int offsetVoltage,
                                                                uint pkToPk,
                                                                WaveType waveType,
                                                                float startFrequency,
                                                                float stopFrequency,
                                                                float increment,
                                                                float dwellTime,
                                                                SweepType sweepType,
                                                                uint sweeps);
Martyn
Technical Support Manager

wengao
Newbie
Posts: 0
Joined: Thu May 12, 2016 5:45 pm

Re: 2205A C# ps2000_set_sig_gen_built_in() not working

Post by wengao » Fri May 13, 2016 1:54 pm

Thanks Martyn, It's working now.

Post Reply