mirror of
https://github.com/PepperDash/PepperDashCore.git
synced 2026-02-19 06:34:46 +00:00
Multiple character gather on CommunicationGather
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using Crestron.SimplSharp;
|
||||
|
||||
using PepperDash.Core;
|
||||
@@ -41,6 +42,8 @@ namespace PepperDash.Core
|
||||
/// </summary>
|
||||
char Delimiter;
|
||||
|
||||
string StringDelimiter;
|
||||
|
||||
/// <summary>
|
||||
/// Fires up a gather, given a IBasicCommunicaion port and char for de
|
||||
/// </summary>
|
||||
@@ -53,6 +56,18 @@ namespace PepperDash.Core
|
||||
port.TextReceived += new EventHandler<GenericCommMethodReceiveTextArgs>(Port_TextReceived);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="port"></param>
|
||||
/// <param name="delimiter"></param>
|
||||
public CommunicationGather(IBasicCommunication port, string delimiter)
|
||||
{
|
||||
Port = port;
|
||||
StringDelimiter = delimiter;
|
||||
port.TextReceived += TextReceivedStringDelimiter;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handler for raw data coming from port
|
||||
/// </summary>
|
||||
@@ -73,6 +88,31 @@ namespace PepperDash.Core
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="args"></param>
|
||||
void TextReceivedStringDelimiter(object sender, GenericCommMethodReceiveTextArgs args)
|
||||
{
|
||||
var handler = LineReceived;
|
||||
if (handler != null)
|
||||
{
|
||||
// Receive buffer should either be empty or not contain the delimiter
|
||||
// If the line does not have a delimiter, append the
|
||||
|
||||
ReceiveBuffer.Append(args.Text);
|
||||
var str = ReceiveBuffer.ToString();
|
||||
var lines = Regex.Split(str, StringDelimiter);
|
||||
if (lines.Length > 1)
|
||||
{
|
||||
for (int i = 0; i < lines.Length - 1; i++)
|
||||
handler(this, new GenericCommMethodReceiveTextArgs(lines[i]));
|
||||
ReceiveBuffer = new StringBuilder(lines[lines.Length - 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deconstructor. Disconnects from port TextReceived events.
|
||||
/// </summary>
|
||||
|
||||
@@ -85,7 +85,7 @@
|
||||
<Programmer />
|
||||
<ArchiveFilename>C:\Users\hvolm\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\bin\PepperDash_Core.clz</ArchiveFilename>
|
||||
<MinFirmwareVersion>1.007.0017</MinFirmwareVersion>
|
||||
<CompiledOn>9/12/2016 2:06:04 PM</CompiledOn>
|
||||
<CompiledOn>9/20/2016 2:09:33 PM</CompiledOn>
|
||||
<AdditionalInfo />
|
||||
<EmbedSourceArchive>False</EmbedSourceArchive>
|
||||
<CopyTo />
|
||||
|
||||
Binary file not shown.
@@ -10,7 +10,7 @@
|
||||
<ArchiveName />
|
||||
</RequiredInfo>
|
||||
<OptionalInfo>
|
||||
<CompiledOn>9/12/2016 2:06:04 PM</CompiledOn>
|
||||
<CompilerRev>1.0.0.23581</CompilerRev>
|
||||
<CompiledOn>9/20/2016 2:09:33 PM</CompiledOn>
|
||||
<CompilerRev>1.0.0.23686</CompilerRev>
|
||||
</OptionalInfo>
|
||||
</ProgramInfo>
|
||||
Binary file not shown.
@@ -1,4 +1,4 @@
|
||||
MainAssembly=PepperDash_Core.dll:841414db99de3a39f802c9ba80e23ad1
|
||||
MainAssembly=PepperDash_Core.dll:d21b9348a9ff127c20006e8d8b9a166c
|
||||
MainAssemblyMinFirmwareVersion=1.007.0017
|
||||
ü
|
||||
DependencySource=Newtonsoft.Json.Compact.dll:ea996aa2ec65aa1878e7c9d09e37a896
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user