Цитата:
[DllImportAttribute("owen_io.dll", EntryPoint = "OpenPort", CallingConvention = CallingConvention.StdCall)]
public static extern int OpenPort(int n, int sped, int part, int bits, int stop, int vid);
[DllImportAttribute("owen_io.dll", EntryPoint = "ClosePort", CallingConvention = CallingConvention.StdCall)]
public static extern int ClosePort();
[DllImportAttribute("owen_io.dll", EntryPoint = "ReadIEEE32", CallingConvention = CallingConvention.StdCall)]
public static extern int ReadIEEE32(int adr, int adr_type, System.IntPtr command, ref float value, ref int time, int index);
[DllImportAttribute("owen_io.dll", EntryPoint = "SetMaxRetriesGlobal", CallingConvention = CallingConvention.StdCall)]
public static extern void SetMaxRetriesGlobal(int n);
[DllImportAttribute("owen_io.dll", EntryPoint = "ReadFloat24", CallingConvention = CallingConvention.StdCall)]
public static extern int ReadFloat24(int adr, int adr_type, System.IntPtr command, ref float value, int index);
[DllImportAttribute("owen_io.dll", EntryPoint = "ReadSInt", CallingConvention = CallingConvention.StdCall)]
public static extern int ReadSInt(int adr, int adr_type, IntPtr command, ref int param, int index);
[DllImportAttribute("owen_io.dll", EntryPoint = "WriteWord", CallingConvention = CallingConvention.StdCall)]
public static extern int WriteWord(int adr, int adr_type, IntPtr command, int value, int index);
Импорт dll выполнен так.
Цитата:
int adr = Convert.ToInt32(textBox1.Text); // адрес прибора
IntPtr command = Marshal.StringToCoTaskMemAnsi("STAT");
int value = Convert.ToInt32(textBox3.Text); // величина, которую будем записывать
try
{
int result = RS485.WriteWord(adr, 0, command, value, -1);
MessageBox.Show("процесс " + result.ToString() + "\n" + "значение " + value.ToString());
}
catch
{
MessageBox.Show("ошибка чтения данных");
}