diff --git a/Pepperdash Core/Pepperdash Core/Comm/CommunicationGather.cs b/Pepperdash Core/Pepperdash Core/Comm/CommunicationGather.cs new file mode 100644 index 0000000..da8a7cd --- /dev/null +++ b/Pepperdash Core/Pepperdash Core/Comm/CommunicationGather.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Crestron.SimplSharp; + +using PepperDash.Core; + + +namespace PepperDash.Core +{ + /// + /// Defines the string event handler for line events on the gather + /// + /// + public delegate void LineReceivedHandler(string text); + + /// + /// Attaches to IBasicCommunication as a text gather + /// + public class CommunicationGather + { + /// + /// Event that fires when a line is received from the IBasicCommunication source. + /// The event merely contains the text, not an EventArgs type class. + /// + public event EventHandler LineReceived; + + /// + /// The communication port that this gathers on + /// + public IBasicCommunication Port { get; private set; } + + /// + /// For receive buffer + /// + StringBuilder ReceiveBuffer = new StringBuilder(); + + /// + /// Delimiter, like it says! + /// + char Delimiter; + + /// + /// Fires up a gather, given a IBasicCommunicaion port and char for de + /// + /// + /// + public CommunicationGather(IBasicCommunication port, char delimiter) + { + Port = port; + Delimiter = delimiter; + port.TextReceived += new EventHandler(Port_TextReceived); + } + + /// + /// Handler for raw data coming from port + /// + void Port_TextReceived(object sender, GenericCommMethodReceiveTextArgs args) + { + var handler = LineReceived; + if (handler != null) + { + ReceiveBuffer.Append(args.Text); + var str = ReceiveBuffer.ToString(); + var lines = str.Split(Delimiter); + if (lines.Length > 0) + { + for (int i = 0; i < lines.Length - 1; i++) + handler(this, new GenericCommMethodReceiveTextArgs(lines[i])); + ReceiveBuffer = new StringBuilder(lines[lines.Length - 1]); + } + } + } + + /// + /// Deconstructor. Disconnects from port TextReceived events. + /// + ~CommunicationGather() + { + Port.TextReceived -= Port_TextReceived; + } + } +} \ No newline at end of file diff --git a/Pepperdash Core/Pepperdash Core/PepperDash_Core.csproj b/Pepperdash Core/Pepperdash Core/PepperDash_Core.csproj index 8e347d0..030dd55 100644 --- a/Pepperdash Core/Pepperdash Core/PepperDash_Core.csproj +++ b/Pepperdash Core/Pepperdash Core/PepperDash_Core.csproj @@ -63,6 +63,7 @@ + @@ -82,7 +83,7 @@ C:\Users\hvolm\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\bin\PepperDash_Core.clz 1.007.0017 - 8/4/2016 2:17:06 PM + 8/15/2016 1:48:16 PM False diff --git a/Pepperdash Core/Pepperdash Core/bin/PepperDash_Core.clz b/Pepperdash Core/Pepperdash Core/bin/PepperDash_Core.clz index d43219c..72f7c6a 100644 Binary files a/Pepperdash Core/Pepperdash Core/bin/PepperDash_Core.clz and b/Pepperdash Core/Pepperdash Core/bin/PepperDash_Core.clz differ diff --git a/Pepperdash Core/Pepperdash Core/bin/PepperDash_Core.config b/Pepperdash Core/Pepperdash Core/bin/PepperDash_Core.config index 7ae7b12..8055bd7 100644 --- a/Pepperdash Core/Pepperdash Core/bin/PepperDash_Core.config +++ b/Pepperdash Core/Pepperdash Core/bin/PepperDash_Core.config @@ -10,7 +10,7 @@ - 8/4/2016 2:17:06 PM - 1.0.0.23912 + 8/15/2016 1:48:16 PM + 1.0.0.23047 \ No newline at end of file diff --git a/Pepperdash Core/Pepperdash Core/bin/manifest.info b/Pepperdash Core/Pepperdash Core/bin/manifest.info index 7a892d8..b182711 100644 --- a/Pepperdash Core/Pepperdash Core/bin/manifest.info +++ b/Pepperdash Core/Pepperdash Core/bin/manifest.info @@ -1,4 +1,4 @@ -MainAssembly=PepperDash_Core.dll:66c29b6308b378a0722f4f8fae4d948c +MainAssembly=PepperDash_Core.dll:23de4ff8ab162b967cd3760f55691182 MainAssemblyMinFirmwareVersion=1.007.0017 ü DependencySource=Newtonsoft.Json.Compact.dll:ea996aa2ec65aa1878e7c9d09e37a896 diff --git a/Pepperdash Core/Pepperdash Core/bin/manifest.ser b/Pepperdash Core/Pepperdash Core/bin/manifest.ser index b3abd89..7078afc 100644 Binary files a/Pepperdash Core/Pepperdash Core/bin/manifest.ser and b/Pepperdash Core/Pepperdash Core/bin/manifest.ser differ