37 lines
1.2 KiB
C#
37 lines
1.2 KiB
C#
namespace Xylem.Common.Ui.GenesisToolBox.Infrastructure
|
|
{
|
|
using System;
|
|
using System.Runtime.InteropServices;
|
|
|
|
public class TemperatureSource : IDisposable
|
|
{
|
|
[DllImport("GMH3x32E.dll")]
|
|
public static extern Int16 UniversalOpenCom(Int16 ini16COMPortNumber, UInt32 inui32BaudRate, Int16 inui16ConverterType, Int16 ini16Parity, Int16 ini16StoppBits);
|
|
|
|
[DllImport("GMH3x32E.dll")]
|
|
public static extern Int16 GMH_CloseCom();
|
|
|
|
[DllImport("GMH3x32E.dll")]
|
|
unsafe public static extern Int16 GMH_Transmit(Int16 ini16DeviceAddress, Int16 ini16TransmitCode, Int16* refi16ptrPriority, double* refdblptrFloatValue, Int32* refi32ptrIntegerValue);
|
|
|
|
public TemperatureSource()
|
|
=> UniversalOpenCom(Appsettings.GMHPort, 4800, 8, 0, 0);
|
|
|
|
public double GetTemperature()
|
|
{
|
|
var result = default(short);
|
|
var priority = default(short);
|
|
var temperature = double.MinValue;
|
|
var value = default(int);
|
|
|
|
unsafe
|
|
{
|
|
result = GMH_Transmit(1, 0, &priority, &temperature, &value);
|
|
}
|
|
|
|
return temperature;
|
|
}
|
|
|
|
public void Dispose() => GMH_CloseCom();
|
|
}
|
|
} |