using System; using System.IO.Ports; namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisConfig { /// /// Collection of port settings /// public struct PortConfig { private String _portName; /// /// Assigns a port name and creates the serial port object /// Port name e.g. "COM2" /// public String PortName { get => //if the serial port object does not exists GetSerialPort() == null ? "NA" : _portName; set { if (value == null) return; _portName = value; //create a serial port object if (GetSerialPort() == null) { SetSerialPort(new SerialPort(value)); } else { GetSerialPort().PortName = value; } } } /// /// setup of port type from name (referenced as "Type" in config file) /// public String Type { get; set; } private SerialPort _serialPort; /// /// using dotNets for connection /// public SerialPort GetSerialPort() { return _serialPort; } /// /// using dotNets for connection /// private void SetSerialPort(SerialPort value) { _serialPort = value; } } }