RfidReader

This commit is contained in:
2011-10-25 17:01:15 +00:00
parent 7c1fda5bc4
commit d0458e85a9
12 changed files with 420 additions and 0 deletions
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// Allgemeine Informationen über eine Assembly werden über die folgenden
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
// die mit einer Assembly verknüpft sind.
[assembly: AssemblyTitle("RfidClass")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RfidClass")]
[assembly: AssemblyCopyright("Copyright © 2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar
// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von
// COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest.
[assembly: ComVisible(false)]
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
[assembly: Guid("eb701fb5-14a2-43f9-89c2-527a60f989fd")]
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
//
// Hauptversion
// Nebenversion
// Buildnummer
// Revision
//
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
+100
View File
@@ -0,0 +1,100 @@
using System;
using System.Diagnostics;
using System.Threading;
using System.IO.Ports;
using System.Text.RegularExpressions;
namespace RfidClass
{
public class RFIDReaderClass
{
private Thread t;
private SerialPort s;
private long id;
private bool _stop;
private Exception e;
public RFIDReaderClass(string com)
{
this.t = new Thread(this.reader);
s = new SerialPort(com, 9600, Parity.None, 8, StopBits.One);
}
private void reader()
{
while (!_stop)
{
Process r = new Process();
r.StartInfo.FileName = "librfid-tool.exe";
r.StartInfo.Arguments = "-s";
r.StartInfo.UseShellExecute = false;
r.StartInfo.RedirectStandardOutput = true;
r.StartInfo.RedirectStandardError = true;
try
{
r.Start();
}
catch (Exception exeption)
{
this.e = exeption;
return;
}
string a = r.StandardOutput.ReadToEnd();
string err = r.StandardError.ReadToEnd();
if (err.Contains("No OpenPCD found either"))
{
this.e = new Exception("No OpenPCD found");
return;
}
if (a.Contains("Layer 2 success") && a.Contains("Protocol success"))
{
string ids = a.Substring(a.IndexOf("):")+2,13);
ids = Regex.Replace(ids.Trim(), @"[^0-9a-fA-F]", "");
try
{
this.id = Int64.Parse(ids, System.Globalization.NumberStyles.HexNumber);
}
catch (Exception exeption)
{
this.e = exeption;
return;
}
}
Thread.Sleep(1000);
}
}
public long readKey()
{
this.t = new Thread(this.reader);
this.id = 0;
this._stop = false;
try
{
this.s.Open();
}
catch (Exception exeption)
{
//throw exeption;
}
this.t.Start();
while (!this.t.IsAlive) ;
while (this.t.IsAlive)
{
if (this.id != 0 || this.e != null)
{
this._stop = true;
}
}
if (this.e != null)
{
throw this.e;
}
return this.id;
}
public void abort()
{
this._stop = true;
}
}
}
+59
View File
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{2F816B95-069B-4D48-9FBF-9B805A1049A8}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>RfidClass</RootNamespace>
<AssemblyName>RfidClass</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</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="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="RFIDReaderClass.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="librfid-tool.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</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>
Binary file not shown.
Binary file not shown.
Binary file not shown.