Initial commit
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user