Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with Wrapper for .NET

Hello.

I've got a problem. U'm using the niRFSA 5661 and want to programm in C#. Threfor i installed the National Instrument Driver and wrapper for modular instruments, the trial verison because have no license.
But there is a problem:

The created wrapper works for the most part, however, some types remain unconverted, since the declaration is obviously missing in the driver dll. The wrapper correctly states the types however in the first lines of the c-sharp code file:

// TODO: Function Panel type with id: 1016 and name: "nicomplexnumber" could not be resolved; Type will be treated as System.Int32.

// TODO: Function Panel type with id: 1013 and name: "nirfsa_wfminfo" could not be resolved; Type will be treated as System.Int32.

// TODO: Function Panel type with id: 1014 and name: "nirfsa_spectruminfo" could not be resolved; Type will be treated as System.Int32.

// TODO: Function Panel type with id: 1015 and name: "viint64" could not be resolved; Type will be treated as System.Int32.

// TODO: Function Panel type with id: 1018 and name: "smtspectruminfo" could not be resolved; Type will be treated as System.Int32.

I want to make an IQ Acquisition and therefor i need the "nicomplexnumber" but as seen above the type remain unconverted.

So i rebuilt the structure in C#

[StructLayout(LayoutKind.Sequential)]
        public struct NIComplexNumber_struct
        {
          double real;
          double imaginary;
        }

But it doesn't works. The message is that he can not read/write to corrupted memory. I understand what the problem is. The complex numbers are addicted by the number of samples.So it must be an array which is flexible.

Does anybody know how to solve the problem??
Thanks
Christian
0 Kudos
Message 1 of 12
(7,160 Views)

I checked the header of the LabWindows/CVI driver(which is the basis fore the wrapper), and the struct is defined like this:

typedef struct NIComplexNumber_struct {
   ViReal64 real;
   ViReal64 imaginary;
} NIComplexNumber;

 

As ViReal64 is a double in C#, this should fit to your declaration.

In an CVI I/Q example, it is used like this:

NIComplexNumber* dataPtr = NULL;

dataPtr = malloc (sizeof (ViReal64) * 2 * samplesPerBlock);    //dynamically set the arrysize

niRFSA_FetchIQSingleRecordComplexF64 (
         session,          /* session  */
         "0",              /* channel list */
         0,                /* record number */
         samplesPerBlock,
         10.0,             /* timeout */
         dataPtr,
         &wfmInfo));

 

I hope this helps!

0 Kudos
Message 2 of 12
(7,089 Views)
Hi Andre_Saller,

I have already seen this example. I use the ReadIQSingleRecordComplexF64 function and there is the struct nearly the same as in your described function
After i defined a new struct with the same layout as in the headerfile , 1st post of me, i created an instance of this struct:

NIComplexNumber_struct[] _new_instance = new NIComplexNumber_struct[numberofsamples]

I thougt this would solve the problem but when i try to make an acquisition the for example with 512 samples, the fields are empty.
See picture in Attechement.

I don't know why this happens. The only reason that i can imagine is that the it has something to do with the structure of the niComplexnumber_struct.
Do you have an idea what the reason can be or know a solution for the problem??

thanks Christian


Message Edited by crueger on 06-26-2008 05:36 AM
0 Kudos
Message 3 of 12
(7,086 Views)
Could you post the code with which you configure your RFSA and acquire the data?
 
0 Kudos
Message 4 of 12
(7,009 Views)
Yes no problem.

static string namestr = "DownConverter5600_0\0";    // init rfsa
        niRFSA nirfsa = new niRFSA(namestr, true, false);

        TextWriter tw = new StreamWriter(@"C:\data.txt", false, Encoding.ASCII);
        niRFSA_wfmInfo wfmInfo = new niRFSA_wfmInfo();     
      
        public void configure_read()       // Method to configure rfsa and read data
        {
            nirfsa.ConfigureAcquisitionType(Iq);
            int RefClock = nirfsa.ConfigureRefClock(OnboardClockStr, 10e6);
            int RefLevel = nirfsa.ConfigureReferenceLevel("", 0);
            int CarrFreq = nirfsa.ConfigureIQCarrierFrequency("", 100e6);
            int IQrate = nirfsa.ConfigureIQRate("", 1e6);
            int nmbOfsampl = nirfsa.ConfigureNumberOfSamples("", true, 512);

            NiComplexnumber_struct[] _new_struct = new NiComplexnumber_struct[512];
            nirfsa.ReadIQSingleRecordComplexF64("", 10.0, _new_struct, _new_struct.length, ref wfmInfo);

            for (int i = 1; i < _new_struct.Length; i++)
            {
                tw.writeLine(_new_struct[i].real);
                tw.writeLine(_new_struct[i].imaginary);
            }
        }

The " niRFSA_wfmInfo wfmInfo = new niRFSA_wfmInfo(); " is also a rebuild of the stuct in the headerfile and this struct works but not the struct for the complex numbers.

0 Kudos
Message 5 of 12
(7,003 Views)
EDIT to my post above:

 I think to understand this you maybe need the parts of the wrapper class:

[DllImport("niRFSA.dll", EntryPoint = "niRFSA_ReadIQSingleRecordComplexF64", CallingConvention = CallingConvention.StdCall)]
public static extern int ReadIQSingleRecordComplexF64(System.IntPtr Instrument_Handle, string Channel_List, double Timeout, out int Data, int Data_Array_Size, out int Waveform_Info);

this part i changed  in :

[DllImport("niRFSA.dll", EntryPoint = "niRFSA_ReadIQSingleRecordComplexF64", CallingConvention = CallingConvention.StdCall)]
public static extern int ReadIQSingleRecordComplexF64(System.IntPtr Instrument_Handle, string Channel_List, double Timeout, measurev2.fetch_data.NiComplexnumber_struct Data, int Data_Array_Size, ref Waveform_Info);

The reference to Waveform_Info is right and works so i think the problem is the measurev2.fetch_data.Nicomplexnumer_struct Data, but i don´t know where.
The Program also returns no error message only the fields for imaginary and real part are empty, as i already said



Message Edited by crueger on 06-26-2008 07:03 PM
0 Kudos
Message 6 of 12
(6,995 Views)
Hello.

After some days of trying i solved the problem.

solution:

[DllImport("niRFSA.dll", EntryPoint = "niRFSA_ReadIQSingleRecordComplexF64", CallingConvention = CallingConvention.StdCall)]
public static extern int ReadIQSingleRecordComplexF64(System.IntPtr Instrument_Handle, string Channel_List, double Timeout, [In,Out] measurev2.read_IQ_data.NIComplexNumber_struct[] Data, int Data_Array_Size, ref measurev2.read_IQ_data.niRFSA_wfmInfo_struct Waveform_Info);

Now it works perfectly.


Message Edited by crueger on 06-27-2008 01:07 PM
0 Kudos
Message 7 of 12
(6,919 Views)
Where did you get the NIRFSA wrapper in the first place? I am working on using PXI-5661 with C#.
0 Kudos
Message 8 of 12
(6,525 Views)

I downloaded the Measurement Studio 8.5 for Visual Studio 2005 Evaluation Kit. After installing you have the opportunity in Visual Studio to create a .NET Wrapper for National Instrument Drivers. Have a look at the 2 links below: 

 

http://digital.ni.com/public.nsf/allkb/27177DA13C6ED0AE86257362006A68B0

 

http://digital.ni.com/public.nsf/websearch/52D289F65941474A86256E8A0057D72E?OpenDocument 

 

But i can say that this tool isn't working so well. Some of the functions and methods could not be "wrapped" into C#, so you have to manipulate the wrapper a little bit. 

The parts which could not be "wrapped" you can see first Post.  I have manipulated the "wrapped" (Post 7) file so that it now works fine.

 

Message Edited by crueger on 10-07-2008 08:47 AM
Message Edited by crueger on 10-07-2008 08:48 AM
0 Kudos
Message 9 of 12
(6,518 Views)

Hi,

 

National Instruments provides .NET wrappers, both in C# and VB, for most of the Modular Instruments drivers in the KB 3939UN5B on ni.com. Currently it includes.NET wrappers generated against the 2.1 version of the NI-RFSA driver. The zip file containing the niRFSA wrapper also contains a couple of simple C# and VB examples that show how to use them.

 

If the driver version that you are using is lower than the one that the wrappers are generated, you can still utilize these wrappers as long as you make sure that you do not call into the entry points that are not present in the version of the driver that you are using but are present in the wrapper.

 

Feel free to use the Product Suggestion Center, if you do not find wrapper for a particular driver or if the one generated by the .NET Instrument Driver Wizard of Measurement Studio does not work as expected.

-Mahesh
National Instruments
0 Kudos
Message 10 of 12
(6,135 Views)