init
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.21022</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{D485515C-366A-4D14-83DA-585FC4007461}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>SerialConnection.cs</RootNamespace>
|
||||
<AssemblyName>SerialConnection.cs</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<FileUpgradeFlags>
|
||||
</FileUpgradeFlags>
|
||||
<UpgradeBackupLocation>
|
||||
</UpgradeBackupLocation>
|
||||
<OldToolsVersion>3.5</OldToolsVersion>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x86\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
|
||||
<OutputPath>bin\x86\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x64\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<OutputPath>bin\x64\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml.Linq">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Data.DataSetExtensions">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="SerialConnection.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\DTS.Common.DASResource\DTS.Common.DASResource.csproj">
|
||||
<Project>{f621ce48-bb4b-4cfc-a325-9410b721cc44}</Project>
|
||||
<Name>DTS.Common.DASResource</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\DTS.Common\DTS.Common.csproj">
|
||||
<Project>{F7A0804F-61A4-40AE-83D0-F1137622B592}</Project>
|
||||
<Name>DTS.Common</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
@@ -0,0 +1,35 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("SerialConnection.cs")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("SerialConnection.cs")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2009")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("8d3a85de-321a-48fb-8f9e-f1d9594ee423")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
[assembly: AssemblyVersion("1.06.0081")]
|
||||
[assembly: AssemblyFileVersion("1.06.0081")]
|
||||
@@ -0,0 +1,276 @@
|
||||
using DTS.Common.Interface.Connection;
|
||||
using System;
|
||||
using System.IO.Ports;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DTS.Common.SerialConnection
|
||||
{
|
||||
public class SerialConnection : IConnection
|
||||
{
|
||||
/// <summary>
|
||||
/// returns true if the unit is soft disconnected
|
||||
/// </summary>
|
||||
public bool IsSoftDisconnected { get; private set; } = false;
|
||||
/// <summary>
|
||||
/// connects the unit
|
||||
/// :note does nothing for serial as we don't have a soft disconnect option yet:
|
||||
/// </summary>
|
||||
public void SoftConnect()
|
||||
{
|
||||
}
|
||||
/// <summary>
|
||||
/// disconnects the unit
|
||||
/// :note does nothing for serial as we don't have a soft disconnect option yet:
|
||||
/// </summary>
|
||||
public void SoftDisconnect()
|
||||
{
|
||||
}
|
||||
|
||||
void IConnection.KeepAliveErrorReceived()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Create(string connectString, string hostIPAddress)
|
||||
{
|
||||
//ConnectString = connectString;
|
||||
}
|
||||
public string GetConnectionData() { return ""; }
|
||||
public double GetCurrentDownloadRate() { return 0D; }
|
||||
public double GetCurrentUploadRate() { return 0D; }
|
||||
|
||||
protected SerialPort Port;
|
||||
protected string _PortName;
|
||||
private bool disposed;
|
||||
|
||||
public event EventHandler OnDisconnected;
|
||||
|
||||
public bool Connected { get; } = false;
|
||||
|
||||
//this was only being set, and not used, in addition it's name
|
||||
//is confusing next to _Connected and Connected{}
|
||||
//but since it's value is never referenced it's probably safe to remove it
|
||||
//public bool connected = false;
|
||||
|
||||
public string ConnectString => _PortName;
|
||||
|
||||
public System.Net.Sockets.SocketFlags Flags { get; set; }
|
||||
|
||||
public SerialConnection()
|
||||
{
|
||||
disposed = false;
|
||||
}
|
||||
|
||||
~SerialConnection()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposed)
|
||||
return;
|
||||
|
||||
if (disposing)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (Port != null)
|
||||
Port.Close();
|
||||
Port = null;
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
disposed = true;
|
||||
}
|
||||
|
||||
public void Create(string PortName)
|
||||
{
|
||||
Port = new SerialPort(_PortName);
|
||||
_PortName = PortName;
|
||||
}
|
||||
|
||||
#region Connect
|
||||
|
||||
public IAsyncResult BeginConnect(AsyncCallback cb, object state)
|
||||
{
|
||||
if (Port == null)
|
||||
{
|
||||
// "SerialConnection.BeginConnect: socket is not created"
|
||||
throw new System.Exception("SerialConnection.BeginConnect: socket is not created");
|
||||
}
|
||||
if (string.IsNullOrEmpty(_PortName))
|
||||
{
|
||||
// "SerialConnection.BeginConnect: Connect_String is empty"
|
||||
throw new System.Exception("SerialConnection.BeginConnect: Connect_String is empty");
|
||||
}
|
||||
Port.Open();
|
||||
return null;
|
||||
}
|
||||
|
||||
public void EndConnect(IAsyncResult ar)
|
||||
{
|
||||
if (Port == null)
|
||||
{
|
||||
// "SerialConnection.EndConnect: socket is not created"
|
||||
throw new System.Exception("SerialConnection.EndConnect: socket is not created");
|
||||
}
|
||||
//connected = true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Disconnect
|
||||
|
||||
public IAsyncResult BeginDisconnect(bool reuseSocket,
|
||||
AsyncCallback cb,
|
||||
Object state)
|
||||
{
|
||||
if (Port == null)
|
||||
{
|
||||
// "SerialConnection.BeginDisconnect: socket is not created"
|
||||
throw new System.Exception("SerialConnection.BeginDisconnect: socket is not created");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void EndDisconnect(IAsyncResult asyncResult)
|
||||
{
|
||||
if (Port == null)
|
||||
{
|
||||
// "SerialConnection.EndDisconnect: socket is not created"
|
||||
throw new System.Exception("SerialConnection.EndDisconnect: socket is not created");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Accept
|
||||
|
||||
public IAsyncResult BeginAccept(AsyncCallback callback,
|
||||
Object state)
|
||||
{
|
||||
if (Port == null)
|
||||
{
|
||||
// "SerialConnection.BeginAccept: socket is not created"
|
||||
throw new System.Exception("SerialConnection.BeginAccept: socket is not created");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public IConnection EndAccept(IAsyncResult asyncResult)
|
||||
{
|
||||
if (Port == null)
|
||||
{
|
||||
// "SerialConnection.EndAccept: socket is not created"
|
||||
throw new System.Exception("SerialConnection.EndAccept: socket is not created");
|
||||
}
|
||||
|
||||
var newConnection = new SerialConnection();
|
||||
return newConnection;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Bind
|
||||
|
||||
public void Bind(int port)
|
||||
{
|
||||
if (Port == null)
|
||||
{
|
||||
// "SerialConnection.Bind: socket is not created"
|
||||
throw new System.Exception("SerialConnection.Bind: socket is not created");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Listen
|
||||
|
||||
public void Listen(int backlog)
|
||||
{
|
||||
if (Port == null)
|
||||
{
|
||||
// "SerialConnection.Listen: socket is not created"
|
||||
throw new System.Exception("SerialConnection.Listen: socket is not created");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Send
|
||||
|
||||
public IAsyncResult BeginSend(byte[] buffer, int offset, int size,
|
||||
AsyncCallback cb, object state)
|
||||
{
|
||||
if (Port == null)
|
||||
{
|
||||
// "SerialConnection.BeginSend: socket is not created"
|
||||
throw new System.Exception("SerialConnection.BeginSend: socket is not created");
|
||||
}
|
||||
if (cb == null)
|
||||
{
|
||||
// "SerialConnection.BeginSend: callback can't be null"
|
||||
throw new System.Exception("SerialConnection.BeginSend: callback can't be null");
|
||||
}
|
||||
return Port.BaseStream.BeginWrite(buffer, offset, size, new AsyncCallback(cb), state);
|
||||
}
|
||||
|
||||
public int EndSend(IAsyncResult ar)
|
||||
{
|
||||
if (Port == null)
|
||||
{
|
||||
// "SerialConnection.EndSend: socket is not created"
|
||||
throw new System.Exception("SerialConnection.EndSend: socket is not created");
|
||||
}
|
||||
Port.BaseStream.EndWrite(ar);
|
||||
return Port.BytesToWrite;
|
||||
}
|
||||
|
||||
public Task<int> SendAsync(byte[] sendBuffer, int bufferStartOffset, int bufferSizeToSend)
|
||||
{
|
||||
return Task<int>.Factory.FromAsync(
|
||||
(callback, state) => BeginSend(sendBuffer, bufferStartOffset, bufferSizeToSend, callback, state),
|
||||
EndSend, state: null
|
||||
);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Receive
|
||||
|
||||
public IAsyncResult BeginReceive(byte[] buffer, int offset, int size,
|
||||
AsyncCallback cb, object state)
|
||||
{
|
||||
if (Port == null)
|
||||
{
|
||||
// "SerialConnection.BeginReceive: socket is not created"
|
||||
throw new System.Exception("SerialConnection.BeginReceive: socket is not created");
|
||||
}
|
||||
if (cb == null)
|
||||
{
|
||||
// "SerialConnection.BeginReceive: callback can't be null"
|
||||
throw new System.Exception("SerialConnection.BeginReceive: callback can't be null");
|
||||
}
|
||||
return Port.BaseStream.BeginRead(buffer, offset, size, new AsyncCallback(cb), state);
|
||||
}
|
||||
|
||||
public int EndReceive(IAsyncResult ar)
|
||||
{
|
||||
if (Port == null)
|
||||
{
|
||||
// "SerialConnection.EndReceive: socket is not created"
|
||||
throw new System.Exception("SerialConnection.EndReceive: socket is not created");
|
||||
}
|
||||
return Port.BaseStream.EndRead(ar);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// <autogenerated />
|
||||
using System;
|
||||
using System.Reflection;
|
||||
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.8", FrameworkDisplayName = "")]
|
||||
@@ -0,0 +1,4 @@
|
||||
// <autogenerated />
|
||||
using System;
|
||||
using System.Reflection;
|
||||
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user