Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

ActiveX cwdsp control in c#

I'm trying to generate a squarewave signal with the cwdsp control in a c# application. The signature for the SquareWave method requires five object parameters that set number of samples, amplitude, frequency, duty cycle, and phase. I keep getting a Type Mismatch exception. I've tried passing in objects, int, int32. Does anyone know what I need to pass in?

Also, is there a better way other than trial and error to try and figure out what needs to be passed into an NI ActiveX control that is being used in c#? Better yet, when is Measurement Studio .net going to be released?

Thanks,
Philip
0 Kudos
Message 1 of 4
(4,386 Views)
The first parameter (number of samples) should be an int, the next three parameters (amplitude, frequency, and duty cycle) should be doubles, and the last parameter (phase), which is passed by reference, should be an object. The method returns an array of doubles and you should be able to safely cast it to a double array.

There really isn't an easy way to figure out which .NET data types can be passed to the interop assemblies for the ActiveX controls. You can sometimes get some clues by reading the documentation for the ActiveX controls, look at some examples to see what data types they're using, and look at the Measurement Studio C++ interfaces since they're more strongly-typed.

Regarding Measurement Studio libraries for .NET, the newest version of Mea
surement Studio, which includes the .NET libraries, is orderable now.

- Elton
0 Kudos
Message 2 of 4
(4,386 Views)
I tried passing an int, double, double, double, ref object and still get a type mismatch. Here is my code.

double[] jj;
int samples = 1000;
double amp, freq, percent;
freq = 1;
amp = 1;
percent = 100;
object phase = new Object();
phase = 0;
jj = (double[]) cwdsp.SquareWave(samples, amp, freq, percent, ref phase);

I get a type mismatch regardless of whether or not I initialize phase (i.e., phase = 0). Here is the stack trace.

Type mismatch.
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at CWAnalysisControlsLib._DCWDSP.SquareWave(Object n, Object Amp, Object f, Object DutyCycle, Object&
Phase)
at AxCWAnalysisControlsLib.AxCWDSP.SquareWave(Object n, Object amp, Object f, Object dutyCycle, Object& phase)
at MotorTest.BearingForm.generateAnalogOutput(Boolean status) in c:\projects\p39\base_gantry\motortest\bearingform.cs:line 764

Any thoughts, thanks.
Philip

I'm ordering Studio 7.0 as soon as I can get the approval!!
0 Kudos
Message 3 of 4
(4,386 Views)
I tried your code and I also saw the same problem. I changed phase to be initialized to null instead of 0 and the problem no longer reproduced. Please give that a try and see if that fixes your problem.

When you get Measurement Studio 7.0, check out the classes in the NationalInstruments.Analysis.SignalGeneration namespace, specifically the SquareSignal class. This code becomes a lot easier and more intuitive with the new .NET classes:

SquareSignal signal = new SquareSignal();
double[] data = signal.Generate(1.0, 1000);

- Elton
0 Kudos
Message 4 of 4
(4,386 Views)