mirror of
https://github.com/PepperDash/PepperDashCore.git
synced 2026-02-08 09:14:52 +00:00
Moved CommunicationGather class in
This commit is contained in:
84
Pepperdash Core/Pepperdash Core/Comm/CommunicationGather.cs
Normal file
84
Pepperdash Core/Pepperdash Core/Comm/CommunicationGather.cs
Normal file
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the string event handler for line events on the gather
|
||||
/// </summary>
|
||||
/// <param name="text"></param>
|
||||
public delegate void LineReceivedHandler(string text);
|
||||
|
||||
/// <summary>
|
||||
/// Attaches to IBasicCommunication as a text gather
|
||||
/// </summary>
|
||||
public class CommunicationGather
|
||||
{
|
||||
/// <summary>
|
||||
/// Event that fires when a line is received from the IBasicCommunication source.
|
||||
/// The event merely contains the text, not an EventArgs type class.
|
||||
/// </summary>
|
||||
public event EventHandler<GenericCommMethodReceiveTextArgs> LineReceived;
|
||||
|
||||
/// <summary>
|
||||
/// The communication port that this gathers on
|
||||
/// </summary>
|
||||
public IBasicCommunication Port { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// For receive buffer
|
||||
/// </summary>
|
||||
StringBuilder ReceiveBuffer = new StringBuilder();
|
||||
|
||||
/// <summary>
|
||||
/// Delimiter, like it says!
|
||||
/// </summary>
|
||||
char Delimiter;
|
||||
|
||||
/// <summary>
|
||||
/// Fires up a gather, given a IBasicCommunicaion port and char for de
|
||||
/// </summary>
|
||||
/// <param name="port"></param>
|
||||
/// <param name="delimiter"></param>
|
||||
public CommunicationGather(IBasicCommunication port, char delimiter)
|
||||
{
|
||||
Port = port;
|
||||
Delimiter = delimiter;
|
||||
port.TextReceived += new EventHandler<GenericCommMethodReceiveTextArgs>(Port_TextReceived);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handler for raw data coming from port
|
||||
/// </summary>
|
||||
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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deconstructor. Disconnects from port TextReceived events.
|
||||
/// </summary>
|
||||
~CommunicationGather()
|
||||
{
|
||||
Port.TextReceived -= Port_TextReceived;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,6 +63,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CommunicationExtras.cs" />
|
||||
<Compile Include="Comm\CommunicationGather.cs" />
|
||||
<Compile Include="Comm\GenericSshClient.cs" />
|
||||
<Compile Include="Comm\SshConfig.cs" />
|
||||
<Compile Include="CoreInterfaces.cs" />
|
||||
@@ -82,7 +83,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>8/4/2016 2:17:06 PM</CompiledOn>
|
||||
<CompiledOn>8/15/2016 1:48:16 PM</CompiledOn>
|
||||
<AdditionalInfo />
|
||||
<EmbedSourceArchive>False</EmbedSourceArchive>
|
||||
<CopyTo />
|
||||
|
||||
Binary file not shown.
@@ -10,7 +10,7 @@
|
||||
<ArchiveName />
|
||||
</RequiredInfo>
|
||||
<OptionalInfo>
|
||||
<CompiledOn>8/4/2016 2:17:06 PM</CompiledOn>
|
||||
<CompilerRev>1.0.0.23912</CompilerRev>
|
||||
<CompiledOn>8/15/2016 1:48:16 PM</CompiledOn>
|
||||
<CompilerRev>1.0.0.23047</CompilerRev>
|
||||
</OptionalInfo>
|
||||
</ProgramInfo>
|
||||
@@ -1,4 +1,4 @@
|
||||
MainAssembly=PepperDash_Core.dll:66c29b6308b378a0722f4f8fae4d948c
|
||||
MainAssembly=PepperDash_Core.dll:23de4ff8ab162b967cd3760f55691182
|
||||
MainAssemblyMinFirmwareVersion=1.007.0017
|
||||
ü
|
||||
DependencySource=Newtonsoft.Json.Compact.dll:ea996aa2ec65aa1878e7c9d09e37a896
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user