Files
laatzen/Common/Hardware/WaterMeter/Genesis/GenesisConfig/PortConfig.cs
T
2021-10-01 11:09:20 +02:00

66 lines
1.7 KiB
C#

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