From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

Using HWC_FetchSampleErrors with C#

Solved!
Go to solution

I am using a C# wrapper to call the methods from niHSDIO.dll.  I am having trouble with the HWC_FetchSampleErrors method, in particular the Reserved1 and Reserved2 parameters.

The C# wrapper calls this method as follows:
public int HWC_FetchSampleErrors(int Sample_Errors_to_Read, int Max_Time_Milliseconds, out int Number_Of_Samples_Error_Read, double[] Error_Sample_Numbers, uint[] Error_Bits, uint[] Error_Repeat_Counts, out uint Reserved_1, out uint Reserved_2)
        {
            int pInvokeResult = PInvoke.HWC_FetchSampleErrors(this._handle, Sample_Errors_to_Read, Max_Time_Milliseconds, out Number_Of_Samples_Error_Read, Error_Sample_Numbers, Error_Bits, Error_Repeat_Counts, out Reserved_1, out Reserved_2);
            PInvoke.TestForError(this._handle, pInvokeResult);
            return pInvokeResult;
        }
[DllImport("niHSDIO.dll", EntryPoint = "niHSDIO_HWC_FetchSampleErrors", CallingConvention = CallingConvention.StdCall)]
            public static extern int HWC_FetchSampleErrors(System.IntPtr Instrument_Handle, int Sample_Errors_to_Read, int Max_Time_Milliseconds, out int Number_Of_Samples_Error_Read, [In, Out] double[] Error_Sample_Numbers, [In, Out] uint[] Error_Bits, [In, Out] uint[] Error_Repeat_Counts, out uint Reserved_1, out uint Reserved_2);
According to this thread
I should pass the Reserved1 and Reserved2 parameters as "NULL".  The problem I am having in C# is that parameters of type uint are not nullable in C#.  I have tried a number of workarounds, including trying to create overloads of the above methods and with Reserved1 and Reserved2 declared as type UIntPtr and passing in UInPtr.Zero.  I am still not having any luck.
Any suggestions on how to get this code to work in C# ??

 

0 Kudos
Message 1 of 3
(3,259 Views)

Hey syndiant,

 

What other kinds of workarounds have you tried? And when you say it does not work, does that mean that the code is not building for you? One thing you can try is to pass 0 into those parameters in the function call in your code, without making any changes to the wrapper, for example ....., 0, 0). If this doesn't work, there might be some other things we can do. Let me know how the 0 value works for you. Thanks, and have a great weekend.

 

Regards,

DJ L.

0 Kudos
Message 2 of 3
(3,247 Views)
Solution
Accepted by topic author davidqk

Here is my solution.  You have to change the Reserved1 and Reserved2 parameters to type uint[] instead of uint.  Then you can pass null.

 

Declare them in your program as such.

uint[] res1 = null;
uint[] res2 = null;

 

 

 

Change the method in the C# wrapper:

 

public int HWC_FetchSampleErrors(int Sample_Errors_to_Read, int Max_Time_Milliseconds, out int Number_Of_Samples_Error_Read, double[] Error_Sample_Numbers, uint[] Error_Bits, uint[] Error_Repeat_Counts, uint[] Reserved_1, uint[] Reserved_2)
        {
            int pInvokeResult = PInvoke.HWC_FetchSampleErrors(this._handle, Sample_Errors_to_Read, Max_Time_Milliseconds, out Number_Of_Samples_Error_Read, Error_Sample_Numbers, Error_Bits, Error_Repeat_Counts, Reserved_1, Reserved_2);
            PInvoke.TestForError(this._handle, pInvokeResult);
            return pInvokeResult;
        }

0 Kudos
Message 3 of 3
(3,098 Views)