Multiple character gather on CommunicationGather

This commit is contained in:
Heath Volmer
2016-09-20 15:07:36 -06:00
parent 13482269a7
commit 0c72e68cc0
7 changed files with 250 additions and 210 deletions

View File

@@ -1,84 +1,124 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Crestron.SimplSharp; using System.Text.RegularExpressions;
using Crestron.SimplSharp;
using PepperDash.Core;
using PepperDash.Core;
namespace PepperDash.Core
{ namespace PepperDash.Core
/// <summary> {
/// Defines the string event handler for line events on the gather /// <summary>
/// </summary> /// Defines the string event handler for line events on the gather
/// <param name="text"></param> /// </summary>
public delegate void LineReceivedHandler(string text); /// <param name="text"></param>
public delegate void LineReceivedHandler(string text);
/// <summary>
/// Attaches to IBasicCommunication as a text gather /// <summary>
/// </summary> /// Attaches to IBasicCommunication as a text gather
public class CommunicationGather /// </summary>
{ public class CommunicationGather
/// <summary> {
/// Event that fires when a line is received from the IBasicCommunication source. /// <summary>
/// The event merely contains the text, not an EventArgs type class. /// Event that fires when a line is received from the IBasicCommunication source.
/// </summary> /// The event merely contains the text, not an EventArgs type class.
public event EventHandler<GenericCommMethodReceiveTextArgs> LineReceived; /// </summary>
public event EventHandler<GenericCommMethodReceiveTextArgs> LineReceived;
/// <summary>
/// The communication port that this gathers on /// <summary>
/// </summary> /// The communication port that this gathers on
public IBasicCommunication Port { get; private set; } /// </summary>
public IBasicCommunication Port { get; private set; }
/// <summary>
/// For receive buffer /// <summary>
/// </summary> /// For receive buffer
StringBuilder ReceiveBuffer = new StringBuilder(); /// </summary>
StringBuilder ReceiveBuffer = new StringBuilder();
/// <summary>
/// Delimiter, like it says! /// <summary>
/// </summary> /// Delimiter, like it says!
char Delimiter; /// </summary>
char Delimiter;
/// <summary>
/// Fires up a gather, given a IBasicCommunicaion port and char for de string StringDelimiter;
/// </summary>
/// <param name="port"></param> /// <summary>
/// <param name="delimiter"></param> /// Fires up a gather, given a IBasicCommunicaion port and char for de
public CommunicationGather(IBasicCommunication port, char delimiter) /// </summary>
{ /// <param name="port"></param>
Port = port; /// <param name="delimiter"></param>
Delimiter = delimiter; public CommunicationGather(IBasicCommunication port, char delimiter)
port.TextReceived += new EventHandler<GenericCommMethodReceiveTextArgs>(Port_TextReceived); {
} Port = port;
Delimiter = delimiter;
/// <summary> port.TextReceived += new EventHandler<GenericCommMethodReceiveTextArgs>(Port_TextReceived);
/// Handler for raw data coming from port }
/// </summary>
void Port_TextReceived(object sender, GenericCommMethodReceiveTextArgs args) /// <summary>
{ ///
var handler = LineReceived; /// </summary>
if (handler != null) /// <param name="port"></param>
{ /// <param name="delimiter"></param>
ReceiveBuffer.Append(args.Text); public CommunicationGather(IBasicCommunication port, string delimiter)
var str = ReceiveBuffer.ToString(); {
var lines = str.Split(Delimiter); Port = port;
if (lines.Length > 0) StringDelimiter = delimiter;
{ port.TextReceived += TextReceivedStringDelimiter;
for (int i = 0; i < lines.Length - 1; i++) }
handler(this, new GenericCommMethodReceiveTextArgs(lines[i]));
ReceiveBuffer = new StringBuilder(lines[lines.Length - 1]); /// <summary>
} /// Handler for raw data coming from port
} /// </summary>
} void Port_TextReceived(object sender, GenericCommMethodReceiveTextArgs args)
{
/// <summary> var handler = LineReceived;
/// Deconstructor. Disconnects from port TextReceived events. if (handler != null)
/// </summary> {
~CommunicationGather() ReceiveBuffer.Append(args.Text);
{ var str = ReceiveBuffer.ToString();
Port.TextReceived -= Port_TextReceived; 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>
///
/// </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>
~CommunicationGather()
{
Port.TextReceived -= Port_TextReceived;
}
}
} }

View File

@@ -1,99 +1,99 @@
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Release</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Release</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion> <ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion> <SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{87E29B4C-569B-4368-A4ED-984AC1440C96}</ProjectGuid> <ProjectGuid>{87E29B4C-569B-4368-A4ED-984AC1440C96}</ProjectGuid>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>PepperDash_Core</RootNamespace> <RootNamespace>PepperDash_Core</RootNamespace>
<AssemblyName>PepperDash_Core</AssemblyName> <AssemblyName>PepperDash_Core</AssemblyName>
<ProjectTypeGuids>{0B4745B0-194B-4BB6-8E21-E9057CA92500};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> <ProjectTypeGuids>{0B4745B0-194B-4BB6-8E21-E9057CA92500};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<PlatformFamilyName>WindowsCE</PlatformFamilyName> <PlatformFamilyName>WindowsCE</PlatformFamilyName>
<PlatformID>E2BECB1F-8C8C-41ba-B736-9BE7D946A398</PlatformID> <PlatformID>E2BECB1F-8C8C-41ba-B736-9BE7D946A398</PlatformID>
<OSVersion>5.0</OSVersion> <OSVersion>5.0</OSVersion>
<DeployDirSuffix>SmartDeviceProject1</DeployDirSuffix> <DeployDirSuffix>SmartDeviceProject1</DeployDirSuffix>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion> <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<NativePlatformName>Windows CE</NativePlatformName> <NativePlatformName>Windows CE</NativePlatformName>
<FormFactorID> <FormFactorID>
</FormFactorID> </FormFactorID>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<AllowedReferenceRelatedFileExtensions>.allowedReferenceRelatedFileExtensions</AllowedReferenceRelatedFileExtensions> <AllowedReferenceRelatedFileExtensions>.allowedReferenceRelatedFileExtensions</AllowedReferenceRelatedFileExtensions>
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
<OutputPath>bin\</OutputPath> <OutputPath>bin\</OutputPath>
<DefineConstants>DEBUG;TRACE;</DefineConstants> <DefineConstants>DEBUG;TRACE;</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<NoStdLib>true</NoStdLib> <NoStdLib>true</NoStdLib>
<NoConfig>true</NoConfig> <NoConfig>true</NoConfig>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<AllowedReferenceRelatedFileExtensions>.allowedReferenceRelatedFileExtensions</AllowedReferenceRelatedFileExtensions> <AllowedReferenceRelatedFileExtensions>.allowedReferenceRelatedFileExtensions</AllowedReferenceRelatedFileExtensions>
<DebugType>none</DebugType> <DebugType>none</DebugType>
<Optimize>true</Optimize> <Optimize>true</Optimize>
<OutputPath>bin\</OutputPath> <OutputPath>bin\</OutputPath>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<NoStdLib>true</NoStdLib> <NoStdLib>true</NoStdLib>
<NoConfig>true</NoConfig> <NoConfig>true</NoConfig>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="mscorlib" /> <Reference Include="mscorlib" />
<Reference Include="Newtonsoft.Json.Compact, Version=3.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <Reference Include="Newtonsoft.Json.Compact, Version=3.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\..\..\ProgramData\Crestron\SDK\Newtonsoft.Json.Compact.dll</HintPath> <HintPath>..\..\..\..\..\..\..\ProgramData\Crestron\SDK\Newtonsoft.Json.Compact.dll</HintPath>
</Reference> </Reference>
<Reference Include="SimplSharpCustomAttributesInterface, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1099c178b3b54c3b, processorArchitecture=MSIL"> <Reference Include="SimplSharpCustomAttributesInterface, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1099c178b3b54c3b, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\..\..\ProgramData\Crestron\SDK\SimplSharpCustomAttributesInterface.dll</HintPath> <HintPath>..\..\..\..\..\..\..\ProgramData\Crestron\SDK\SimplSharpCustomAttributesInterface.dll</HintPath>
</Reference> </Reference>
<Reference Include="SimplSharpHelperInterface, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1099c178b3b54c3b, processorArchitecture=MSIL"> <Reference Include="SimplSharpHelperInterface, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1099c178b3b54c3b, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\..\..\ProgramData\Crestron\SDK\SimplSharpHelperInterface.dll</HintPath> <HintPath>..\..\..\..\..\..\..\ProgramData\Crestron\SDK\SimplSharpHelperInterface.dll</HintPath>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="CommunicationExtras.cs" /> <Compile Include="CommunicationExtras.cs" />
<Compile Include="Comm\CommunicationGather.cs" /> <Compile Include="Comm\CommunicationGather.cs" />
<Compile Include="Comm\GenericSshClient.cs" /> <Compile Include="Comm\GenericSshClient.cs" />
<Compile Include="Comm\GenericTcpIpClientWithGather.cs" /> <Compile Include="Comm\GenericTcpIpClientWithGather.cs" />
<Compile Include="Comm\SshConfig.cs" /> <Compile Include="Comm\SshConfig.cs" />
<Compile Include="CoreInterfaces.cs" /> <Compile Include="CoreInterfaces.cs" />
<Compile Include="Debug.cs" /> <Compile Include="Debug.cs" />
<Compile Include="Device.cs" /> <Compile Include="Device.cs" />
<Compile Include="EthernetHelper.cs" /> <Compile Include="EthernetHelper.cs" />
<Compile Include="Comm\GenericTcpIpClient.cs" /> <Compile Include="Comm\GenericTcpIpClient.cs" />
<Compile Include="Network\DiscoveryThings.cs" /> <Compile Include="Network\DiscoveryThings.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<None Include="Properties\ControlSystem.cfg" /> <None Include="Properties\ControlSystem.cfg" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CompactFramework.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CompactFramework.CSharp.targets" />
<ProjectExtensions> <ProjectExtensions>
<VisualStudio> <VisualStudio>
<FlavorProperties GUID="{0B4745B0-194B-4BB6-8E21-E9057CA92500}"> <FlavorProperties GUID="{0B4745B0-194B-4BB6-8E21-E9057CA92500}">
<ProgramIdTag>PepperDash_Core</ProgramIdTag> <ProgramIdTag>PepperDash_Core</ProgramIdTag>
<SystemName>PepperDash_Core</SystemName> <SystemName>PepperDash_Core</SystemName>
<Programmer /> <Programmer />
<ArchiveFilename>C:\Users\hvolm\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\bin\PepperDash_Core.clz</ArchiveFilename> <ArchiveFilename>C:\Users\hvolm\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\bin\PepperDash_Core.clz</ArchiveFilename>
<MinFirmwareVersion>1.007.0017</MinFirmwareVersion> <MinFirmwareVersion>1.007.0017</MinFirmwareVersion>
<CompiledOn>9/12/2016 2:06:04 PM</CompiledOn> <CompiledOn>9/20/2016 2:09:33 PM</CompiledOn>
<AdditionalInfo /> <AdditionalInfo />
<EmbedSourceArchive>False</EmbedSourceArchive> <EmbedSourceArchive>False</EmbedSourceArchive>
<CopyTo /> <CopyTo />
<OriginalReferenceSources /> <OriginalReferenceSources />
</FlavorProperties> </FlavorProperties>
</VisualStudio> </VisualStudio>
</ProjectExtensions> </ProjectExtensions>
<PropertyGroup> <PropertyGroup>
<PostBuildEvent>rem S# preparation will execute after these operations</PostBuildEvent> <PostBuildEvent>rem S# preparation will execute after these operations</PostBuildEvent>
</PropertyGroup> </PropertyGroup>
</Project> </Project>

View File

@@ -1,16 +1,16 @@
<ProgramInfo> <ProgramInfo>
<RequiredInfo> <RequiredInfo>
<FriendlyName>PepperDash_Core</FriendlyName> <FriendlyName>PepperDash_Core</FriendlyName>
<SystemName>PepperDash_Core</SystemName> <SystemName>PepperDash_Core</SystemName>
<EntryPoint>PepperDash_Core</EntryPoint> <EntryPoint>PepperDash_Core</EntryPoint>
<MinFirmwareVersion>1.007.0017</MinFirmwareVersion> <MinFirmwareVersion>1.007.0017</MinFirmwareVersion>
<ProgramTool>SIMPL# Plugin</ProgramTool> <ProgramTool>SIMPL# Plugin</ProgramTool>
<DesignToolId>5</DesignToolId> <DesignToolId>5</DesignToolId>
<ProgramToolId>5</ProgramToolId> <ProgramToolId>5</ProgramToolId>
<ArchiveName /> <ArchiveName />
</RequiredInfo> </RequiredInfo>
<OptionalInfo> <OptionalInfo>
<CompiledOn>9/12/2016 2:06:04 PM</CompiledOn> <CompiledOn>9/20/2016 2:09:33 PM</CompiledOn>
<CompilerRev>1.0.0.23581</CompilerRev> <CompilerRev>1.0.0.23686</CompilerRev>
</OptionalInfo> </OptionalInfo>
</ProgramInfo> </ProgramInfo>

View File

@@ -1,14 +1,14 @@
MainAssembly=PepperDash_Core.dll:841414db99de3a39f802c9ba80e23ad1 MainAssembly=PepperDash_Core.dll:d21b9348a9ff127c20006e8d8b9a166c
MainAssemblyMinFirmwareVersion=1.007.0017 MainAssemblyMinFirmwareVersion=1.007.0017
ü ü
DependencySource=Newtonsoft.Json.Compact.dll:ea996aa2ec65aa1878e7c9d09e37a896 DependencySource=Newtonsoft.Json.Compact.dll:ea996aa2ec65aa1878e7c9d09e37a896
DependencyPath=PepperDash_Core.clz:Newtonsoft.Json.Compact.dll DependencyPath=PepperDash_Core.clz:Newtonsoft.Json.Compact.dll
DependencyMainAssembly=Newtonsoft.Json.Compact.dll:ea996aa2ec65aa1878e7c9d09e37a896 DependencyMainAssembly=Newtonsoft.Json.Compact.dll:ea996aa2ec65aa1878e7c9d09e37a896
ü ü
DependencySource=SimplSharpCustomAttributesInterface.dll:9c4b4d4c519b655af90016edca2d66b9 DependencySource=SimplSharpCustomAttributesInterface.dll:9c4b4d4c519b655af90016edca2d66b9
DependencyPath=PepperDash_Core.clz:SimplSharpCustomAttributesInterface.dll DependencyPath=PepperDash_Core.clz:SimplSharpCustomAttributesInterface.dll
DependencyMainAssembly=SimplSharpCustomAttributesInterface.dll:9c4b4d4c519b655af90016edca2d66b9 DependencyMainAssembly=SimplSharpCustomAttributesInterface.dll:9c4b4d4c519b655af90016edca2d66b9
ü ü
DependencySource=SimplSharpHelperInterface.dll:aed72eb0e19559a3f56708be76445dcd DependencySource=SimplSharpHelperInterface.dll:aed72eb0e19559a3f56708be76445dcd
DependencyPath=PepperDash_Core.clz:SimplSharpHelperInterface.dll DependencyPath=PepperDash_Core.clz:SimplSharpHelperInterface.dll
DependencyMainAssembly=SimplSharpHelperInterface.dll:aed72eb0e19559a3f56708be76445dcd DependencyMainAssembly=SimplSharpHelperInterface.dll:aed72eb0e19559a3f56708be76445dcd