Имеется ТРМ202 старой модификации (без modbus, только OWEN). Никак не могу считать float параметры. Целочисленные читаются.
Порт открывается
Методы из библиотеки owen_io.dllКод:ConnectionError res = (ConnectionError)NativeMethods.OpenPort( (int)numericUpDown1.Value, (int)BaudRate.Baud115200, (int)Parity.None, (int)DataBits.Eight, (int)StopBits.One, (int)ConverterType.Auto); if (res != ConnectionError.Ok) { label8.Text = "Ошибка открытия порта: " + res.ToString(); } else { label8.Text = "Com port открыт"; }
Целочисленные параметры читаютсяКод:partial class NativeMethods { [DllImportAttribute("owen_io.dll", EntryPoint = "OpenPort", CallingConvention = CallingConvention.StdCall)] public static extern int OpenPort(int n, int speed, 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 = "ReadUInt", CallingConvention = CallingConvention.StdCall)] public static extern int ReadUInt(int adr, int adr_type, System.IntPtr command, ref int value, int index); [DllImportAttribute("owen_io.dll", EntryPoint = "ReadSInt", CallingConvention = CallingConvention.StdCall)] public static extern int ReadSInt(int adr, int adr_type, System.IntPtr command, ref int value, int index); [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 = "ReadStoredDotS", CallingConvention = CallingConvention.StdCall)] public static extern int ReadStoredDotS(int adr, int adr_type, System.IntPtr command, ref float value, int index); }
А вот float вообще никак не хочет читатьсяКод:int bitMask = 0; ConnectionError res; IntPtr name = Marshal.StringToCoTaskMemAnsi(textBox1.Text); res = (ConnectionError)NativeMethods.ReadUInt( (int)numericUpDown2.Value, 0, name, ref bitMask, -1); if (res == ConnectionError.Ok) { textBox2.Text = bitMask.ToString(); }
Посоветуйте как float вычитать. Или примерами поделитесь рабочими. Заранее благодарен.Код:IntPtr name = Marshal.StringToCoTaskMemAnsi(textBox1.Text); float value = 0; ConnectionError res = (ConnectionError)NativeMethods.ReadStoredDotS((int)numericUpDown2.Value, 1, name, ref value, -1);


Ответить с цитированием
