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); private readonly bool connected; public TemperatureSource() => this.connected = UniversalOpenCom(Appsettings.GMHPort, 4800, 8, 0, 0) == 2; public double GetTemperature() { try { 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); } //if (temperature < 50) //{ // return -1.11; //} //else if (temperature > 50) //{ // return 1.11; //} return temperature; } catch { return 0; } } public void Dispose() => GMH_CloseCom(); } }