Имеется ТРМ202 старой модификации (без modbus, только OWEN). Никак не могу считать float параметры. Целочисленные читаются.
Порт открывается
Код:
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 открыт";
}
Методы из библиотеки owen_io.dll
Код:
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);
}
Целочисленные параметры читаются
Код:
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);
Посоветуйте как float вычитать. Или примерами поделитесь рабочими. Заранее благодарен.