Commit a0b46654 by zxw

打印程序集成索力得读写器

parent 58868809
...@@ -50,4 +50,4 @@ using System.Windows; ...@@ -50,4 +50,4 @@ using System.Windows;
//通过使用 "*",如下所示: //通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.19.11281")] [assembly: AssemblyVersion("1.2.19.11281")]
[assembly: AssemblyFileVersion("1.2.19.11281")] [assembly: AssemblyFileVersion("1.2.20.01030")]
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<LangVersion>latest</LangVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
...@@ -31,6 +32,7 @@ ...@@ -31,6 +32,7 @@
<DefineConstants>TRACE</DefineConstants> <DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<LangVersion>latest</LangVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<StartupObject /> <StartupObject />
...@@ -75,6 +77,7 @@ ...@@ -75,6 +77,7 @@
<ItemGroup> <ItemGroup>
<Compile Include="InitializeModel.cs" /> <Compile Include="InitializeModel.cs" />
<Compile Include="Log.cs" /> <Compile Include="Log.cs" />
<Compile Include="IReaderHelper.cs" />
<Compile Include="UhfService.cs"> <Compile Include="UhfService.cs">
<SubType>Component</SubType> <SubType>Component</SubType>
</Compile> </Compile>
...@@ -90,6 +93,7 @@ ...@@ -90,6 +93,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="fix.ico" /> <Content Include="fix.ico" />
<Content Include="ThirdPackages\USBUHFPlatform.dll" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\JmpZbModel\JmpZbModel.csproj"> <ProjectReference Include="..\JmpZbModel\JmpZbModel.csproj">
...@@ -98,4 +102,7 @@ ...@@ -98,4 +102,7 @@
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>xcopy $(ProjectDir)ThirdPackages\* $(TargetDir) /S /Y</PostBuildEvent>
</PropertyGroup>
</Project> </Project>
\ No newline at end of file
...@@ -6,12 +6,14 @@ using Newtonsoft.Json; ...@@ -6,12 +6,14 @@ using Newtonsoft.Json;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Configuration;
using System.Data; using System.Data;
using System.Diagnostics; using System.Diagnostics;
using System.Globalization; using System.Globalization;
using System.IO.Ports; using System.IO.Ports;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Runtime.Remoting.Messaging;
using System.ServiceProcess; using System.ServiceProcess;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
...@@ -30,7 +32,9 @@ namespace JmpUhfService ...@@ -30,7 +32,9 @@ namespace JmpUhfService
//private LinkageExtend link = new LinkageExtend(); //private LinkageExtend link = new LinkageExtend();
//private List<rfidLink.Extend.RadioInformation> radios; //private List<rfidLink.Extend.RadioInformation> radios;
private Reader reader; private IReaderHelper reader;
private JmpRfidLpReaderHelper reader1;
private USBRFIDReaderHelper reader2;
private Task taskDevice; private Task taskDevice;
private CancellationTokenSource cDeviceToken; private CancellationTokenSource cDeviceToken;
private WebSocketServer server; private WebSocketServer server;
...@@ -325,10 +329,10 @@ namespace JmpUhfService ...@@ -325,10 +329,10 @@ namespace JmpUhfService
reader.InventoryStop(); reader.InventoryStop();
//单次盘点,确认无其他标签 //单次盘点,确认无其他标签
var tmpList = new List<TagInfo>(); var tmpList = new List<TagInfoData>();
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
{ {
reader.InventorySingle(50).ForEach(s => reader.InventorySingle().ForEach(s =>
{ {
if (!tmpList.Any(t => t.EPC == s.EPC)) if (!tmpList.Any(t => t.EPC == s.EPC))
{ {
...@@ -351,18 +355,18 @@ namespace JmpUhfService ...@@ -351,18 +355,18 @@ namespace JmpUhfService
//} //}
else else
{ {
OperData _oper = new OperData var _oper = new OperatingData()
{ {
EPC = "", EPC = "",
DATA = "8000" + data.Epc, DATA = "8000" + data.Epc,
Offset = data.Offset, Offset = data.Offset,
Length = data.Len, Length = data.Len,
Bank = BankType.EPC, Bank = RfidBankType.EPC,
Access = "00000000" Access = "00000000"
}; };
var res = reader.WriteTag(_oper); var res = reader.WriteTag(_oper);
if (res == OperResult.OK) if (res.Item1 == 0)
{ {
OnSendMsg(client, InitializeCmdType.Initialize, "成功" + data.Epc); OnSendMsg(client, InitializeCmdType.Initialize, "成功" + data.Epc);
} }
...@@ -394,14 +398,14 @@ namespace JmpUhfService ...@@ -394,14 +398,14 @@ namespace JmpUhfService
{ {
var tid = ""; var tid = "";
//读取tid //读取tid
var tag = new OperData var tag = new OperatingData()
{ {
Offset = 0, Offset = 0,
Length = 6, Length = 6,
Bank = BankType.TID, Bank = RfidBankType.TID,
Access = "00000000" Access = "00000000"
}; };
if (reader.ReadTag(ref tag) == OperResult.OK) if (reader.ReadTag(ref tag).Item1 == 0)
{ {
tid = tag.DATA; tid = tag.DATA;
} }
...@@ -421,18 +425,18 @@ namespace JmpUhfService ...@@ -421,18 +425,18 @@ namespace JmpUhfService
reader.InventoryStop(); reader.InventoryStop();
//不进行盘点,认为无其他标签(调用之前自行判断是否能写入) //不进行盘点,认为无其他标签(调用之前自行判断是否能写入)
OperData _oper = new OperData var _oper = new OperatingData()
{ {
EPC = "", EPC = "",
DATA = "8000" + data.Epc, DATA = "8000" + data.Epc,
Offset = data.Offset, Offset = data.Offset,
Length = data.Len, Length = data.Len,
Bank = BankType.EPC, Bank = RfidBankType.EPC,
Access = "00000000" Access = "00000000"
}; };
var res = reader.WriteTag(_oper); var res = reader.WriteTag(_oper);
if (res == OperResult.OK) if (res.Item1 == 0)//成功
{ {
OnSendMsg(client, InitializeCmdType.Initialize, "成功" + data.Epc + "|" + tid); OnSendMsg(client, InitializeCmdType.Initialize, "成功" + data.Epc + "|" + tid);
} }
...@@ -452,10 +456,10 @@ namespace JmpUhfService ...@@ -452,10 +456,10 @@ namespace JmpUhfService
protected void ReadInventorySingle(string client) protected void ReadInventorySingle(string client)
{ {
var tmpList = new List<TagInfo>(); var tmpList = new List<TagInfoData>();
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
{ {
reader.InventorySingle(50).ForEach(s => reader.InventorySingle().ForEach(s =>
{ {
if (tmpList.All(t => t.EPC != s.EPC)) if (tmpList.All(t => t.EPC != s.EPC))
{ {
...@@ -480,20 +484,27 @@ namespace JmpUhfService ...@@ -480,20 +484,27 @@ namespace JmpUhfService
#endregion #endregion
#region uhf inventory method #region uhf inventory method
private void ConnectReader() private void ConnectReader(int type = 0)
{ {
try try
{ {
reader = new Reader("COM4"); //钧普读写器
reader.OnInventory += OnRadioInventory; reader1 ??= new JmpRfidLpReaderHelper("COM4");
var state = reader.Open();
//索力得读写器
reader2 ??= new USBRFIDReaderHelper();
var state = type == 0 ? reader1.Open() : reader2.Open();
deviceStatus = state ? DeviceStatus.已连接 : DeviceStatus.未连接; deviceStatus = state ? DeviceStatus.已连接 : DeviceStatus.未连接;
if (state) if (state)
{ {
reader = type == 0 ? reader1 : reader2;
reader.InventoryStop(); reader.InventoryStop();
reader.SetPALevel(1); reader.SetPALevel(1);
reader.SetTxPower(0, true, 24); reader.SetTxPower(0, true, 24);
reader.OnInventory += OnRadioInventory;
SendLinked(used_client); SendLinked(used_client);
} }
} }
...@@ -504,7 +515,7 @@ namespace JmpUhfService ...@@ -504,7 +515,7 @@ namespace JmpUhfService
Log.ErrorLog(ex.ToString(), MethodBase.GetCurrentMethod().Name); Log.ErrorLog(ex.ToString(), MethodBase.GetCurrentMethod().Name);
} }
} }
private void OnRadioInventory(TagInfo args) private void OnRadioInventory(TagInfoData args)
{ {
if (!epcList.Contains(args.EPC)) if (!epcList.Contains(args.EPC))
{ {
...@@ -517,7 +528,7 @@ namespace JmpUhfService ...@@ -517,7 +528,7 @@ namespace JmpUhfService
lock (syncObj) lock (syncObj)
{ {
epcList.Clear(); epcList.Clear();
if (deviceStatus == DeviceStatus.已连接) if (reader?.IsOpen() == true)
{ {
reader.InventoryStart(); reader.InventoryStart();
} }
...@@ -542,37 +553,38 @@ namespace JmpUhfService ...@@ -542,37 +553,38 @@ namespace JmpUhfService
{ {
try try
{ {
if (SerialPort.GetPortNames().Any(t => t.ToLower().Contains("com4"))) if (deviceStatus == DeviceStatus.未连接)
{ {
if (reader == null) //需要连接读写器
{ if (SerialPort.GetPortNames().Any(t => t.ToLower().Contains("com4")))
ConnectReader();
}
else if (deviceStatus == DeviceStatus.未连接)
{
var state = reader?.Open() ?? false;
if (state)
{ {
//设置功率 //钧普读写器
reader.SetPALevel(1); ConnectReader(0);
reader.SetTxPower(0, true, 24);
SendLinked(used_client);
} }
else else
{ {
reader = null; //尝试连接索力得读写器
deviceStatus = DeviceStatus.未连接; ConnectReader(1);
} }
if (reader == null)
{
//都连接失败,放弃
SendLinkError(used_client);
} }
else { }
} }
else else
{ {
//已连接,检查是否掉线
if (reader?.IsOpen() != true)
{
SendLinkError(used_client); SendLinkError(used_client);
reader?.InventoryStop(); reader?.InventoryStop();
reader?.Close(); reader?.Close();
reader = null; reader = null;
} }
}
if (resetEvent.WaitOne(5000)) if (resetEvent.WaitOne(5000))
{ {
break; break;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论