67 lines
2.3 KiB
C#
67 lines
2.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace DTS.SensorDB.TDCINI
|
|
{
|
|
/// <summary>
|
|
/// helper class for RS232 section of INI file
|
|
/// </summary>
|
|
public class TDCINIRS232Info
|
|
{
|
|
/// <summary>
|
|
/// Communication port
|
|
/// </summary>
|
|
public int ComPortNumber { get; set; }
|
|
/// <summary>
|
|
/// Max speed of com port
|
|
/// </summary>
|
|
public int MaxComSpeed { get; set; }
|
|
/// <summary>
|
|
/// max number of ports
|
|
/// </summary>
|
|
public int MaxComPorts { get; set; }
|
|
public TDCINIRS232Info() { }
|
|
/// <summary>
|
|
/// read section from a line
|
|
/// returns true if read successfully, false if there were errors
|
|
/// </summary>
|
|
/// <param name="line"></param>
|
|
/// <param name="errors"></param>
|
|
/// <returns></returns>
|
|
public bool ReadFrom(string line, ref List<TDCINIError> errors)
|
|
{
|
|
string[] tokens = line.Split(new char[] { ',' });
|
|
if (3 != tokens.Length)
|
|
{
|
|
errors.Add(new TDCINIError(TDCINIError.INIErrors.INI_COMINFO_INVALID, line));
|
|
return false;
|
|
}
|
|
|
|
int i;
|
|
if (!int.TryParse(tokens[0], System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out i))
|
|
{
|
|
errors.Add(new TDCINIError(TDCINIError.INIErrors.INI_COMINFO_INVALID, line));
|
|
return false;
|
|
}
|
|
else { ComPortNumber = i; }
|
|
|
|
if (!int.TryParse(tokens[1], System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out i))
|
|
{
|
|
errors.Add(new TDCINIError(TDCINIError.INIErrors.INI_COMINFO_INVALID, line));
|
|
return false;
|
|
}
|
|
else { MaxComSpeed = i; }
|
|
|
|
if (!int.TryParse(tokens[2], System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out i))
|
|
{
|
|
errors.Add(new TDCINIError(TDCINIError.INIErrors.INI_COMINFO_INVALID, line));
|
|
return false;
|
|
}
|
|
else { MaxComPorts = i; }
|
|
return true;
|
|
}
|
|
}
|
|
}
|