Skip to content
Permalink
Browse files

Multitarget to net20, net35, net40 through Theraot.Core (#97)

* Read status now set correctly  (#82)

* 1. Fixed the issue with Read timing out even when Read time out is set to 0.   This boils down to using an incorrect value for WAIT_INFINITE
2. Fixed the issue with ReadReport failing after being blocked initially on a read.  The Wait after readreport is also now conditional, based on whether or not the ReadReport succeeded.  There is also an additional call to get overlapped result to retrieve data after a Wait

* Fixed indentation

* Status of the read operation is now set if the ReadFile returns immediately with success. Addresses the issue around #81 (#81)

* Added support to net20 through Theraot.Core;
Updated project to multi-target frameworks

* Fix build process

* Added support to net35 and net40

* Fix indentation
  • Loading branch information...
Hazzard17h authored and mikeobrien committed Jun 25, 2018
1 parent 0cb47d6 commit a0ddb57b17ba0d7baf546a42d463a8a40fc834f4
Showing with 60 additions and 29 deletions.
  1. +2 −1 .gitignore
  2. +12 −1 HidLibrary.nuspec
  3. +2 −2 gulpfile.js
  4. +1 −1 package.json
  5. +22 −1 src/HidLibrary/HidDevice.cs
  6. +8 −0 src/HidLibrary/HidFastReadDevice.cs
  7. +13 −23 src/HidLibrary/HidLibrary.csproj
@@ -6,4 +6,5 @@ _ReSharper.*
*.user
*.suo
*.log
.DS_Store
.DS_Store
.vs/
@@ -15,5 +15,16 @@
<summary>This library enables you to enumerate and communicate with Hid compatible USB devices in .NET.</summary>
<iconUrl>https://github.com/mikeobrien/HidLibrary/raw/master/misc/logo.png</iconUrl>
<tags>usb hid</tags>
<dependencies>
<group targetFramework="net20">
<dependency id="Theraot.Core" version="1.0.3" />
</group>
<group targetFramework="net35">
<dependency id="Theraot.Core" version="1.0.3" />
</group>
<group targetFramework="net40">
<dependency id="Theraot.Core" version="1.0.3" />
</group>
</dependencies>
</metadata>
</package>
</package>
@@ -26,7 +26,7 @@ gulp.task('build', ['assemblyInfo'], function() {
return gulp
.src('src/*.sln')
.pipe(msbuild({
toolsVersion: 4.0,
toolsVersion: 'auto',
targets: ['Clean', 'Build'],
errorOnFail: true,
stdout: true
@@ -43,7 +43,7 @@ gulp.task('test', ['build'], function () {

gulp.task('nuget-package', ['build'], function() {

gulp.src('src/HidLibrary/bin/Release/HidLibrary.*')
gulp.src('src/HidLibrary/bin/Release/**/HidLibrary.*')
.pipe(gulp.dest('package/lib'));

return Nuget()
@@ -4,7 +4,7 @@
"dependencies": {
"gulp": "^3.8.10",
"gulp-dotnet-assembly-info": "^0.1.10",
"gulp-msbuild": "^0.2.5",
"gulp-msbuild": "^0.5.4",
"gulp-nunit-runner": "^0.4.1",
"nuget-runner": "^0.1.5",
"yargs": "^1.3.3"
@@ -150,7 +150,11 @@ public void Read(ReadCallback callback, int timeout)
public async Task<HidDeviceData> ReadAsync(int timeout = 0)
{
var readDelegate = new ReadDelegate(Read);
#if NET20 || NET35
return await Task<HidDeviceData>.Factory.StartNew(() => readDelegate.Invoke(timeout));
#else
return await Task<HidDeviceData>.Factory.FromAsync(readDelegate.BeginInvoke, readDelegate.EndInvoke, timeout, null);
#endif
}

public HidReport ReadReport()
@@ -178,7 +182,11 @@ public void ReadReport(ReadReportCallback callback, int timeout)
public async Task<HidReport> ReadReportAsync(int timeout = 0)
{
var readReportDelegate = new ReadReportDelegate(ReadReport);
#if NET20 || NET35
return await Task<HidReport>.Factory.StartNew(() => readReportDelegate.Invoke(timeout));
#else
return await Task<HidReport>.Factory.FromAsync(readReportDelegate.BeginInvoke, readReportDelegate.EndInvoke, timeout, null);
#endif
}

/// <summary>
@@ -357,7 +365,11 @@ public void Write(byte[] data, WriteCallback callback, int timeout)
public async Task<bool> WriteAsync(byte[] data, int timeout = 0)
{
var writeDelegate = new WriteDelegate(Write);
#if NET20 || NET35
return await Task<bool>.Factory.StartNew(() => writeDelegate.Invoke(data, timeout));
#else
return await Task<bool>.Factory.FromAsync(writeDelegate.BeginInvoke, writeDelegate.EndInvoke, data, timeout, null);
#endif
}

public bool WriteReport(HidReport report)
@@ -404,7 +416,11 @@ public bool WriteReportSync(HidReport report)
public async Task<bool> WriteReportAsync(HidReport report, int timeout = 0)
{
var writeReportDelegate = new WriteReportDelegate(WriteReport);
#if NET20 || NET35
return await Task<bool>.Factory.StartNew(() => writeReportDelegate.Invoke(report, timeout));
#else
return await Task<bool>.Factory.FromAsync(writeReportDelegate.BeginInvoke, writeReportDelegate.EndInvoke, report, timeout, null);
#endif
}

public HidReport CreateReport()
@@ -614,7 +630,12 @@ protected HidDeviceData ReadData(int timeout)
{
var success = NativeMethods.ReadFile(Handle, nonManagedBuffer, (uint)buffer.Length, out bytesRead, ref overlapped);

if (!success) {
if (success)
{
status = HidDeviceData.ReadStatus.Success; // No check here to see if bytesRead > 0 . Perhaps not necessary?
}
else
{
var result = NativeMethods.WaitForSingleObject(overlapped.EventHandle, overlapTimeout);

switch (result)
@@ -42,7 +42,11 @@ public void FastRead(ReadCallback callback, int timeout)
public async Task<HidDeviceData> FastReadAsync(int timeout = 0)
{
var readDelegate = new ReadDelegate(FastRead);
#if NET20 || NET35
return await Task<HidDeviceData>.Factory.StartNew(() => readDelegate.Invoke(timeout));
#else
return await Task<HidDeviceData>.Factory.FromAsync(readDelegate.BeginInvoke, readDelegate.EndInvoke, timeout, null);
#endif
}

public HidReport FastReadReport()
@@ -70,7 +74,11 @@ public void FastReadReport(ReadReportCallback callback, int timeout)
public async Task<HidReport> FastReadReportAsync(int timeout = 0)
{
var readReportDelegate = new ReadReportDelegate(FastReadReport);
#if NET20 || NET35
return await Task<HidReport>.Factory.StartNew(() => readReportDelegate.Invoke(timeout));
#else
return await Task<HidReport>.Factory.FromAsync(readReportDelegate.BeginInvoke, readReportDelegate.EndInvoke, timeout, null);
#endif
}
}
}
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -10,9 +10,10 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>HidLibrary</RootNamespace>
<AssemblyName>HidLibrary</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworks>net20;net35;net40;net45</TargetFrameworks>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -36,31 +37,20 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Extensions.cs" />
<Compile Include="HidAsyncState.cs" />
<Compile Include="HidDevice.cs" />
<Compile Include="HidDeviceAttributes.cs" />
<Compile Include="HidDeviceCapabilities.cs" />
<Compile Include="HidDeviceData.cs" />
<Compile Include="HidDeviceEventMonitor.cs" />
<Compile Include="HidFastReadDevice.cs" />
<Compile Include="HidFastReadEnumerator.cs" />
<Compile Include="IHidEnumerator.cs" />
<Compile Include="HidDevices.cs" />
<Compile Include="HidReport.cs" />
<Compile Include="IHidDevice.cs" />
<Compile Include="NativeMethods.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<ItemGroup Condition=" '$(TargetFramework)' != 'net45' ">
<PackageReference Include="Theraot.Core" Version="1.0.3" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ItemGroup Condition=" '$(TargetFramework)' != 'net20' ">
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' != 'net20' AND '$(TargetFramework)' != 'net35' ">
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<!-- 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">

1 comment on commit a0ddb57

@mikeobrien

This comment has been minimized.

Copy link
Owner

commented on a0ddb57 Jun 25, 2018

TeamCity Hid Library :: Deploy Build 3.2.48.0 outcome was FAILURE
Summary: Exit code 1 Build time: 00:00:26

Please sign in to comment.
You can’t perform that action at this time.