Add projects
This commit is contained in:
6
WaveshareUARTFingerprintSensor.Sample/App.config
Normal file
6
WaveshareUARTFingerprintSensor.Sample/App.config
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<configuration>
|
||||||
|
<startup>
|
||||||
|
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
|
||||||
|
</startup>
|
||||||
|
</configuration>
|
||||||
27
WaveshareUARTFingerprintSensor.Sample/Program.cs
Normal file
27
WaveshareUARTFingerprintSensor.Sample/Program.cs
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO.Ports;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Unosquare.RaspberryIO;
|
||||||
|
using Unosquare.RaspberryIO.Abstractions;
|
||||||
|
using Unosquare.WiringPi;
|
||||||
|
|
||||||
|
namespace WaveshareUARTFingerprintSensor.Sample
|
||||||
|
{
|
||||||
|
class Program
|
||||||
|
{
|
||||||
|
static void Main(string[] args)
|
||||||
|
{
|
||||||
|
var sensor = new FingerprintSensor(FingerprintSensor.PrimarySerialPort);
|
||||||
|
|
||||||
|
sensor.Start();
|
||||||
|
|
||||||
|
var count = sensor.GetUserCount();
|
||||||
|
|
||||||
|
Thread.Sleep(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
// Les informations générales relatives à un assembly dépendent de
|
||||||
|
// l'ensemble d'attributs suivant. Changez les valeurs de ces attributs pour modifier les informations
|
||||||
|
// associées à un assembly.
|
||||||
|
[assembly: AssemblyTitle("WaveshareUARTFingerprintSensor.Sample")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("")]
|
||||||
|
[assembly: AssemblyProduct("WaveshareUARTFingerprintSensor.Sample")]
|
||||||
|
[assembly: AssemblyCopyright("Copyright © 2020")]
|
||||||
|
[assembly: AssemblyTrademark("")]
|
||||||
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
// L'affectation de la valeur false à ComVisible rend les types invisibles dans cet assembly
|
||||||
|
// aux composants COM. Si vous devez accéder à un type dans cet assembly à partir de
|
||||||
|
// COM, affectez la valeur true à l'attribut ComVisible sur ce type.
|
||||||
|
[assembly: ComVisible(false)]
|
||||||
|
|
||||||
|
// Le GUID suivant est pour l'ID de la typelib si ce projet est exposé à COM
|
||||||
|
[assembly: Guid("0a9c9910-45e4-428f-9bc4-054808794c66")]
|
||||||
|
|
||||||
|
// Les informations de version pour un assembly se composent des quatre valeurs suivantes :
|
||||||
|
//
|
||||||
|
// Version principale
|
||||||
|
// Version secondaire
|
||||||
|
// Numéro de build
|
||||||
|
// Révision
|
||||||
|
//
|
||||||
|
// Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut
|
||||||
|
// en utilisant '*', comme indiqué ci-dessous :
|
||||||
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
|
[assembly: AssemblyVersion("1.0.0.0")]
|
||||||
|
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProjectGuid>{0A9C9910-45E4-428F-9BC4-054808794C66}</ProjectGuid>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<RootNamespace>WaveshareUARTFingerprintSensor.Sample</RootNamespace>
|
||||||
|
<AssemblyName>WaveshareUARTFingerprintSensor.Sample</AssemblyName>
|
||||||
|
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||||
|
<FileAlignment>512</FileAlignment>
|
||||||
|
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||||
|
<Deterministic>true</Deterministic>
|
||||||
|
<PublishUrl>publish\</PublishUrl>
|
||||||
|
<Install>true</Install>
|
||||||
|
<InstallFrom>Disk</InstallFrom>
|
||||||
|
<UpdateEnabled>false</UpdateEnabled>
|
||||||
|
<UpdateMode>Foreground</UpdateMode>
|
||||||
|
<UpdateInterval>7</UpdateInterval>
|
||||||
|
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||||
|
<UpdatePeriodically>false</UpdatePeriodically>
|
||||||
|
<UpdateRequired>false</UpdateRequired>
|
||||||
|
<MapFileExtensions>true</MapFileExtensions>
|
||||||
|
<ApplicationRevision>0</ApplicationRevision>
|
||||||
|
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||||
|
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||||
|
<UseApplicationTrust>false</UseApplicationTrust>
|
||||||
|
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="Swan, Version=3.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Unosquare.Swan.3.0.0\lib\net461\Swan.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Swan.Lite, Version=3.0.0.0, Culture=neutral, PublicKeyToken=30c707c872729fff, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Unosquare.Swan.Lite.3.0.0\lib\net461\Swan.Lite.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Core" />
|
||||||
|
<Reference Include="System.Drawing" />
|
||||||
|
<Reference Include="System.ServiceProcess" />
|
||||||
|
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Xml.Linq" />
|
||||||
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
|
<Reference Include="Microsoft.CSharp" />
|
||||||
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Net.Http" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
|
<Reference Include="Unosquare.Raspberry.Abstractions, Version=0.4.1.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Unosquare.Raspberry.Abstractions.0.4.1\lib\netstandard2.0\Unosquare.Raspberry.Abstractions.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Unosquare.RaspberryIO, Version=0.27.1.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Unosquare.Raspberry.IO.0.27.1\lib\netstandard2.0\Unosquare.RaspberryIO.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Unosquare.WiringPi, Version=0.5.1.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Unosquare.WiringPi.0.5.1\lib\netstandard2.0\Unosquare.WiringPi.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="Program.cs" />
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="App.config" />
|
||||||
|
<None Include="packages.config" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<BootstrapperPackage Include=".NETFramework,Version=v4.7.2">
|
||||||
|
<Visible>False</Visible>
|
||||||
|
<ProductName>Microsoft .NET Framework 4.7.2 %28x86 et x64%29</ProductName>
|
||||||
|
<Install>true</Install>
|
||||||
|
</BootstrapperPackage>
|
||||||
|
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||||
|
<Visible>False</Visible>
|
||||||
|
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||||
|
<Install>false</Install>
|
||||||
|
</BootstrapperPackage>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\WaveshareUARTFingerprintSensor\WaveshareUARTFingerprintSensor.csproj">
|
||||||
|
<Project>{dc535997-1161-4a7d-8573-259b13595778}</Project>
|
||||||
|
<Name>WaveshareUARTFingerprintSensor</Name>
|
||||||
|
</ProjectReference>
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
</Project>
|
||||||
9
WaveshareUARTFingerprintSensor.Sample/packages.config
Normal file
9
WaveshareUARTFingerprintSensor.Sample/packages.config
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<packages>
|
||||||
|
<package id="System.ValueTuple" version="4.5.0" targetFramework="net472" />
|
||||||
|
<package id="Unosquare.Raspberry.Abstractions" version="0.4.1" targetFramework="net472" />
|
||||||
|
<package id="Unosquare.Raspberry.IO" version="0.27.1" targetFramework="net472" />
|
||||||
|
<package id="Unosquare.Swan" version="3.0.0" targetFramework="net472" />
|
||||||
|
<package id="Unosquare.Swan.Lite" version="3.0.0" targetFramework="net472" />
|
||||||
|
<package id="Unosquare.WiringPi" version="0.5.1" targetFramework="net472" />
|
||||||
|
</packages>
|
||||||
31
WaveshareUARTFingerprintSensor.sln
Normal file
31
WaveshareUARTFingerprintSensor.sln
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 16
|
||||||
|
VisualStudioVersion = 16.0.30711.63
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WaveshareUARTFingerprintSensor.Sample", "WaveshareUARTFingerprintSensor.Sample\WaveshareUARTFingerprintSensor.Sample.csproj", "{0A9C9910-45E4-428F-9BC4-054808794C66}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WaveshareUARTFingerprintSensor", "WaveshareUARTFingerprintSensor\WaveshareUARTFingerprintSensor.csproj", "{DC535997-1161-4A7D-8573-259B13595778}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{0A9C9910-45E4-428F-9BC4-054808794C66}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{0A9C9910-45E4-428F-9BC4-054808794C66}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{0A9C9910-45E4-428F-9BC4-054808794C66}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{0A9C9910-45E4-428F-9BC4-054808794C66}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{DC535997-1161-4A7D-8573-259B13595778}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{DC535997-1161-4A7D-8573-259B13595778}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{DC535997-1161-4A7D-8573-259B13595778}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{DC535997-1161-4A7D-8573-259B13595778}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {4D22CA29-4B04-4D9E-A21D-E7DBF3013CBF}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
36
WaveshareUARTFingerprintSensor/CommandType.cs
Normal file
36
WaveshareUARTFingerprintSensor/CommandType.cs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace WaveshareUARTFingerprintSensor
|
||||||
|
{
|
||||||
|
public enum CommandType : byte
|
||||||
|
{
|
||||||
|
ModifySerialNumber = 0x08,
|
||||||
|
QuerySerialNumber = 0x2A,
|
||||||
|
SleepMode = 0x2C,
|
||||||
|
ManageFingerprintAddingMode = 0x2D,
|
||||||
|
AddFingerprint1 = 0x01,
|
||||||
|
AddFingerprint2 = 0x02,
|
||||||
|
AddFingerprint3 = 0x03,
|
||||||
|
AddAndAcquireFingerprint = 0x06,
|
||||||
|
DeleteUser = 0x04,
|
||||||
|
DeleteAllUsers = 0x05,
|
||||||
|
QueryUserCount = 0x09,
|
||||||
|
Comparison11 = 0x0B,
|
||||||
|
Comparison1N = 0x0C,
|
||||||
|
QueryPermission = 0x0A,
|
||||||
|
ManageComparisonLevel = 0x28,
|
||||||
|
AcquireImage = 0x24,
|
||||||
|
AcquireEigenvalues = 0x23,
|
||||||
|
UploadEigenvaluesAndCompare = 0x44,
|
||||||
|
UploadEigenvaluesAndCompare11 = 0x42,
|
||||||
|
UploadEigenvaluesAndCompare1N = 0x43,
|
||||||
|
AcquireEigenvaluesDSP = 0x31,
|
||||||
|
CreateUserFromEigenvalues = 0x41,
|
||||||
|
QueryUsersInfo = 0x2B,
|
||||||
|
ManageCaptureTimeout = 0x2E
|
||||||
|
}
|
||||||
|
}
|
||||||
162
WaveshareUARTFingerprintSensor/FingerprintSensor.cs
Normal file
162
WaveshareUARTFingerprintSensor/FingerprintSensor.cs
Normal file
@@ -0,0 +1,162 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.IO.Ports;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Unosquare.RaspberryIO;
|
||||||
|
using Unosquare.RaspberryIO.Abstractions;
|
||||||
|
using Unosquare.WiringPi;
|
||||||
|
|
||||||
|
namespace WaveshareUARTFingerprintSensor
|
||||||
|
{
|
||||||
|
public class FingerprintSensor : IDisposable
|
||||||
|
{
|
||||||
|
public const string PrimarySerialPort = "/dev/ttyAMA0";
|
||||||
|
public const string SecondarySerialPort = "/dev/ttyS0";
|
||||||
|
|
||||||
|
public string PortName { get; }
|
||||||
|
|
||||||
|
private const byte PacketSeparator = 0xF5;
|
||||||
|
|
||||||
|
private SerialPort _serialPort;
|
||||||
|
private int _wakePinNumber;
|
||||||
|
private int _rstPinNumber;
|
||||||
|
private IGpioPin _wakePin;
|
||||||
|
private IGpioPin _rstPin;
|
||||||
|
private object _lock = new object();
|
||||||
|
|
||||||
|
public FingerprintSensor(string portName, int wakePin = 23, int rstPin = 24)
|
||||||
|
{
|
||||||
|
PortName = portName;
|
||||||
|
_wakePinNumber = wakePin;
|
||||||
|
_rstPinNumber = rstPin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Start()
|
||||||
|
{
|
||||||
|
// Initialize Gpio
|
||||||
|
Pi.Init<BootstrapWiringPi>();
|
||||||
|
|
||||||
|
_wakePin = Pi.Gpio[_wakePinNumber];
|
||||||
|
_rstPin = Pi.Gpio[_rstPinNumber];
|
||||||
|
|
||||||
|
_wakePin.PinMode = GpioPinDriveMode.Input;
|
||||||
|
_rstPin.PinMode = GpioPinDriveMode.Output;
|
||||||
|
|
||||||
|
_rstPin.Write(GpioPinValue.High);
|
||||||
|
_wakePin.RegisterInterruptCallback(EdgeDetection.FallingAndRisingEdge, OnWake);
|
||||||
|
|
||||||
|
// Initialize SerialPort
|
||||||
|
_serialPort = new SerialPort(PortName, 19200);
|
||||||
|
|
||||||
|
_serialPort.Open();
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte ComputeChecksum(byte[] data)
|
||||||
|
{
|
||||||
|
byte checksum = 0;
|
||||||
|
|
||||||
|
for (int i = 1; i < 6; i++)
|
||||||
|
{
|
||||||
|
checksum += data[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return checksum;
|
||||||
|
}
|
||||||
|
|
||||||
|
private (byte first, byte second, ResponseType responseType) SendAndReceive(CommandType commandType, byte first, byte second, byte third)
|
||||||
|
{
|
||||||
|
// Command packet
|
||||||
|
byte[] buffer = { PacketSeparator, (byte)commandType, first, second, third, 0, 0, PacketSeparator };
|
||||||
|
|
||||||
|
lock (_lock)
|
||||||
|
{
|
||||||
|
|
||||||
|
// Checksum
|
||||||
|
buffer[6] = ComputeChecksum(buffer);
|
||||||
|
|
||||||
|
_serialPort.Write(buffer, 0, buffer.Length);
|
||||||
|
|
||||||
|
// Response
|
||||||
|
_serialPort.Read(buffer, 0, buffer.Length);
|
||||||
|
|
||||||
|
if (buffer[0] != PacketSeparator || buffer[7] != PacketSeparator || buffer[1] != (byte)commandType)
|
||||||
|
{
|
||||||
|
throw new InvalidDataException("Invalid response from the sensor");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buffer[6] != ComputeChecksum(buffer))
|
||||||
|
{
|
||||||
|
throw new InvalidDataException("Invalid checksum");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (buffer[2], buffer[3], (ResponseType)buffer[4]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
private void Send(CommandType commandType, byte first, byte second, byte third)
|
||||||
|
{
|
||||||
|
// Command packet
|
||||||
|
byte[] buffer = { PacketSeparator, (byte)commandType, first, second, third, 0, 0, PacketSeparator };
|
||||||
|
|
||||||
|
// Checksum
|
||||||
|
buffer[6] = ComputeChecksum(buffer);
|
||||||
|
|
||||||
|
_serialPort.Write(buffer, 0, buffer.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
private (byte first, byte second, byte third) Receive(CommandType commandType)
|
||||||
|
{
|
||||||
|
// Response buffer
|
||||||
|
var buffer = new byte[8];
|
||||||
|
|
||||||
|
// Response
|
||||||
|
_serialPort.Read(buffer, 0, buffer.Length);
|
||||||
|
|
||||||
|
if (buffer[0] != PacketSeparator || buffer[7] != PacketSeparator || buffer[1] != (byte)commandType)
|
||||||
|
{
|
||||||
|
throw new InvalidDataException("Invalid response from the sensor");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buffer[6] != ComputeChecksum(buffer))
|
||||||
|
{
|
||||||
|
throw new InvalidDataException("Invalid checksum");
|
||||||
|
}
|
||||||
|
|
||||||
|
return (buffer[2], buffer[3], buffer[4]);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
public bool TryGetUserCount(out ushort count)
|
||||||
|
{
|
||||||
|
(byte countHigh, byte countLow, ResponseType response) = SendAndReceive(CommandType.QueryUserCount, 0, 0, 0);
|
||||||
|
|
||||||
|
count = Utils.Merge(countHigh, countLow);
|
||||||
|
|
||||||
|
return response == ResponseType.Success;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Sleep()
|
||||||
|
{
|
||||||
|
_rstPin.Write(GpioPinValue.Low);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnWake()
|
||||||
|
{
|
||||||
|
if (_wakePin.Read())
|
||||||
|
{
|
||||||
|
Console.WriteLine("Sensor WAKE signal received");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
_serialPort.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
36
WaveshareUARTFingerprintSensor/Properties/AssemblyInfo.cs
Normal file
36
WaveshareUARTFingerprintSensor/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
// Les informations générales relatives à un assembly dépendent de
|
||||||
|
// l'ensemble d'attributs suivant. Changez les valeurs de ces attributs pour modifier les informations
|
||||||
|
// associées à un assembly.
|
||||||
|
[assembly: AssemblyTitle("WaveshareUARTFingerprintSensor")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("")]
|
||||||
|
[assembly: AssemblyProduct("WaveshareUARTFingerprintSensor")]
|
||||||
|
[assembly: AssemblyCopyright("Copyright © 2020")]
|
||||||
|
[assembly: AssemblyTrademark("")]
|
||||||
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
// L'affectation de la valeur false à ComVisible rend les types invisibles dans cet assembly
|
||||||
|
// aux composants COM. Si vous devez accéder à un type dans cet assembly à partir de
|
||||||
|
// COM, affectez la valeur true à l'attribut ComVisible sur ce type.
|
||||||
|
[assembly: ComVisible(false)]
|
||||||
|
|
||||||
|
// Le GUID suivant est pour l'ID de la typelib si ce projet est exposé à COM
|
||||||
|
[assembly: Guid("dc535997-1161-4a7d-8573-259b13595778")]
|
||||||
|
|
||||||
|
// Les informations de version pour un assembly se composent des quatre valeurs suivantes :
|
||||||
|
//
|
||||||
|
// Version principale
|
||||||
|
// Version secondaire
|
||||||
|
// Numéro de build
|
||||||
|
// Révision
|
||||||
|
//
|
||||||
|
// Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut
|
||||||
|
// en utilisant '*', comme indiqué ci-dessous :
|
||||||
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
|
[assembly: AssemblyVersion("1.0.0.0")]
|
||||||
|
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||||
19
WaveshareUARTFingerprintSensor/ResponseType.cs
Normal file
19
WaveshareUARTFingerprintSensor/ResponseType.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace WaveshareUARTFingerprintSensor
|
||||||
|
{
|
||||||
|
public enum ResponseType : byte
|
||||||
|
{
|
||||||
|
Success = 0x00,
|
||||||
|
Fail = 0x01,
|
||||||
|
Full = 0x04,
|
||||||
|
NoUser = 0x05,
|
||||||
|
UserOccupied = 0x06,
|
||||||
|
FingerOccupied = 0x07,
|
||||||
|
Timeout = 0x08
|
||||||
|
}
|
||||||
|
}
|
||||||
15
WaveshareUARTFingerprintSensor/Utils.cs
Normal file
15
WaveshareUARTFingerprintSensor/Utils.cs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace WaveshareUARTFingerprintSensor
|
||||||
|
{
|
||||||
|
public static class Utils
|
||||||
|
{
|
||||||
|
public static ushort Merge(byte high, byte low) => (ushort)(high << 8 | low);
|
||||||
|
|
||||||
|
public static (byte high, byte low) Split(ushort value) => ((byte)(value >> 8), (byte)(value & 0xFF));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProjectGuid>{DC535997-1161-4A7D-8573-259B13595778}</ProjectGuid>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
|
<RootNamespace>WaveshareUARTFingerprintSensor</RootNamespace>
|
||||||
|
<AssemblyName>WaveshareUARTFingerprintSensor</AssemblyName>
|
||||||
|
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||||
|
<FileAlignment>512</FileAlignment>
|
||||||
|
<Deterministic>true</Deterministic>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="Swan, Version=3.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Unosquare.Swan.3.0.0\lib\net461\Swan.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Swan.Lite, Version=3.0.0.0, Culture=neutral, PublicKeyToken=30c707c872729fff, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Unosquare.Swan.Lite.3.0.0\lib\net461\Swan.Lite.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Core" />
|
||||||
|
<Reference Include="System.Drawing" />
|
||||||
|
<Reference Include="System.ServiceProcess" />
|
||||||
|
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Xml.Linq" />
|
||||||
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
|
<Reference Include="Microsoft.CSharp" />
|
||||||
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Net.Http" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
|
<Reference Include="Unosquare.Raspberry.Abstractions, Version=0.4.1.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Unosquare.Raspberry.Abstractions.0.4.1\lib\netstandard2.0\Unosquare.Raspberry.Abstractions.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Unosquare.RaspberryIO, Version=0.27.1.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Unosquare.Raspberry.IO.0.27.1\lib\netstandard2.0\Unosquare.RaspberryIO.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Unosquare.WiringPi, Version=0.5.1.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Unosquare.WiringPi.0.5.1\lib\netstandard2.0\Unosquare.WiringPi.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="CommandType.cs" />
|
||||||
|
<Compile Include="FingerprintSensor.cs" />
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="ResponseType.cs" />
|
||||||
|
<Compile Include="Utils.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="packages.config" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
</Project>
|
||||||
9
WaveshareUARTFingerprintSensor/packages.config
Normal file
9
WaveshareUARTFingerprintSensor/packages.config
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<packages>
|
||||||
|
<package id="System.ValueTuple" version="4.5.0" targetFramework="net472" />
|
||||||
|
<package id="Unosquare.Raspberry.Abstractions" version="0.4.1" targetFramework="net472" />
|
||||||
|
<package id="Unosquare.Raspberry.IO" version="0.27.1" targetFramework="net472" />
|
||||||
|
<package id="Unosquare.Swan" version="3.0.0" targetFramework="net472" />
|
||||||
|
<package id="Unosquare.Swan.Lite" version="3.0.0" targetFramework="net472" />
|
||||||
|
<package id="Unosquare.WiringPi" version="0.5.1" targetFramework="net472" />
|
||||||
|
</packages>
|
||||||
Reference in New Issue
Block a user