PicoScope 7 Software
Available on Windows, Mac and Linux
Code: Select all
[DllImport("adc1132.dll", SetLastError = true)]
public static extern bool adc11_open_unit(short port, short product);
[DllImport("adc1132.dll", SetLastError = true)]
public static extern int adc11_get_unit_info(StringBuilder str, short str_lth, short line, short port);
[DllImport("adc1132.dll", SetLastError = true)]
public static extern void adc11_close_unit(short port);
[DllImport("adc1132.dll", SetLastError = true)]
public static extern int adc11_get_value(short channel);
[DllImport("adc1132.dll", SetLastError = true)]
public static extern int adc11_get_driver_version();
[DllImport("adc1132.dll", SetLastError = true)]
public static extern ulong adc11_get_values(ushort[] values, uint no_of_values);
Code: Select all
StringBuilder info = new StringBuilder(256);
try
{
if (usbbaglanti.usbcom.adc11_open_unit(101, 111))
{
MessageBox.Show("The unit opened successfully");
for (short a = 0; a < 4; a++)
{
if (usbbaglanti.usbcom.adc11_get_unit_info(info, (short) info.Length, a, 101) > 0)
MessageBox.Show(info.ToString());
}
}
else
{
MessageBox.Show("The unit couldn't opened..");
if (usbbaglanti.usbcom.adc11_get_unit_info(info, (short) info.Length, 0, 101) > 0)
MessageBox.Show(info.ToString());
}
}
catch (Exception ee)
{
MessageBox.Show(ee.Message.ToString());
}
You therefore need to define and use the function as follows:You need to be careful with your native and managed types. ints and shorts are different sizes and so you cant simply interchange them.
.
.
You dont need to use attribute to override the default marshalling unless you are going to something out of the ordinary.
Code: Select all
[DllImport("adc1132.dll")]
public static extern uint adc11_set_interval(uint us_for_block, uint ideal_no_of_samples, short[] channels, short no_of_channels);
uint BUFFER_SIZE = 1000;
short[] channels = { 1, 3 };
uint actual = usbbaglanti.usbcom.adc11_set_interval(100000, BUFFER_SIZE, channels, (short) channels.Length);