@@ -9,36 +9,78 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HKCardOUT", "HKCardOUT\HKCa | |||||
EndProject | EndProject | ||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HKLog", "HKLog\HKLog.csproj", "{617E076F-D422-44B7-8455-006AA34ECD45}" | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HKLog", "HKLog\HKLog.csproj", "{617E076F-D422-44B7-8455-006AA34ECD45}" | ||||
EndProject | EndProject | ||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HKControl", "HKControl\HKControl.csproj", "{C82945B1-3D74-40E3-A16C-213BCED377E1}" | |||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HKControl", "HKControl\HKControl.csproj", "{C82945B1-3D74-40E3-A16C-213BCED377E1}" | |||||
EndProject | EndProject | ||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HKHelper", "HKHelper\HKHelper.csproj", "{CFA68AF9-1C11-41A3-8A73-34E004660CFC}" | |||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HKHelper", "HKHelper\HKHelper.csproj", "{CFA68AF9-1C11-41A3-8A73-34E004660CFC}" | |||||
EndProject | |||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UHFHelper", "UHFHelper\UHFHelper.csproj", "{F7A3683F-B767-427C-BCB8-7C5DA507D663}" | |||||
EndProject | |||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "test", "test\test.csproj", "{3AD252E2-6878-4ABC-8A3E-22CCFCE2E075}" | |||||
EndProject | EndProject | ||||
Global | Global | ||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||||
Debug|Any CPU = Debug|Any CPU | Debug|Any CPU = Debug|Any CPU | ||||
Debug|x86 = Debug|x86 | |||||
Release|Any CPU = Release|Any CPU | Release|Any CPU = Release|Any CPU | ||||
Release|x86 = Release|x86 | |||||
EndGlobalSection | EndGlobalSection | ||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||||
{B1174E5F-41B1-447E-BCDD-3C94E311487D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | {B1174E5F-41B1-447E-BCDD-3C94E311487D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||||
{B1174E5F-41B1-447E-BCDD-3C94E311487D}.Debug|Any CPU.Build.0 = Debug|Any CPU | {B1174E5F-41B1-447E-BCDD-3C94E311487D}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||
{B1174E5F-41B1-447E-BCDD-3C94E311487D}.Debug|x86.ActiveCfg = Debug|x86 | |||||
{B1174E5F-41B1-447E-BCDD-3C94E311487D}.Debug|x86.Build.0 = Debug|x86 | |||||
{B1174E5F-41B1-447E-BCDD-3C94E311487D}.Release|Any CPU.ActiveCfg = Release|Any CPU | {B1174E5F-41B1-447E-BCDD-3C94E311487D}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||
{B1174E5F-41B1-447E-BCDD-3C94E311487D}.Release|Any CPU.Build.0 = Release|Any CPU | {B1174E5F-41B1-447E-BCDD-3C94E311487D}.Release|Any CPU.Build.0 = Release|Any CPU | ||||
{B1174E5F-41B1-447E-BCDD-3C94E311487D}.Release|x86.ActiveCfg = Release|x86 | |||||
{B1174E5F-41B1-447E-BCDD-3C94E311487D}.Release|x86.Build.0 = Release|x86 | |||||
{A03F8002-B946-4FD6-BEE7-54EFC199FE4E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | {A03F8002-B946-4FD6-BEE7-54EFC199FE4E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||||
{A03F8002-B946-4FD6-BEE7-54EFC199FE4E}.Debug|Any CPU.Build.0 = Debug|Any CPU | {A03F8002-B946-4FD6-BEE7-54EFC199FE4E}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||
{A03F8002-B946-4FD6-BEE7-54EFC199FE4E}.Debug|x86.ActiveCfg = Debug|x86 | |||||
{A03F8002-B946-4FD6-BEE7-54EFC199FE4E}.Debug|x86.Build.0 = Debug|x86 | |||||
{A03F8002-B946-4FD6-BEE7-54EFC199FE4E}.Release|Any CPU.ActiveCfg = Release|Any CPU | {A03F8002-B946-4FD6-BEE7-54EFC199FE4E}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||
{A03F8002-B946-4FD6-BEE7-54EFC199FE4E}.Release|Any CPU.Build.0 = Release|Any CPU | {A03F8002-B946-4FD6-BEE7-54EFC199FE4E}.Release|Any CPU.Build.0 = Release|Any CPU | ||||
{A03F8002-B946-4FD6-BEE7-54EFC199FE4E}.Release|x86.ActiveCfg = Release|x86 | |||||
{A03F8002-B946-4FD6-BEE7-54EFC199FE4E}.Release|x86.Build.0 = Release|x86 | |||||
{617E076F-D422-44B7-8455-006AA34ECD45}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | {617E076F-D422-44B7-8455-006AA34ECD45}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||||
{617E076F-D422-44B7-8455-006AA34ECD45}.Debug|Any CPU.Build.0 = Debug|Any CPU | {617E076F-D422-44B7-8455-006AA34ECD45}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||
{617E076F-D422-44B7-8455-006AA34ECD45}.Debug|x86.ActiveCfg = Debug|x86 | |||||
{617E076F-D422-44B7-8455-006AA34ECD45}.Debug|x86.Build.0 = Debug|x86 | |||||
{617E076F-D422-44B7-8455-006AA34ECD45}.Release|Any CPU.ActiveCfg = Release|Any CPU | {617E076F-D422-44B7-8455-006AA34ECD45}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||
{617E076F-D422-44B7-8455-006AA34ECD45}.Release|Any CPU.Build.0 = Release|Any CPU | {617E076F-D422-44B7-8455-006AA34ECD45}.Release|Any CPU.Build.0 = Release|Any CPU | ||||
{617E076F-D422-44B7-8455-006AA34ECD45}.Release|x86.ActiveCfg = Release|x86 | |||||
{617E076F-D422-44B7-8455-006AA34ECD45}.Release|x86.Build.0 = Release|x86 | |||||
{C82945B1-3D74-40E3-A16C-213BCED377E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | {C82945B1-3D74-40E3-A16C-213BCED377E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||||
{C82945B1-3D74-40E3-A16C-213BCED377E1}.Debug|Any CPU.Build.0 = Debug|Any CPU | {C82945B1-3D74-40E3-A16C-213BCED377E1}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||
{C82945B1-3D74-40E3-A16C-213BCED377E1}.Debug|x86.ActiveCfg = Debug|x86 | |||||
{C82945B1-3D74-40E3-A16C-213BCED377E1}.Debug|x86.Build.0 = Debug|x86 | |||||
{C82945B1-3D74-40E3-A16C-213BCED377E1}.Release|Any CPU.ActiveCfg = Release|Any CPU | {C82945B1-3D74-40E3-A16C-213BCED377E1}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||
{C82945B1-3D74-40E3-A16C-213BCED377E1}.Release|Any CPU.Build.0 = Release|Any CPU | {C82945B1-3D74-40E3-A16C-213BCED377E1}.Release|Any CPU.Build.0 = Release|Any CPU | ||||
{C82945B1-3D74-40E3-A16C-213BCED377E1}.Release|x86.ActiveCfg = Release|x86 | |||||
{C82945B1-3D74-40E3-A16C-213BCED377E1}.Release|x86.Build.0 = Release|x86 | |||||
{CFA68AF9-1C11-41A3-8A73-34E004660CFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | {CFA68AF9-1C11-41A3-8A73-34E004660CFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||||
{CFA68AF9-1C11-41A3-8A73-34E004660CFC}.Debug|Any CPU.Build.0 = Debug|Any CPU | {CFA68AF9-1C11-41A3-8A73-34E004660CFC}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||
{CFA68AF9-1C11-41A3-8A73-34E004660CFC}.Debug|x86.ActiveCfg = Debug|x86 | |||||
{CFA68AF9-1C11-41A3-8A73-34E004660CFC}.Debug|x86.Build.0 = Debug|x86 | |||||
{CFA68AF9-1C11-41A3-8A73-34E004660CFC}.Release|Any CPU.ActiveCfg = Release|Any CPU | {CFA68AF9-1C11-41A3-8A73-34E004660CFC}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||
{CFA68AF9-1C11-41A3-8A73-34E004660CFC}.Release|Any CPU.Build.0 = Release|Any CPU | {CFA68AF9-1C11-41A3-8A73-34E004660CFC}.Release|Any CPU.Build.0 = Release|Any CPU | ||||
{CFA68AF9-1C11-41A3-8A73-34E004660CFC}.Release|x86.ActiveCfg = Release|x86 | |||||
{CFA68AF9-1C11-41A3-8A73-34E004660CFC}.Release|x86.Build.0 = Release|x86 | |||||
{F7A3683F-B767-427C-BCB8-7C5DA507D663}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |||||
{F7A3683F-B767-427C-BCB8-7C5DA507D663}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||||
{F7A3683F-B767-427C-BCB8-7C5DA507D663}.Debug|x86.ActiveCfg = Debug|x86 | |||||
{F7A3683F-B767-427C-BCB8-7C5DA507D663}.Debug|x86.Build.0 = Debug|x86 | |||||
{F7A3683F-B767-427C-BCB8-7C5DA507D663}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||||
{F7A3683F-B767-427C-BCB8-7C5DA507D663}.Release|Any CPU.Build.0 = Release|Any CPU | |||||
{F7A3683F-B767-427C-BCB8-7C5DA507D663}.Release|x86.ActiveCfg = Release|x86 | |||||
{F7A3683F-B767-427C-BCB8-7C5DA507D663}.Release|x86.Build.0 = Release|x86 | |||||
{3AD252E2-6878-4ABC-8A3E-22CCFCE2E075}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |||||
{3AD252E2-6878-4ABC-8A3E-22CCFCE2E075}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||||
{3AD252E2-6878-4ABC-8A3E-22CCFCE2E075}.Debug|x86.ActiveCfg = Debug|x86 | |||||
{3AD252E2-6878-4ABC-8A3E-22CCFCE2E075}.Debug|x86.Build.0 = Debug|x86 | |||||
{3AD252E2-6878-4ABC-8A3E-22CCFCE2E075}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||||
{3AD252E2-6878-4ABC-8A3E-22CCFCE2E075}.Release|Any CPU.Build.0 = Release|Any CPU | |||||
{3AD252E2-6878-4ABC-8A3E-22CCFCE2E075}.Release|x86.ActiveCfg = Release|x86 | |||||
{3AD252E2-6878-4ABC-8A3E-22CCFCE2E075}.Release|x86.Build.0 = Release|x86 | |||||
EndGlobalSection | EndGlobalSection | ||||
GlobalSection(SolutionProperties) = preSolution | GlobalSection(SolutionProperties) = preSolution | ||||
HideSolutionNode = FALSE | HideSolutionNode = FALSE | ||||
@@ -11,13 +11,20 @@ | |||||
<Copyright>Copyright © HBL 2022</Copyright> | <Copyright>Copyright © HBL 2022</Copyright> | ||||
<FileVersion>1.0.0.0</FileVersion> | <FileVersion>1.0.0.0</FileVersion> | ||||
<AssemblyVersion>1.0.0.0</AssemblyVersion> | <AssemblyVersion>1.0.0.0</AssemblyVersion> | ||||
<Platforms>AnyCPU;x86</Platforms> | |||||
</PropertyGroup> | </PropertyGroup> | ||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> | ||||
<DefineConstants>TRACE;Core</DefineConstants> | <DefineConstants>TRACE;Core</DefineConstants> | ||||
</PropertyGroup> | </PropertyGroup> | ||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x86'"> | |||||
<DefineConstants>TRACE;Core</DefineConstants> | |||||
</PropertyGroup> | |||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> | ||||
<DefineConstants>TRACE;Core</DefineConstants> | <DefineConstants>TRACE;Core</DefineConstants> | ||||
</PropertyGroup> | </PropertyGroup> | ||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x86'"> | |||||
<DefineConstants>TRACE;Core</DefineConstants> | |||||
</PropertyGroup> | |||||
<ItemGroup> | <ItemGroup> | ||||
<None Remove="HKResouces\头像.png" /> | <None Remove="HKResouces\头像.png" /> | ||||
<None Remove="HKResouces\背景.jpg" /> | <None Remove="HKResouces\背景.jpg" /> | ||||
@@ -12,13 +12,20 @@ | |||||
<Copyright>Copyright © HBL 2022</Copyright> | <Copyright>Copyright © HBL 2022</Copyright> | ||||
<FileVersion>1.0.0.0</FileVersion> | <FileVersion>1.0.0.0</FileVersion> | ||||
<AssemblyVersion>1.0.0.0</AssemblyVersion> | <AssemblyVersion>1.0.0.0</AssemblyVersion> | ||||
<Platforms>AnyCPU;x86</Platforms> | |||||
</PropertyGroup> | </PropertyGroup> | ||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> | ||||
<DefineConstants>TRACE;Core</DefineConstants> | <DefineConstants>TRACE;Core</DefineConstants> | ||||
</PropertyGroup> | </PropertyGroup> | ||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x86'"> | |||||
<DefineConstants>TRACE;Core</DefineConstants> | |||||
</PropertyGroup> | |||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> | ||||
<DefineConstants>TRACE;Core</DefineConstants> | <DefineConstants>TRACE;Core</DefineConstants> | ||||
</PropertyGroup> | </PropertyGroup> | ||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x86'"> | |||||
<DefineConstants>TRACE;Core</DefineConstants> | |||||
</PropertyGroup> | |||||
<ItemGroup> | <ItemGroup> | ||||
<None Remove="HKResouces\背景.jpg" /> | <None Remove="HKResouces\背景.jpg" /> | ||||
</ItemGroup> | </ItemGroup> | ||||
@@ -4,6 +4,7 @@ | |||||
<TargetFramework>net6.0</TargetFramework> | <TargetFramework>net6.0</TargetFramework> | ||||
<ImplicitUsings>enable</ImplicitUsings> | <ImplicitUsings>enable</ImplicitUsings> | ||||
<Nullable>enable</Nullable> | <Nullable>enable</Nullable> | ||||
<Platforms>AnyCPU;x86</Platforms> | |||||
</PropertyGroup> | </PropertyGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
@@ -4,6 +4,7 @@ | |||||
<TargetFramework>net6.0</TargetFramework> | <TargetFramework>net6.0</TargetFramework> | ||||
<ImplicitUsings>enable</ImplicitUsings> | <ImplicitUsings>enable</ImplicitUsings> | ||||
<Nullable>enable</Nullable> | <Nullable>enable</Nullable> | ||||
<Platforms>AnyCPU;x86</Platforms> | |||||
</PropertyGroup> | </PropertyGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
@@ -4,6 +4,7 @@ | |||||
<TargetFramework>net6.0</TargetFramework> | <TargetFramework>net6.0</TargetFramework> | ||||
<ImplicitUsings>enable</ImplicitUsings> | <ImplicitUsings>enable</ImplicitUsings> | ||||
<Nullable>enable</Nullable> | <Nullable>enable</Nullable> | ||||
<Platforms>AnyCPU;x86</Platforms> | |||||
</PropertyGroup> | </PropertyGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
@@ -0,0 +1,310 @@ | |||||
using ReaderB; | |||||
using System.Text; | |||||
namespace UHFHelper | |||||
{ | |||||
public class UHFCardHelper | |||||
{ | |||||
/// <summary> | |||||
/// 单例模式 | |||||
/// </summary> | |||||
private static UHFCardHelper? Instance { get; set; } | |||||
private UHFCardHelper() | |||||
{ | |||||
} | |||||
public static UHFCardHelper GetInstance() | |||||
{ | |||||
if (Instance == null) | |||||
{ | |||||
Instance = new UHFCardHelper(); | |||||
} | |||||
return Instance; | |||||
} | |||||
//当前操作的ComAdr | |||||
private byte fComAdr = 0xff; | |||||
//返回串口的索引号 | |||||
private int frmcomportindex; | |||||
/// <summary> | |||||
/// 打开的COM口号 | |||||
/// </summary> | |||||
public int OpenComNo { get; set; } | |||||
//所有执行指令的返回值 | |||||
private int fCmdRet { get; set; } = 30; | |||||
/// <summary> | |||||
/// 串口打开标示 | |||||
/// </summary> | |||||
public bool ComOpen { get; set; } = false; | |||||
/// <summary> | |||||
/// 密码 | |||||
/// </summary> | |||||
private byte[] fPassWord = new byte[4]; | |||||
/// <summary> | |||||
/// 错误码 | |||||
/// </summary> | |||||
private int ferrorcode; | |||||
//定义Timer类 | |||||
private System.Timers.Timer timer; | |||||
//定义委托 | |||||
public delegate void SetControlValue(string value); | |||||
private void InitTimer() | |||||
{ | |||||
int interval = 1000; | |||||
timer = new System.Timers.Timer(interval); | |||||
timer.AutoReset = true; | |||||
timer.Enabled = true; | |||||
//绑定事件,每隔一秒执行一次此方法 | |||||
timer.Elapsed += new System.Timers.ElapsedEventHandler(MyMethod); | |||||
} | |||||
private void MyMethod(object sender, System.Timers.ElapsedEventArgs e) | |||||
{ | |||||
//TODO 持续扫码 | |||||
} | |||||
/// <summary> | |||||
/// 打开串口 | |||||
/// </summary> | |||||
/// <returns></returns> | |||||
public Resultoutput OpenPort() | |||||
{ | |||||
int port = 0; | |||||
int openresult; | |||||
fComAdr = Convert.ToByte("FF", 16); // $FF; | |||||
try | |||||
{ | |||||
openresult = StaticClassReaderB.AutoOpenComPort(ref port, ref fComAdr, 5, ref frmcomportindex); | |||||
OpenComNo = frmcomportindex; | |||||
if (openresult == 0) | |||||
{ | |||||
ComOpen = true; | |||||
//自动执行读取写卡器信息 | |||||
byte[] TrType = new byte[2]; | |||||
byte[] VersionInfo = new byte[2]; | |||||
byte ReaderType = 0; | |||||
byte ScanTime = 0; | |||||
byte dmaxfre = 0; | |||||
byte dminfre = 0; | |||||
byte powerdBm = 0; | |||||
fCmdRet = StaticClassReaderB.GetReaderInformation(ref fComAdr, VersionInfo, ref ReaderType, TrType, ref dmaxfre, ref dminfre, ref powerdBm, ref ScanTime, frmcomportindex); | |||||
if ((fCmdRet == 0x35) | (fCmdRet == 0x30)) | |||||
{ | |||||
StaticClassReaderB.CloseSpecComPort(frmcomportindex); | |||||
ComOpen = false; | |||||
return new Resultoutput { Res=false,ResMes= "串口通讯错误" }; | |||||
} | |||||
if ((OpenComNo == -1) && (openresult == 0x30)) | |||||
{ | |||||
return new Resultoutput { Res = false, ResMes = "串口通讯错误" }; | |||||
} | |||||
} | |||||
} | |||||
catch(Exception ex) { | |||||
return new Resultoutput { Res = false, ResMes = ex.ToString() }; | |||||
} | |||||
ComOpen = true; | |||||
//var result = WorkMode(); | |||||
//if (!result.Res) | |||||
//{ | |||||
// return result; | |||||
//} | |||||
return new Resultoutput { Res = true, ResMes = "串口打开成功" }; | |||||
} | |||||
/// <summary> | |||||
/// 关闭串口 | |||||
/// </summary> | |||||
/// <returns></returns> | |||||
public Resultoutput ClosePort() | |||||
{ | |||||
fCmdRet = StaticClassReaderB.CloseSpecComPort(OpenComNo); | |||||
if (fCmdRet == 0) | |||||
{ | |||||
ComOpen = false; | |||||
} | |||||
else | |||||
{ | |||||
return new Resultoutput { Res = false, ResMes = "串口关闭失败" }; | |||||
} | |||||
return new Resultoutput { Res = true, ResMes = "串口关闭成功" }; | |||||
} | |||||
/// <summary> | |||||
/// 设置工作模式 | |||||
/// </summary> | |||||
public Resultoutput WorkMode() | |||||
{ | |||||
byte[] Parameter = new byte[6]; | |||||
//应答模式 | |||||
Parameter[0] = Convert.ToByte(0); | |||||
//工作模式 EPCC1 ISO18000-6B | |||||
int Reader_bit0 = 0; | |||||
//输出模式 | |||||
int Reader_bit1 = 0; | |||||
//蜂鸣开关 | |||||
int Reader_bit2 = 0; | |||||
//起始地址 | |||||
int Reader_bit3 = 0; | |||||
//是否SYRIS485输出 | |||||
int Reader_bit4 = 0; | |||||
Parameter[1] = Convert.ToByte(Reader_bit0 * 1 + Reader_bit1 * 2 + Reader_bit2 * 4 + Reader_bit3 * 8 + Reader_bit4 * 16); | |||||
//存储区 EPC区 | |||||
Parameter[2] = 1; | |||||
//起始字地址(Hex) | |||||
Parameter[3] = Convert.ToByte("02", 16); | |||||
//读取字数 | |||||
Parameter[4] = Convert.ToByte(1); | |||||
//单张标签过滤时间 | |||||
Parameter[5] = Convert.ToByte(0); | |||||
//设置工作模式 | |||||
fCmdRet = StaticClassReaderB.SetWorkMode(ref fComAdr, Parameter, frmcomportindex); | |||||
if (fCmdRet == 0) | |||||
{ | |||||
return new Resultoutput { Res = true, ResMes = "工作模式设置成功" }; | |||||
} | |||||
return new Resultoutput { Res = false, ResMes = "读卡失败" }; | |||||
} | |||||
/// <summary> | |||||
/// 读卡 | |||||
/// </summary> | |||||
/// <returns></returns> | |||||
public string ReadCard() | |||||
{ | |||||
int CardNum = 0; | |||||
int Totallen = 0; | |||||
int EPClen, m; | |||||
byte[] EPC = new byte[5000]; | |||||
string temps; | |||||
string sEPC; | |||||
//fIsInventoryScan = true; | |||||
byte AdrTID = 0; | |||||
byte LenTID = 0; | |||||
byte TIDFlag = 0; | |||||
AdrTID = 0; | |||||
LenTID = 0; | |||||
TIDFlag = 0; | |||||
fCmdRet = StaticClassReaderB.Inventory_G2(ref fComAdr, AdrTID, LenTID, TIDFlag, EPC, ref Totallen, ref CardNum, frmcomportindex); | |||||
if ((fCmdRet == 1) | (fCmdRet == 2) | (fCmdRet == 3) | (fCmdRet == 4) | (fCmdRet == 0xFB))//代表已查找结束, | |||||
{ | |||||
byte[] daw = new byte[Totallen]; | |||||
Array.Copy(EPC, daw, Totallen); | |||||
temps = ByteArrayToHexString(daw); | |||||
m = 0; | |||||
if (CardNum == 0) | |||||
{ | |||||
return ""; | |||||
} | |||||
for (int CardIndex = 0; CardIndex < CardNum; CardIndex++) | |||||
{ | |||||
EPClen = daw[m]; | |||||
sEPC = temps.Substring(m * 2 + 2, EPClen * 2); | |||||
m = m + EPClen + 1; | |||||
if (sEPC.Length != EPClen * 2) | |||||
{ | |||||
return ""; | |||||
} | |||||
string cardcode = sEPC.Substring(1, sEPC.Length-1); | |||||
return cardcode; | |||||
} | |||||
} | |||||
return ""; | |||||
} | |||||
/// <summary> | |||||
/// 写卡 | |||||
/// </summary> | |||||
/// <returns></returns> | |||||
public Resultoutput WriteCard(string CardCodeStr) | |||||
{ | |||||
byte[] WriteEPC = new byte[100]; | |||||
byte WriteEPClen; | |||||
byte ENum; | |||||
string AccessCode = "00000000"; | |||||
try | |||||
{ | |||||
string CardCode = CardCodeStr; | |||||
if ((CardCode.Length % 4) != 0) | |||||
{ | |||||
CardCode = "0" + CardCodeStr; | |||||
} | |||||
WriteEPClen = Convert.ToByte(CardCode.Length / 2); | |||||
ENum = Convert.ToByte(CardCode.Length / 4); | |||||
byte[] EPC = new byte[ENum]; | |||||
EPC = HexStringToByteArray(CardCode); | |||||
fPassWord = HexStringToByteArray(AccessCode); | |||||
fCmdRet = StaticClassReaderB.WriteEPC_G2(ref fComAdr, fPassWord, EPC, WriteEPClen, ref ferrorcode, frmcomportindex); | |||||
if (fCmdRet == 0) | |||||
{ | |||||
return new Resultoutput { Res = true, ResMes = "写卡成功!" }; | |||||
} | |||||
else | |||||
{ | |||||
return new Resultoutput { Res = false, ResMes = "写卡失败!错误码:" + ferrorcode }; | |||||
} | |||||
} | |||||
catch (Exception ex) | |||||
{ | |||||
return new Resultoutput { Res = false, ResMes = "写卡失败"+ ex.Message }; | |||||
} | |||||
} | |||||
/// <summary> | |||||
/// 解析数据 | |||||
/// </summary> | |||||
/// <param name="s"></param> | |||||
/// <returns></returns> | |||||
private byte[] HexStringToByteArray(string s) | |||||
{ | |||||
s = s.Replace(" ", ""); | |||||
byte[] buffer = new byte[s.Length / 2]; | |||||
for (int i = 0; i < s.Length; i += 2) | |||||
buffer[i / 2] = (byte)Convert.ToByte(s.Substring(i, 2), 16); | |||||
return buffer; | |||||
} | |||||
/// <summary> | |||||
/// 解析数据 | |||||
/// </summary> | |||||
/// <param name="data"></param> | |||||
/// <returns></returns> | |||||
private string ByteArrayToHexString(byte[] data) | |||||
{ | |||||
StringBuilder sb = new(data.Length * 3); | |||||
foreach (byte b in data) | |||||
sb.Append(Convert.ToString(b, 16).PadLeft(2, '0')); | |||||
return sb.ToString().ToUpper(); | |||||
} | |||||
/// <summary> | |||||
/// 字符串转16进制 | |||||
/// </summary> | |||||
/// <param name="strEncode"></param> | |||||
/// <returns></returns> | |||||
public string ToEncode16(string strEncode) | |||||
{ | |||||
byte[] b = Encoding.UTF8.GetBytes(strEncode);//按照指定编码将string编程字节数组 | |||||
string result = string.Empty; | |||||
for (int i = 0; i < b.Length; i++)//逐字节变为16进制字符 | |||||
{ | |||||
result += Convert.ToString(b[i], 16); | |||||
} | |||||
return result; | |||||
} | |||||
/// <summary> | |||||
/// 16进制转字符串 | |||||
/// </summary> | |||||
/// <param name="strEncode"></param> | |||||
/// <returns></returns> | |||||
public string ToEncodeString(string strDecode) | |||||
{ | |||||
string strTemp = ""; | |||||
byte[] b = new byte[strDecode.Length / 2]; | |||||
for (int i = 0; i < strDecode.Length / 2; i++) | |||||
{ | |||||
strTemp = strDecode.Substring(i * 2, 2); | |||||
b[i] = Convert.ToByte(strTemp, 16); | |||||
} | |||||
//按照指定编码将字节数组变为字符串 | |||||
return Encoding.UTF8.GetString(b); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,18 @@ | |||||
namespace UHFHelper | |||||
{ | |||||
public class Resultoutput | |||||
{ | |||||
public bool Res { get; set; } | |||||
public string? ResMes { get; set; } | |||||
} | |||||
/// <summary> | |||||
/// 蜂鸣开关 | |||||
/// </summary> | |||||
public enum Beep | |||||
{ | |||||
open=0, | |||||
close=1, | |||||
} | |||||
} |
@@ -0,0 +1,16 @@ | |||||
<Project Sdk="Microsoft.NET.Sdk"> | |||||
<PropertyGroup> | |||||
<TargetFramework>net6.0</TargetFramework> | |||||
<ImplicitUsings>enable</ImplicitUsings> | |||||
<Nullable>enable</Nullable> | |||||
<Platforms>AnyCPU;x86</Platforms> | |||||
</PropertyGroup> | |||||
<ItemGroup> | |||||
<Reference Include="UHFReader18CSharp"> | |||||
<HintPath>..\lib\UHFReader18CSharp.dll</HintPath> | |||||
</Reference> | |||||
</ItemGroup> | |||||
</Project> |
@@ -0,0 +1,122 @@ | |||||
namespace test | |||||
{ | |||||
partial class Form1 | |||||
{ | |||||
/// <summary> | |||||
/// Required designer variable. | |||||
/// </summary> | |||||
private System.ComponentModel.IContainer components = null; | |||||
/// <summary> | |||||
/// Clean up any resources being used. | |||||
/// </summary> | |||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> | |||||
protected override void Dispose(bool disposing) | |||||
{ | |||||
if (disposing && (components != null)) | |||||
{ | |||||
components.Dispose(); | |||||
} | |||||
base.Dispose(disposing); | |||||
} | |||||
#region Windows Form Designer generated code | |||||
/// <summary> | |||||
/// Required method for Designer support - do not modify | |||||
/// the contents of this method with the code editor. | |||||
/// </summary> | |||||
private void InitializeComponent() | |||||
{ | |||||
this.button1 = new System.Windows.Forms.Button(); | |||||
this.button2 = new System.Windows.Forms.Button(); | |||||
this.label1 = new System.Windows.Forms.Label(); | |||||
this.button3 = new System.Windows.Forms.Button(); | |||||
this.button4 = new System.Windows.Forms.Button(); | |||||
this.textBox1 = new System.Windows.Forms.TextBox(); | |||||
this.SuspendLayout(); | |||||
// | |||||
// button1 | |||||
// | |||||
this.button1.Location = new System.Drawing.Point(55, 37); | |||||
this.button1.Name = "button1"; | |||||
this.button1.Size = new System.Drawing.Size(75, 23); | |||||
this.button1.TabIndex = 0; | |||||
this.button1.Text = "初始化"; | |||||
this.button1.UseVisualStyleBackColor = true; | |||||
this.button1.Click += new System.EventHandler(this.button1_Click); | |||||
// | |||||
// button2 | |||||
// | |||||
this.button2.Location = new System.Drawing.Point(55, 131); | |||||
this.button2.Name = "button2"; | |||||
this.button2.Size = new System.Drawing.Size(75, 23); | |||||
this.button2.TabIndex = 1; | |||||
this.button2.Text = "读卡"; | |||||
this.button2.UseVisualStyleBackColor = true; | |||||
this.button2.Click += new System.EventHandler(this.button2_Click); | |||||
// | |||||
// label1 | |||||
// | |||||
this.label1.AutoSize = true; | |||||
this.label1.Location = new System.Drawing.Point(178, 134); | |||||
this.label1.Name = "label1"; | |||||
this.label1.Size = new System.Drawing.Size(43, 17); | |||||
this.label1.TabIndex = 2; | |||||
this.label1.Text = "label1"; | |||||
// | |||||
// button3 | |||||
// | |||||
this.button3.Location = new System.Drawing.Point(178, 37); | |||||
this.button3.Name = "button3"; | |||||
this.button3.Size = new System.Drawing.Size(75, 23); | |||||
this.button3.TabIndex = 0; | |||||
this.button3.Text = "关闭串口"; | |||||
this.button3.UseVisualStyleBackColor = true; | |||||
this.button3.Click += new System.EventHandler(this.button3_Click); | |||||
// | |||||
// button4 | |||||
// | |||||
this.button4.Location = new System.Drawing.Point(178, 203); | |||||
this.button4.Name = "button4"; | |||||
this.button4.Size = new System.Drawing.Size(75, 23); | |||||
this.button4.TabIndex = 3; | |||||
this.button4.Text = "写卡"; | |||||
this.button4.UseVisualStyleBackColor = true; | |||||
this.button4.Click += new System.EventHandler(this.button4_Click); | |||||
// | |||||
// textBox1 | |||||
// | |||||
this.textBox1.Location = new System.Drawing.Point(55, 203); | |||||
this.textBox1.Name = "textBox1"; | |||||
this.textBox1.Size = new System.Drawing.Size(100, 23); | |||||
this.textBox1.TabIndex = 4; | |||||
// | |||||
// Form1 | |||||
// | |||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F); | |||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; | |||||
this.ClientSize = new System.Drawing.Size(800, 450); | |||||
this.Controls.Add(this.textBox1); | |||||
this.Controls.Add(this.button4); | |||||
this.Controls.Add(this.label1); | |||||
this.Controls.Add(this.button2); | |||||
this.Controls.Add(this.button3); | |||||
this.Controls.Add(this.button1); | |||||
this.Name = "Form1"; | |||||
this.Text = "Form1"; | |||||
this.ResumeLayout(false); | |||||
this.PerformLayout(); | |||||
} | |||||
#endregion | |||||
private Button button1; | |||||
private Button button2; | |||||
private Label label1; | |||||
private Button button3; | |||||
private Button button4; | |||||
private TextBox textBox1; | |||||
} | |||||
} |
@@ -0,0 +1,51 @@ | |||||
using UHFHelper; | |||||
namespace test | |||||
{ | |||||
public partial class Form1 : Form | |||||
{ | |||||
public Form1() | |||||
{ | |||||
InitializeComponent(); | |||||
} | |||||
private void button1_Click(object sender, EventArgs e) | |||||
{ | |||||
//判断串口是否打开 | |||||
if (!UHFCardHelper.GetInstance().ComOpen) | |||||
{ | |||||
Resultoutput resultoutput = UHFCardHelper.GetInstance().OpenPort(); | |||||
if (resultoutput.Res) | |||||
{ | |||||
MessageBox.Show(resultoutput.ResMes); | |||||
} | |||||
else | |||||
{ | |||||
MessageBox.Show(resultoutput.ResMes); | |||||
} | |||||
} | |||||
} | |||||
private void button2_Click(object sender, EventArgs e) | |||||
{ | |||||
if (!UHFCardHelper.GetInstance().ComOpen) | |||||
{ | |||||
MessageBox.Show("串口未打开"); | |||||
return; | |||||
} | |||||
string res = UHFCardHelper.GetInstance().ReadCard(); | |||||
label1.Text = res; | |||||
} | |||||
private void button3_Click(object sender, EventArgs e) | |||||
{ | |||||
UHFCardHelper.GetInstance().ClosePort(); | |||||
} | |||||
private void button4_Click(object sender, EventArgs e) | |||||
{ | |||||
var res = UHFCardHelper.GetInstance().WriteCard(textBox1.Text); | |||||
MessageBox.Show(res.ResMes); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,60 @@ | |||||
<root> | |||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> | |||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> | |||||
<xsd:element name="root" msdata:IsDataSet="true"> | |||||
<xsd:complexType> | |||||
<xsd:choice maxOccurs="unbounded"> | |||||
<xsd:element name="metadata"> | |||||
<xsd:complexType> | |||||
<xsd:sequence> | |||||
<xsd:element name="value" type="xsd:string" minOccurs="0" /> | |||||
</xsd:sequence> | |||||
<xsd:attribute name="name" use="required" type="xsd:string" /> | |||||
<xsd:attribute name="type" type="xsd:string" /> | |||||
<xsd:attribute name="mimetype" type="xsd:string" /> | |||||
<xsd:attribute ref="xml:space" /> | |||||
</xsd:complexType> | |||||
</xsd:element> | |||||
<xsd:element name="assembly"> | |||||
<xsd:complexType> | |||||
<xsd:attribute name="alias" type="xsd:string" /> | |||||
<xsd:attribute name="name" type="xsd:string" /> | |||||
</xsd:complexType> | |||||
</xsd:element> | |||||
<xsd:element name="data"> | |||||
<xsd:complexType> | |||||
<xsd:sequence> | |||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> | |||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> | |||||
</xsd:sequence> | |||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> | |||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> | |||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> | |||||
<xsd:attribute ref="xml:space" /> | |||||
</xsd:complexType> | |||||
</xsd:element> | |||||
<xsd:element name="resheader"> | |||||
<xsd:complexType> | |||||
<xsd:sequence> | |||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> | |||||
</xsd:sequence> | |||||
<xsd:attribute name="name" type="xsd:string" use="required" /> | |||||
</xsd:complexType> | |||||
</xsd:element> | |||||
</xsd:choice> | |||||
</xsd:complexType> | |||||
</xsd:element> | |||||
</xsd:schema> | |||||
<resheader name="resmimetype"> | |||||
<value>text/microsoft-resx</value> | |||||
</resheader> | |||||
<resheader name="version"> | |||||
<value>2.0</value> | |||||
</resheader> | |||||
<resheader name="reader"> | |||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | |||||
</resheader> | |||||
<resheader name="writer"> | |||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | |||||
</resheader> | |||||
</root> |
@@ -0,0 +1,17 @@ | |||||
namespace test | |||||
{ | |||||
internal static class Program | |||||
{ | |||||
/// <summary> | |||||
/// The main entry point for the application. | |||||
/// </summary> | |||||
[STAThread] | |||||
static void Main() | |||||
{ | |||||
// To customize application configuration such as set high DPI settings or default font, | |||||
// see https://aka.ms/applicationconfiguration. | |||||
ApplicationConfiguration.Initialize(); | |||||
Application.Run(new Form1()); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,22 @@ | |||||
<Project Sdk="Microsoft.NET.Sdk"> | |||||
<PropertyGroup> | |||||
<OutputType>WinExe</OutputType> | |||||
<TargetFramework>net6.0-windows</TargetFramework> | |||||
<Nullable>enable</Nullable> | |||||
<UseWindowsForms>true</UseWindowsForms> | |||||
<ImplicitUsings>enable</ImplicitUsings> | |||||
<Platforms>AnyCPU;x86</Platforms> | |||||
</PropertyGroup> | |||||
<ItemGroup> | |||||
<ProjectReference Include="..\UHFHelper\UHFHelper.csproj" /> | |||||
</ItemGroup> | |||||
<ItemGroup> | |||||
<Reference Include="UHFReader18CSharp"> | |||||
<HintPath>..\lib\UHFReader18CSharp.dll</HintPath> | |||||
</Reference> | |||||
</ItemGroup> | |||||
</Project> |