Developing in C# .Net .dll problems

Post general discussions on using our drivers to write your own software here
Post Reply
rasmuselkjaer
Newbie
Posts: 1
Joined: Wed Jan 26, 2005 9:00 am

Developing in C# .Net .dll problems

Post by rasmuselkjaer »

Hi

I’m trying to make a wrapper class for adc11(12bit) for C#.NET, but when marshalling between the ADC1132.dll and .NET I run into problems regarding passing c-array by reference.

The following code is what I have come up with so fare but not working proper. When using setinterval followed by gettimesandvalues I get no errors but the returned values are only from channel 1, no matter which values I pass as parameters with setinterval.

Code: Select all

using System;
using System.Runtime.InteropServices;

namespace ADC11Communication { 
	public class ADC11Functions{
		[DllImport("ADC1132.dll", SetLastError=true)]
		public static extern ulong adc11_set_interval(ulong us_for_block, ulong ideal_no_of_samples, [MarshalAs(UnmanagedType.LPArray)] short[] channels, short no_of_channels);
		[DllImport("ADC1132.dll", SetLastError=true)]
		public static extern ulong adc11_get_times_and_values([MarshalAs(UnmanagedType.LPArray)] long[] times, [MarshalAs(UnmanagedType.LPArray)] ushort[] values, ulong no_of_values);
	}
}
if anyone got any experience with this or any ideas at all please reply ;-)

or is there a way to take a vb.net module and convert it to C#.net ? (saw the post about supporting vb.net)

many thx in advance

Rasmus

Sarah

Post by Sarah »

Hi

Thank you for your post.

When the adc11_get_times_and_values is called the following pre-requisite function call have to be made:

1. 2 channels active eg 1 and 3 (set by calling adc11_set_interval).
2. 1000 samples requested by calling adc11_run
3. adc11_ready has returned true to indicate that all the readings have been taken.
4. The array size passed for the channels has to be 2000 as 1000 samples will be taken for each channel. The values are interweved channel 1 and then channels 3.

eg. position 0: Channel 1
position 1: Channel 3
position 2: Channel 1
position 3: Channel 3
.
.
.
position 1998: Channel 1
position 1999: Channel 3

Therefore additional calls have to be included in the DLLimport. I would recommend that you look at the adc11con.c example, all the function call as used in this example.

Hope this helps

Best Regards

Post Reply