using DTS.Common.Base; using DTS.Common.Enums; using DTS.Common.Interface.Sensors; using DTS.Common.Interface.Tags; using DTS.Common.Utilities.Logging; using System; using System.Data; using System.IO.Ports; namespace DTS.Common.Classes.Sensors { public class UARTRecord : TagAwareBase, IUARTRecord { public override TagTypes TagType { get => TagTypes.Sensors; } private int _id; public int Id { get => _id; set => SetProperty(ref _id, value, "Id"); } private string _serialNumber; public string SerialNumber { get => _serialNumber; set => SetProperty(ref _serialNumber, value, "SerialNumber"); } private uint _uartBaudRate = DTS.Common.Constant.EmbeddedSensors.BAUD_RATE_DEFAULT; public uint UartBaudRate { get => _uartBaudRate; set => _uartBaudRate = value; } public const uint UART_DATABITS_DEFAULT = 8; private uint _uartDataBits = UART_DATABITS_DEFAULT; public uint UartDataBits { get => _uartDataBits; set => SetProperty(ref _uartDataBits, value, "UartDataBits"); } private StopBits _uartStopBits = StopBits.None; public const StopBits UART_STOPBITS_DEFAULT = StopBits.None; public StopBits UartStopBits { get => _uartStopBits; set => _uartStopBits = value; } public const UartDataFormat UART_DATAFORMAT_DEFAULT = UartDataFormat.Binary; public const Handshake UART_FLOWCONTROL_DEFAULT = Handshake.None; protected Handshake _flowControl = Handshake.None; public Handshake UartFlowControl { get => _flowControl; set => SetProperty(ref _flowControl, value, "UartFlowControl"); } private UartDataFormat _uartDataFormat = UART_DATAFORMAT_DEFAULT; public UartDataFormat UartDataFormat { get => _uartDataFormat; set => SetProperty(ref _uartDataFormat, value, "UartDataFormat"); } private DateTime _lastModified; public DateTime LastModified { get => _lastModified; set => SetProperty(ref _lastModified, value, "LastModified"); } private string _lastUpdatedBy; public string LastUpdatedBy { get => _lastUpdatedBy; set => SetProperty(ref _lastUpdatedBy, value, "LastUpdatedBy"); } private bool _doNotUse; public bool DoNotUse { get => _doNotUse; set => SetProperty(ref _doNotUse, value, "DoNotUse"); } private bool _broken; public bool Broken { get => _broken; set => SetProperty(ref _broken, value, "Broken"); } public const Parity UART_PARITY_DEFAULT = Parity.None; protected Parity _parity = Parity.None; public Parity UartParity { get => _parity; set => SetProperty(ref _parity, value, "UartParity"); } public UARTRecord(ISensorData sensor) { Id = sensor.DatabaseId; SerialNumber = sensor.SerialNumber; UartBaudRate = sensor.UartBaudRate; UartDataBits = sensor.UartDataBits; UartStopBits = sensor.UartStopBits; UartParity = sensor.UartParity; UartFlowControl = sensor.UartFlowControl; UartDataFormat = sensor.UartDataFormat; Broken = sensor.Broken; DoNotUse = sensor.DoNotUse; LastModified = sensor.LastModified; LastUpdatedBy = sensor.LastUpdatedBy; } public UARTRecord(IDataReader reader) { try { Id = Utility.GetInt(reader, "Id"); SerialNumber = Utility.GetString(reader, "SerialNumber"); UartBaudRate = Utility.GetUInt(reader, "BaudRate"); UartDataBits = Utility.GetUInt(reader, "DataBits"); UartStopBits = (StopBits)Enum.Parse(typeof(StopBits), Utility.GetString(reader, "StopBits")); UartParity = (Parity)Enum.Parse(typeof(Parity), Utility.GetString(reader, "Parity")); UartFlowControl = (Handshake)Enum.Parse(typeof(Handshake), Utility.GetString(reader, "FlowControl")); UartDataFormat = (UartDataFormat)Enum.Parse(typeof(UartDataFormat), Utility.GetString(reader, "DataFormat")); Broken = Utility.GetBool(reader, "Broken"); DoNotUse = Utility.GetBool(reader, "DoNotUse"); LastModified = Utility.GetDateTime(reader, "LastModified", DateTime.MinValue); LastUpdatedBy = Utility.GetString(reader, "LastModifiedBy"); } catch (Exception ex) { APILogger.Log("Failed to process: ", ex); } } } }