UsbAdc11SetInterval...... problems and UsbAdc11GetTimesAndV

Post your .Net discussions here
Post Reply
Seyi
Newbie
Posts: 1
Joined: Wed Sep 23, 2009 2:17 pm
Location: nigeria
Contact:

UsbAdc11SetInterval...... problems and UsbAdc11GetTimesAndV

Post by Seyi »

Thanks so far to all the programmers in the house, most expecially Mr. Mark I tried all he gave me and they worked excellently well. I have a few questions to ask programmatically.
1)
using System.Runtime.InteropServices;
...
DllImport("usbadc11.dll")]
public static extern uint UsbAdc11GetValue(short handle, int channel, uint value);
...
short a =(short) UsbAdc11MaxValue();
uint value = 0;
UsbAdc11GetValue(a, 5,value );

richTextBox1.Text = value.ToString();

do you think I aways have to use the out keyword just like the way it was done to the declaration bellow when I'm expecting any value from my logger card? i got 62062593 which i felt it is not correct because when i divided by maximum count and multiply by 25000(mv) it did not give me a required voltage.


[DllImport("usbadc11.dll")]
public static extern BOOL UsbAdc11MaxValue(short handle, out ushort max);

2)


[DllImport("usbadc11.dll")]
public static extern long UsbAdc11SetInterval(short handle, long us_for_block,long halfburffer, short channels, short no_of_channel);

[DllImport("usbadc11.dll")]
public static extern ulong UsbAdc11GetTimesAndValues (short handle, long[] times,ushort[] values,long no_of_values);

[DllImport("usbadc11.dll")]
public static extern short UsbAdc11Run(short handle, long no_of_values,short method);
int i;
long actual;
short[] channels ={ 1, 3 };
short no_of_channels = 2;

Console.WriteLine("Collect block immediate....\n");
Console.WriteLine(" press any key to start\n");
Console.ReadLine();

short opened = UsbAdc11OpenUnit();
g_handle = opened;
// trigger dis disabled
UsbAdc11SetTrigger(g_handle, FALE, FALE, 0, 1, FALE, 0, 0);
//actual is E-10^6
actual = UsbAdc11SetInterval(g_handle, 100000, 500000, channels[0], 1);

// double no_of_sample = BUFFER_SIZE * 5000 / actual;

UsbAdc11Run(g_handle, BUFFER_SIZE, 1);


while (UsbAdc11Ready(g_handle) == 0)
{
AutoResetEvent autoEvent = new AutoResetEvent(false);
// autoEvent.WaitOne();
autoEvent.WaitOne(5000, false);

}



UsbAdc11GetTimesAndValues(opened, times , values, BUFFER_SIZE);

Console.WriteLine("\n ALL THE READINGS\n");
Console.WriteLine("\n(us)\tTimevalues\t");

foreach (int t in values)
{
Console.WriteLine("\n{0}}", times.Length);
}

its not giving me any value, it complains about the parameter signature ,sometimes about the memory corrupt value cannot be read a soon.
how can i go about this three function in short. any other way out please.
1) UsbAdc11Run
2) UsbAdc11GetTimesAndValues
3)UsbAdc11SetInterval
and if i still need to know UsbAdc11SetTrigger thanks
programming

markB
Site Admin
Site Admin
Posts: 83
Joined: Tue Mar 27, 2007 9:43 am
Location: Cambridgeshire,UK

Re: UsbAdc11SetInterval...... problems and UsbAdc11GetTimesAndV

Post by markB »

1) Yes. You would definetley use the out keyword.

2) The error about the parameter signature being incorrect would suggest a problems with your declarations. I've only taken a quick look but it looks like you have used longs where you should have used ints (a managed long is 64s bit whereas a native long is 32 bits).

The MSDN is a useful place to look when having problems marshalling native dlls. A good place to start is here: http://msdn.microsoft.com/en-us/library/ms235282.aspx
Regards

Mark

Post Reply