I have tried declaring a struct like so:
Code: Select all
public struct usbtc08Info
{
public short size;
public char[] DriverVersion;
public short PicoppVersion;
public short HardwareVersion;
public short Variant;
public char[] szSerial;
public char[] szCalDate;
}
ive tried passing char arrays and string across to info2 by val and as ref and the closed ive got is getting the first letter of the serial no by passing a char array,
ive even tried the get formatted info but i keep getting too many bits to copy error and every time i put a value in above 255 the application dies.
a short snippit of the code that is important
Code: Select all
[DllImport("usbtc08.dll")]
public static extern short usb_tc08_open_unit();
[DllImport("usbtc08.dll")]
public static extern int usb_tc08_close_unit(short handle);
[DllImport("usbtc08.dll")]
public static extern int usb_tc08_set_channel(short handle, int channel, byte tc_type);
[DllImport("usbtc08.dll")]
public static extern int usb_tc08_set_mains(short handle, int sixty_herts);
[DllImport("usbtc08.dll")]
public static extern long usb_tc08_get_single(short handle, ref Single temp, ref int overflow, int units);
[DllImport("usbtc08.dll")]
public static extern int usb_tc08_get_last_error(short handle);
[DllImport("usbtc08.dll")]
public static extern long usb_tc08_run(short handle, long interval_ms);
[DllImport("usbtc08.dll")]
public static extern long usb_tc08_get_temp(short handel, ref Single temp_buffer, ref long times_ms_buffer, long buffer_length, ref int overflow, int channel, int units, int fill_missing);
[DllImport("usbtc08.dll")]
public static extern long usb_tc08_get_minimum_interval_ms(short handle);
[DllImport("usbtc08.dll")]
public static extern short usb_tc08_get_unit_info2(short handle, ref char info, int string_length, int line_no);
[DllImport("usbtc08.dll")]
public static extern short usb_tc08_get_unit_info2(short handle, ref string info, int string_length, int line_no);
[DllImport("usbtc08.dll")]
public static extern short usb_tc08_get_unit_info(short handle, ref usbtc08Info info);
[DllImport("usbtc08.dll")]
public static extern short usb_tc08_get_formatted_info(short handle, ref char info, short string_length);
short tc08Handle;
char[] tc08SerialNo = new char[256];
public Menu()
{
InitializeComponent();
}
private void btnStart_Click(object sender, EventArgs e)
{
tslStatus.Text = "Starting";
if (tc08Handle < 1)
{
tc08Handle = usb_tc08_open_unit();
if (tc08Handle > 0)
{
try
{
//usb_tc08_get_unit_info2(tc08Handle, ref tc08SerialNo[0], 11, 4);
//string driver = new string(tc08SerialNo);
//MessageBox.Show(driver);
//string test = new string(tc08SerialNo);
//usb_tc08_get_unit_info2(tc08Handle, ref test, 11, 4);
//MessageBox.Show(test);
//usbtc08Info info = new usbtc08Info();
//info.size = sizeof(char) * 45 + sizeof(short) * 4;
//usb_tc08_get_unit_info(tc08Handle, ref info);
//MessageBox.Show(info.szSerial.ToString());
short res = usb_tc08_get_formatted_info(tc08Handle, ref tc08SerialNo[0], (short)512);
//string info = new string(tc08SerialNo);
MessageBox.Show(res.ToString()); //+ " " + info);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
Thanks,
Jacob Dixon