From af1a27a355bf753973a1211d991d7304da59e258 Mon Sep 17 00:00:00 2001 From: gaoc Date: Wed, 10 Jun 2015 13:53:59 +0800 Subject: [PATCH] delete agentgenerator --- Windup.SerialTalker/AgentGenerator.cs | 40 ------------- Windup.SerialTalker/Analyzer.cs | 2 +- Windup.SerialTalker/SerialList.cs | 26 -------- Windup.SerialTalker/Talker.cs | 60 ++++++++++++++++++- .../Windup.SerialTalker.csproj | 2 - 5 files changed, 60 insertions(+), 70 deletions(-) delete mode 100644 Windup.SerialTalker/AgentGenerator.cs delete mode 100644 Windup.SerialTalker/SerialList.cs diff --git a/Windup.SerialTalker/AgentGenerator.cs b/Windup.SerialTalker/AgentGenerator.cs deleted file mode 100644 index 5f35ca6..0000000 --- a/Windup.SerialTalker/AgentGenerator.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Text; - -namespace Windup.SerialTalker -{ - static class AgentGenerator - { - - public static SerialAgent CreateAgent(SPSetting setting) - { - Debug.Assert(null != setting); - var sa = new SerialAgent() { - AgentPortName = setting.PortName, - AgentBaudRate = setting.BaudRate, - AgentParity = setting.Parity, - AgentDataBits = setting.DataBits, - AgentStopBits = setting.StopBits - }; - return sa; - } - - public static IEnumerable CreateAgents(IEnumerable settings) - { - var list = new List(); - foreach (var sa in settings.Select(setting => new SerialAgent( - portName: setting.PortName, - baudRate: setting.BaudRate, - parity: setting.Parity, - dataBits: setting.DataBits, - stopBits: setting.StopBits - ))) { - list.Add(sa); - } - return list; - } - } -} diff --git a/Windup.SerialTalker/Analyzer.cs b/Windup.SerialTalker/Analyzer.cs index 65bd218..803986b 100644 --- a/Windup.SerialTalker/Analyzer.cs +++ b/Windup.SerialTalker/Analyzer.cs @@ -5,7 +5,7 @@ namespace Windup.SerialTalker { - public enum ChangeFlag + enum ChangeFlag { Succeed, Failed diff --git a/Windup.SerialTalker/SerialList.cs b/Windup.SerialTalker/SerialList.cs deleted file mode 100644 index a4059a5..0000000 --- a/Windup.SerialTalker/SerialList.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.IO.Ports; - -namespace Windup.SerialTalker -{ - class SerialList - { - public static string[] ReturnSerialList() - { - string[] allSerial = null; - try - { - allSerial = SerialPort.GetPortNames(); - } - catch /*(Exception e)*/ - { - //throw new Exception(e.Message); - return null; - } - return allSerial; - } - } -} diff --git a/Windup.SerialTalker/Talker.cs b/Windup.SerialTalker/Talker.cs index 06fa5d8..7d58402 100644 --- a/Windup.SerialTalker/Talker.cs +++ b/Windup.SerialTalker/Talker.cs @@ -1,4 +1,6 @@ using System; +using System.Linq; +using System.IO.Ports; using System.Collections.Generic; namespace Windup.SerialTalker @@ -21,7 +23,7 @@ public Talker(string portName, int baudRate, LineBreak lineBreak) public Talker(SPSetting setting, LineBreak lineBreak) { - var sa = AgentGenerator.CreateAgent (setting); + var sa = CreateAgent(setting); CreateAnalyzer (sa, lineBreak); } @@ -49,6 +51,62 @@ void OnDataListReady(object o, DataListReadyEventArgs e) { byteListProc (e.Bytes); } + + /// + /// Creates the agent. + /// + /// The agent. + /// Setting. + SerialAgent CreateAgent(SPSetting setting) + { + var sa = new SerialAgent() { + AgentPortName = setting.PortName, + AgentBaudRate = setting.BaudRate, + AgentParity = setting.Parity, + AgentDataBits = setting.DataBits, + AgentStopBits = setting.StopBits + }; + return sa; + } + + /// + /// Creates the agents. + /// + /// The agents. + /// Settings. + IEnumerable CreateAgents(IEnumerable settings) + { + var list = new List(); + foreach (var sa in settings.Select(setting => new SerialAgent( + portName: setting.PortName, + baudRate: setting.BaudRate, + parity: setting.Parity, + dataBits: setting.DataBits, + stopBits: setting.StopBits + ))) { + list.Add(sa); + } + return list; + } + + /// + /// Gets the serial ports. + /// + /// The serial ports. + public string[] GetSerialPorts() + { + string[] allSerial = null; + try + { + allSerial = SerialPort.GetPortNames(); + } + catch /*(Exception e)*/ + { + //throw new Exception(e.Message); + return null; + } + return allSerial; + } } } diff --git a/Windup.SerialTalker/Windup.SerialTalker.csproj b/Windup.SerialTalker/Windup.SerialTalker.csproj index 8b45664..11325a4 100644 --- a/Windup.SerialTalker/Windup.SerialTalker.csproj +++ b/Windup.SerialTalker/Windup.SerialTalker.csproj @@ -37,13 +37,11 @@ - -