Commit 1e8500ca by zxw

充电台集成索力得读写器

温湿度接入
parent 3803bfa9
......@@ -111,7 +111,7 @@
this.ddb_warehouse.ImageTransparentColor = System.Drawing.Color.Magenta;
this.ddb_warehouse.Name = "ddb_warehouse";
this.ddb_warehouse.ShowDropDownArrow = false;
this.ddb_warehouse.Size = new System.Drawing.Size(204, 20);
this.ddb_warehouse.Size = new System.Drawing.Size(203, 20);
this.ddb_warehouse.Text = "当前仓库:未获取云端配置";
//
// btn_clear
......@@ -180,6 +180,7 @@
this.txt_log.Font = new System.Drawing.Font("幼圆", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.txt_log.Location = new System.Drawing.Point(0, 72);
this.txt_log.Name = "txt_log";
this.txt_log.ReadOnly = true;
this.txt_log.Size = new System.Drawing.Size(863, 395);
this.txt_log.TabIndex = 45;
this.txt_log.Text = "";
......
......@@ -152,38 +152,46 @@ namespace JmpServiceMgr
}
}
private class ColorLog
{
public string Text { get; set; }
public Color Color { get; set; }
}
private LinkedList<ColorLog> logList = new LinkedList<ColorLog>();
private readonly object _lockObj = new object();
public void SetLogs(string msg, Color color = default)
{
if (color == default)
{
color = Color.Black;
}
lock (_lockObj)
{
logList.AddFirst(new ColorLog
{
Color = color,
Text = $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")} - {msg}\r\n"
});
if (logList.Count > 100)
{
logList.RemoveLast();
}
}
this.Invoke((Action)delegate
{
if (txt_log.Text.Length > 30000)
txt_log.ResetText();
foreach (var colorLog in logList)
{
txt_log.ResetText();
txt_log.SelectionColor = colorLog.Color;
txt_log.AppendText(colorLog.Text);
}
var txt = $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")} - {msg}\r\n";
//txt_log.Text = txt_log.Text.Insert(0, txt);
AppendTextColorful(txt_log, txt, color, false);
txt_log.SelectionStart = 0;
txt_log.ScrollToCaret();
});
Application.DoEvents();
}
private void AppendTextColorful(RichTextBox rtBox, string text, Color color, bool addNewLine)
{
if (addNewLine)
{
text += Environment.NewLine;
}
rtBox.SelectionStart = rtBox.TextLength;
rtBox.SelectionLength = 0;
rtBox.SelectionColor = color;
rtBox.AppendText(text);
rtBox.SelectionColor = rtBox.ForeColor;
}
private void notifyIcon_MouseDoubleClick(object sender, MouseEventArgs e)
{
......

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30104.148
# Visual Studio Version 17
VisualStudioVersion = 17.4.33110.190
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JmpServiceMgr", "JmpServiceMgr\JmpServiceMgr.csproj", "{442DABC1-9869-4B57-BFCC-287106799248}"
EndProject
......@@ -15,6 +15,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LightCtrl", "LightCtrl\Ligh
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LiteChannelWinXP", "LiteChannelWinXP\LiteChannelWinXP.csproj", "{48900448-82F0-4876-9987-0AAB845027D5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TransmitterService", "TransmitterService\TransmitterService.csproj", "{FB7E4EB3-F9C2-42DA-89CC-D8831C462CB5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
......@@ -45,12 +47,16 @@ Global
{48900448-82F0-4876-9987-0AAB845027D5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{48900448-82F0-4876-9987-0AAB845027D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{48900448-82F0-4876-9987-0AAB845027D5}.Release|Any CPU.Build.0 = Release|Any CPU
{FB7E4EB3-F9C2-42DA-89CC-D8831C462CB5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FB7E4EB3-F9C2-42DA-89CC-D8831C462CB5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FB7E4EB3-F9C2-42DA-89CC-D8831C462CB5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FB7E4EB3-F9C2-42DA-89CC-D8831C462CB5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
VisualSVNWorkingCopyRoot = .
SolutionGuid = {F1BB736E-801B-4BAD-8BC5-A7BA50F023D7}
VisualSVNWorkingCopyRoot = .
EndGlobalSection
EndGlobal
using JmpRfidLp;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace LiteChannel.Commons
{
public interface IReaderHelper : IDisposable
{
event InvDelegate OnInventory;
delegate void InvDelegate(TagInfoData args);
bool Open();
bool Close();
bool IsOpen();
string GetFWVerion();
void InventoryStart();
void InventoryStop();
bool SetPALevel(byte level);
bool SetTxPower(byte port, bool enable, double power);
List<TagInfoData> InventorySingle();
Tuple<int, string> ReadTag(ref OperatingData tag);
Tuple<int, string> WriteTag(OperatingData tag);
}
public class TagInfoData
{
public string EPC { get; set; }
public int RSSI { get; set; }
public byte AntennaPort { get; set; }
public int SeenCount { get; set; }
}
public class OperatingData
{
public string EPC { get; set; }
public string DATA { get; set; }
public ushort Offset { get; set; }
public ushort Length { get; set; }
public RfidBankType Bank { get; set; }
public string Access { get; set; }
}
public enum RfidBankType
{
[Description("RFU")] RFU,
[Description("EPC")] EPC,
[Description("TID")] TID,
[Description("USER")] USER,
}
/// <summary>
/// 钧普读写器
/// </summary>
public class JmpRfidLpReaderHelper : IReaderHelper
{
public event IReaderHelper.InvDelegate OnInventory;
private Reader _reader;
public JmpRfidLpReaderHelper(string comPort = "COM3")
{
_reader = new Reader(comPort);
_reader.OnInventory += OnOnInventory;
}
public bool Open()
{
return _reader.Open();
}
public bool Close()
{
return _reader.Close();
}
public bool IsOpen()
{
return _reader.IsOpen();
}
public string GetFWVerion()
{
return _reader.GetFWVerion();
}
public void InventoryStart()
{
_reader.InventoryStart();
}
public void InventoryStop()
{
_reader.InventoryStop();
}
public bool SetPALevel(byte level)
{
return _reader.SetPALevel(level) == 0;
}
public bool SetTxPower(byte port, bool enable, double power)
{
return _reader.SetTxPower(port, enable, power) == 0;
}
public List<TagInfoData> InventorySingle()
{
return _reader.InventorySingle(50).Select(x => new TagInfoData
{
AntennaPort = x.AntennaPort,
EPC = x.EPC,
RSSI = x.RSSI,
SeenCount = x.SeenCount
}).ToList();
}
public Tuple<int, string> ReadTag(ref OperatingData tag)
{
var data = new OperData
{
Access = tag.Access ?? "00000000",
Bank = (BankType)tag.Bank,
DATA = tag.DATA ?? "",
EPC = tag.EPC ?? "",
Length = tag.Length,
Offset = tag.Offset
};
var res = _reader.ReadTag(ref data);
tag.Access = data.Access;
tag.Bank = (RfidBankType)data.Bank;
tag.DATA = data.DATA;
tag.EPC = data.EPC;
tag.Length = data.Length;
tag.Offset = data.Offset;
return new Tuple<int, string>((int)res, typeof(OperResult).GetEnumDesc((int)res));
}
public Tuple<int, string> WriteTag(OperatingData tag)
{
var data = new OperData
{
Access = tag.Access ?? "00000000",
Bank = (BankType)tag.Bank,
DATA = tag.DATA ?? "",
EPC = tag.EPC ?? "",
Length = tag.Length,
Offset = tag.Offset
};
var res = _reader.WriteTag(data);
return new Tuple<int, string>((int)res, typeof(OperResult).GetEnumDesc((int)res));
}
protected virtual void OnOnInventory(TagInfo args)
{
OnInventory?.Invoke(new TagInfoData()
{
AntennaPort = args.AntennaPort,
EPC = args.EPC,
RSSI = args.RSSI,
SeenCount = args.SeenCount
});
}
public void Dispose()
{
_reader.OnInventory -= OnOnInventory;
_reader = null;
}
}
/// <summary>
/// 索力得USBRFID读写器
/// </summary>
public class USBRFIDReaderHelper : IReaderHelper
{
private int _portHandle = -1;
private bool _isOpen = false;
private ManualResetEvent inventoryEvent = new ManualResetEvent(true);
private CancellationTokenSource _token;
public event IReaderHelper.InvDelegate OnInventory;
public USBRFIDReaderHelper()
{
}
public bool Open()
{
var res = OpenUSBPort(null, ref _portHandle);
if (res == 0)
{
_isOpen = true;
return true;
}
else
{
_isOpen = false;
Log.WorkLog("连接读写器失败:0x" + res.ToString("X2"), "读写器启动失败");
return false;
}
}
public bool Close()
{
_isOpen = false;
return CloseUSBPort(_portHandle) == 0;
}
public bool IsOpen()
{
return _isOpen;
}
public string GetFWVerion()
{
byte TrType = 0;
byte[] VersionInfo = new byte[2];
byte ReaderType = 0;
byte ScanTime = 0;
byte dfreband = 0;
byte dmaxfre = 0;
byte dminfre = 0;
byte powerdBm = 0;
byte Ant = 0;
byte BeepEn = 0;
byte CheckAnt = 0;
var res = GetReaderInfo(VersionInfo, ref ReaderType, ref TrType, ref dfreband, ref dmaxfre, ref dminfre, ref powerdBm, ref ScanTime, ref Ant, ref BeepEn, ref CheckAnt, _portHandle);
if (res == 0)
{
return string.Format("{0}.{1:d2}", VersionInfo[0], VersionInfo[1]);
}
else
{
if (res == 0x30)
{
//通讯失败,掉线
_isOpen = false;
}
return "";
}
}
public void InventoryStart()
{
//开启盘点线程
_token = new CancellationTokenSource();
Task.Run(() =>
{
int totalLen = 0, cardNum = 0, fCmdRet = 0x30;
int cardIdx = 0, epcLen = 0;
int i;
byte MaskMem = 0;
byte[] MaskAdr = new byte[2];
byte MaskLen = 0;
byte[] MaskData = null;
byte MaskFlag = 0;
byte[] EPCList = new byte[30000];
byte Ant = 0;
byte AdrTID = 0;
byte LenTID = 0;
byte TIDFlag = 0;
byte FastFlag = 1;
byte QValue = 4; //Q值 4
byte Session = 0; //Session 0
byte Target = 0; //Target A
byte Scantime = 3; //巡查时间 10*100ms
inventoryEvent = new ManualResetEvent(false);
while (!_token.IsCancellationRequested)
{
try
{
if (!_isOpen)
{
return;
}
fCmdRet = Inventory_G2(QValue, Session, MaskMem, MaskAdr, MaskLen, MaskData, MaskFlag, AdrTID,
LenTID, TIDFlag, Target, 0x80, Scantime, FastFlag, EPCList, ref Ant, ref totalLen,
ref cardNum, _portHandle);
if ((fCmdRet == 1) | (fCmdRet == 2) | (fCmdRet == 3) | (fCmdRet == 4)) //代表已查找结束,
{
if (cardNum > 0)
{
i = 0;
epcLen = 0;
for (cardIdx = 0; cardIdx < cardNum; cardIdx++)
{
epcLen = EPCList[i];
byte[] epcNo = new byte[epcLen];
Array.Copy(EPCList, i + 1, epcNo, 0, epcLen);
String strEpcNo = ByteArrToHexStr(epcNo);
byte rssi = EPCList[i + epcLen + 1];
i += epcLen + 2;
OnOnInventory(new TagInfo()
{
AntennaPort = 0,
EPC = strEpcNo,
RSSI = rssi,
SeenCount = 1
});
//AddTagToInvRealTable(strEpcNo, rssi);
}
}
}
else
{
if (fCmdRet == 0x30)
{
//通讯失败,掉线
_isOpen = false;
}
}
}
catch (Exception e)
{
Log.ErrorLog(e.Message, nameof(USBRFIDReaderHelper));
}
}
inventoryEvent.Set();
}, _token.Token);
}
public void InventoryStop()
{
//关闭盘点线程
_token?.Cancel();
inventoryEvent.WaitOne(1000);
}
public bool SetPALevel(byte level)
{
//索力得读写器无天线使能设置
return true;
}
public bool SetTxPower(byte port, bool enable, double power)
{
var res = SetRfPower((byte)Convert.ToInt32(power), _portHandle);
if (res == 0)
{
return true;
}
else
{
if (res == 0x30)
{
//通讯失败,掉线
_isOpen = false;
}
Log.ErrorLog("设置功率失败:0x" + res.ToString("X2"), nameof(USBRFIDReaderHelper));
return false;
}
}
public List<TagInfoData> InventorySingle()
{
var list = new List<TagInfoData>();
//只盘点一轮
int totalLen = 0, cardNum = 0, fCmdRet = 0x30;
int cardIdx = 0, epcLen = 0;
int i;
byte MaskMem = 0;
byte[] MaskAdr = new byte[2];
byte MaskLen = 0;
byte[] MaskData = null;
byte MaskFlag = 0;
byte[] EPCList = new byte[30000];
byte Ant = 0;
byte AdrTID = 0;
byte LenTID = 0;
byte TIDFlag = 0;
byte FastFlag = 1;
byte QValue = 1; //Q值 Q 值的设置应为场内的标签数量约等亍2的Q次方
byte Session = 0; //Session 0 建议单张或者少量标签查询选 S0
byte Target = 0; //Target A
byte Scantime = 3; //巡查时间 3*100ms
try
{
fCmdRet = Inventory_G2(QValue, Session, MaskMem, MaskAdr, MaskLen, MaskData, MaskFlag, AdrTID, LenTID, TIDFlag, Target, 0x80, Scantime, FastFlag, EPCList, ref Ant, ref totalLen, ref cardNum, _portHandle);
if ((fCmdRet == 1) | (fCmdRet == 2) | (fCmdRet == 3) | (fCmdRet == 4)) //代表已查找结束,
{
if (cardNum > 0)
{
i = 0;
epcLen = 0;
for (cardIdx = 0; cardIdx < cardNum; cardIdx++)
{
epcLen = EPCList[i];
byte[] epcNo = new byte[epcLen];
Array.Copy(EPCList, i + 1, epcNo, 0, epcLen);
String strEpcNo = ByteArrToHexStr(epcNo);
byte rssi = EPCList[i + epcLen + 1];
i += epcLen + 2;
list.Add(new TagInfoData()
{
AntennaPort = 0,
EPC = strEpcNo,
RSSI = rssi,
SeenCount = 1
});
}
}
}
else
{
if (fCmdRet == 0x30)
{
//通讯失败,掉线
_isOpen = false;
}
}
}
catch (Exception e)
{
Log.ErrorLog(e.Message, nameof(USBRFIDReaderHelper));
}
return list;
}
public Tuple<int, string> ReadTag(ref OperatingData tag)
{
byte ENum;
byte[] opWordPtr = null;
byte opLen = 0;
byte opMem = 0;
byte[] accPwd = null;
string str = "";
byte[] MaskEPC = null;
byte MaskMem = 0;
byte[] MaskAdr = null;
byte MaskLen = 0;
byte[] MaskData = null;
ENum = (byte)(str.Length / 4);
MaskEPC = new byte[ENum * 2];
MaskEPC = HexStrToByteArr(str);
opMem = (byte)tag.Bank; //0x00:保留区;0x01:EPC 存储区;0x02:TID 存储区;0x03:用户存储区。
opWordPtr = HexStrToByteArr(tag.Offset.ToString("X4"));
opLen = Convert.ToByte(tag.Length);
accPwd = HexStrToByteArr(tag.Access);
byte[] TagData = new byte[opLen * 2];
var errcode = 0;
var res = 0;
for (int retry = 0; retry < 3; retry++)
{
res = ExtReadData_G2(MaskEPC, ENum, opMem, opWordPtr, opLen, accPwd, MaskMem, MaskAdr, MaskLen, MaskData, TagData, ref errcode, _portHandle);
if (res == 0)
break;
}
if (res == 0)
{
tag.DATA = ByteArrToHexStr(TagData);
return new Tuple<int, string>((int)res, typeof(OperResult).GetEnumDesc(res));
}
else
{
if (res == 0x30)
{
//通讯失败,掉线
_isOpen = false;
}
if (res != 0xFC)
{
return new Tuple<int, string>((int)res, typeof(OperResult).GetEnumDesc(res));
}
else
{
return new Tuple<int, string>((int)res, typeof(ErrorCodeEnum).GetEnumDesc(errcode));
}
}
}
public Tuple<int, string> WriteTag(OperatingData tag)
{
byte ENum;
byte WNum = 0;
byte[] opWordPtr = null;
byte opMem = 0;
byte[] opData = null;
byte[] accPwd = null;
string str = "";
byte[] MaskEPC = null;
byte MaskMem = 0;
byte[] MaskAdr = null;
byte MaskLen = 0;
byte[] MaskData = null;
ENum = (byte)(str.Length / 4);
MaskEPC = new byte[ENum * 2];
MaskEPC = HexStrToByteArr(str);
opMem = (byte)tag.Bank; //0x00:保留区;0x01:EPC 存储区;0x02:TID 存储区;0x03:用户存储区。
opWordPtr = HexStrToByteArr(tag.Offset.ToString("X4"));
accPwd = HexStrToByteArr(tag.Access);
opData = HexStrToByteArr(tag.DATA);
WNum = (byte)(opData.Length / 2);
var errcode = 0;
var res = 0;
for (int retry = 0; retry < 3; retry++)
{
res = ExtWriteData_G2(MaskEPC, WNum, ENum, opMem, opWordPtr, opData, accPwd, MaskMem, MaskAdr, MaskLen, MaskData, ref errcode, _portHandle);
if (res == 0)
break;
}
if (res == 0)
{
return new Tuple<int, string>((int)res, typeof(OperResult).GetEnumDesc(res));
}
else
{
if (res == 0x30)
{
//通讯失败,掉线
_isOpen = false;
}
if (res != 0xFC)
{
return new Tuple<int, string>((int)res, typeof(OperResult).GetEnumDesc(res));
}
else
{
return new Tuple<int, string>((int)res, typeof(ErrorCodeEnum).GetEnumDesc(errcode));
}
}
}
protected virtual void OnOnInventory(TagInfo args)
{
OnInventory?.Invoke(new TagInfoData()
{
AntennaPort = args.AntennaPort,
EPC = args.EPC,
RSSI = args.RSSI,
SeenCount = args.SeenCount
});
}
public void Dispose()
{
}
/// <summary>
/// 字符串转16进制字节数组
/// </summary>
/// <param name="hexString"></param>
/// <returns></returns>
public static byte[] HexStrToByteArr(string hexString)
{
hexString = hexString.Replace(" ", "");
if ((hexString.Length % 2) != 0)
hexString += "0";
byte[] returnBytes = new byte[hexString.Length / 2];
for (int i = 0; i < returnBytes.Length; i++)
returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
return returnBytes;
}
/// <summary>
/// 字节数组转16进制字符串
/// </summary>
/// <param name="bytes"></param>
/// <returns></returns>
public static string ByteArrToHexStr(byte[] bytes)
{
string returnStr = "";
if (bytes != null)
{
for (int i = 0; i < bytes.Length; i++)
{
returnStr += bytes[i].ToString("X2");
}
}
return returnStr;
}
#region USBUHFPlatform
private const string DLLNAME = @"USBUHFPlatform.dll";
[DllImport(DLLNAME, CallingConvention = CallingConvention.StdCall)]
public static extern int OpenUSBPort(string DevSnr, ref int FrmHandle);
[DllImport(DLLNAME, CallingConvention = CallingConvention.StdCall)]
public static extern int CloseUSBPort(int FrmHandle);
[DllImport(DLLNAME, CallingConvention = CallingConvention.StdCall)]
public static extern int CompDevInterfaceName(string DevInterfaceName, int FrmHandle);
[DllImport(DLLNAME, CallingConvention = CallingConvention.StdCall)]
public static extern int GetReaderInfo(
byte[] VersionInfo,
ref byte ReaderType,
ref byte TrType,
ref byte dfreband,
ref byte dmaxfre,
ref byte dminfre,
ref byte powerdBm,
ref byte ScanTime,
ref byte Ant,
ref byte BeepEn,
ref byte CheckAnt,
int FrmHandle);
[DllImport(DLLNAME, CallingConvention = CallingConvention.StdCall)]
public static extern int SetRegion(
byte dfreband,
byte dmaxfre,
byte dminfre,
int FrmHandle);
[DllImport(DLLNAME, CallingConvention = CallingConvention.StdCall)]
public static extern int SetInventoryScanTime(
byte ScanTime,
int FrmHandle);
[DllImport(DLLNAME, CallingConvention = CallingConvention.StdCall)]
public static extern int SetRfPower(
byte PowerDbm,
int FrmHandle);
[DllImport(DLLNAME, CallingConvention = CallingConvention.StdCall)]
public static extern int GetLedStatus(
ref byte LedPin,
int FrmHandle);
[DllImport(DLLNAME, CallingConvention = CallingConvention.StdCall)]
public static extern int SetLedCtrl(
byte LedPin,
int FrmHandle);
[DllImport(DLLNAME, CallingConvention = CallingConvention.StdCall)]
public static extern int SetBeep(
byte AvtiveTime,
byte SilentTime,
byte Times,
int FrmHandle);
[DllImport(DLLNAME, CallingConvention = CallingConvention.StdCall)]
public static extern int GetSerialNo(
StringBuilder SeriaNo,
int FrmHandle);
[DllImport(DLLNAME, CallingConvention = CallingConvention.StdCall)]
public static extern int SetSaveLen(
byte SaveLen,
int FrmHandle);
[DllImport(DLLNAME, CallingConvention = CallingConvention.StdCall)]
public static extern int GetSaveLen(
ref byte SaveLen,
int FrmHandle);
[DllImport(DLLNAME, CallingConvention = CallingConvention.StdCall)]
public static extern int ReadBuffer_G2(
ref int Totallen,
ref int CardNum,
byte[] pEPCList,
int FrmHandle);
[DllImport(DLLNAME, CallingConvention = CallingConvention.StdCall)]
public static extern int ClearBuffer_G2(int FrmHandle);
[DllImport(DLLNAME, CallingConvention = CallingConvention.StdCall)]
public static extern int GetBufferCnt_G2(
ref int Count,
int FrmHandle);
[DllImport(DLLNAME, CallingConvention = CallingConvention.StdCall)]
public static extern int SetTagCustomFunction(
ref byte InlayType,
int FrmHandle);
[DllImport(DLLNAME, CallingConvention = CallingConvention.StdCall)]
public static extern int Inventory_G2(
byte QValue,
byte Session,
byte MaskMem,
byte[] MaskAdr,
byte MaskLen,
byte[] MaskData,
byte MaskFlag,
byte AdrTID,
byte LenTID,
byte TIDFlag,
byte Target,
byte InAnt,
byte Scantime,
byte FastFlag,
byte[] pEPCList,
ref byte Ant,
ref int Totallen,
ref int CardNum,
int FrmHandle);
[DllImport(DLLNAME, CallingConvention = CallingConvention.StdCall)]
public static extern int ExtReadData_G2(
byte[] EPC,
byte ENum,
byte Mem,
byte[] WordPtr,
byte Num,
byte[] Password,
byte MaskMem,
byte[] MaskAdr,
byte MaskLen,
byte[] MaskData,
byte[] Data,
ref int Errorcode,
int FrmHandle);
[DllImport(DLLNAME, CallingConvention = CallingConvention.StdCall)]
public static extern int ExtWriteData_G2(
byte[] EPC,
byte WNum,
byte ENum,
byte Mem,
byte[] WordPtr,
byte[] Wdt,
byte[] Password,
byte MaskMem,
byte[] MaskAdr,
byte MaskLen,
byte[] MaskData,
ref int Errorcode,
int FrmHandle);
[DllImport(DLLNAME, CallingConvention = CallingConvention.StdCall)]
public static extern int WriteEPC_G2(
byte[] Password,
byte[] WriteEPC,
byte ENum,
ref int Errorcode,
int FrmHandle);
[DllImport(DLLNAME, CallingConvention = CallingConvention.StdCall)]
public static extern int BlockWrite_G2(
byte[] EPC,
byte WNum,
byte ENum,
byte Mem,
byte WordPtr,
byte[] Wdt,
byte[] Password,
byte MaskMem,
byte[] MaskAdr,
byte MaskLen,
byte[] MaskData,
ref int Errorcode,
int FrmHandle);
[DllImport(DLLNAME, CallingConvention = CallingConvention.StdCall)]
public static extern int BlockErase_G2(
byte[] EPC,
byte ENum,
byte Mem,
byte WordPtr,
byte Num,
byte[] Password,
byte MaskMem,
byte[] MaskAdr,
byte MaskLen,
byte[] MaskData,
ref int Errorcode,
int FrmHandle);
[DllImport(DLLNAME, CallingConvention = CallingConvention.StdCall)]
public static extern int Lock_G2(
byte[] EPC,
byte ENum,
byte select,
byte setprotect,
byte[] Password,
byte MaskMem,
byte[] MaskAdr,
byte MaskLen,
byte[] MaskData,
ref int Errorcode,
int FrmHandle);
[DllImport(DLLNAME, CallingConvention = CallingConvention.StdCall)]
public static extern int KillTag_G2(
byte[] EPC,
byte ENum,
byte[] Killpwd,
byte MaskMem,
byte[] MaskAdr,
byte MaskLen,
byte[] MaskData,
ref int Errorcode,
int FrmHandle);
[DllImport(DLLNAME, CallingConvention = CallingConvention.StdCall)]
public static extern int SetPrivacyByEPC_G2(
byte[] EPC,
byte ENum,
byte[] Password,
byte MaskMem,
byte[] MaskAdr,
byte MaskLen,
byte[] MaskData,
ref int Errorcode,
int FrmHandle);
[DllImport(DLLNAME, CallingConvention = CallingConvention.StdCall)]
public static extern int SetPrivacyWithoutEPC_G2(
byte[] Password,
ref int Errorcode,
int FrmHandle);
[DllImport(DLLNAME, CallingConvention = CallingConvention.StdCall)]
public static extern int ResetPrivacy_G2(
byte[] Password,
ref int Errorcode,
int FrmHandle);
[DllImport(DLLNAME, CallingConvention = CallingConvention.StdCall)]
public static extern int CheckPrivacy_G2(
ref byte readpro,
ref int Errorcode,
int FrmHandle);
[DllImport(DLLNAME, CallingConvention = CallingConvention.StdCall)]
public static extern int EASConfigure_G2(
byte[] EPC,
byte ENum,
byte[] Password,
byte EAS,
byte MaskMem,
byte[] MaskAdr,
byte MaskLen,
byte[] MaskData,
ref int Errorcode,
int FrmHandle);
[DllImport(DLLNAME, CallingConvention = CallingConvention.StdCall)]
public static extern int EASAlarm_G2(
ref int Errorcode,
int FrmHandle);
[DllImport(DLLNAME, CallingConvention = CallingConvention.StdCall)]
public static extern int GetMonza4QTWorkParamter_G2(
byte[] EPC,
byte ENum,
byte[] Password,
byte MaskMem,
byte[] MaskAdr,
byte MaskLen,
byte[] MaskData,
ref byte QTcontrol,
ref int Errorcode,
int FrmHandle);
[DllImport(DLLNAME, CallingConvention = CallingConvention.StdCall)]
public static extern int SetMonza4QTWorkParamter_G2(
byte[] EPC,
byte ENum,
byte QTcontrol,
byte[] Password,
byte MaskMem,
byte[] MaskAdr,
byte MaskLen,
byte[] MaskData,
ref int Errorcode,
int FrmHandle);
[DllImport(DLLNAME, CallingConvention = CallingConvention.StdCall)]
public static extern int InventoryBuffer_G2(
byte QValue,
byte Session,
byte MaskMem,
byte[] MaskAdr,
byte MaskLen,
byte[] MaskData,
byte MaskFlag,
byte AdrTID,
byte LenTID,
byte TIDFlag,
byte Target,
byte InAnt,
byte Scantime,
byte FastFlag,
ref int BufferCount,
ref int TagNum,
int FrmHandle);
#endregion
public enum OperResult
{
[Description("执行成功")] OK = 0x00,
[Description("扫描时间结束前返回")] Error1 = 0x01,
[Description("指定的扫描时间溢出")] Error2 = 0x02,
[Description("本条消息之后,还有消息")] Error3 = 0x03,
[Description("读写模块存储空间已满")] Error4 = 0x04,
[Description("访问密码错误")] Error5 = 0x05,
[Description("销毁密码错误")] Error9 = 0x09,
[Description("销毁密码丌能为全 0")] Error10 = 0x0A,
[Description("电子标签丌支持该命令")] Error11 = 0x0B,
[Description("对亍特定命令,访问密码丌能为 0")] Error12 = 0x0C,
[Description("电子标签已经被设置了读保护,丌能再次设置")] Error13 = 0x0D,
[Description("电子标签没有被设置读保护,丌需要解锁")] Error14 = 0x0E,
[Description("参数保存失败,设置的值仅在读写器断电前有效")] Error19 = 0x13,
[Description("无法调整功率")] Error20 = 0x14,
[Description("电子丌支持该命令或者访问密码丌能为 0")] Error25 = 0x19,
[Description("标签自定义功能执行错误")] Error26 = 0x1A,
[Description("返回指令错误")] Error238 = 0xEE,
[Description("检测丌到天线连接")] Error248 = 0xF8,
[Description("命令执行出错")] Error249 = 0xF9,
[Description("扫描到电子标签,但由亍通信丌畅,导致操作失败")] Error250 = 0xFA,
[Description("无电子标签可操作")] Error251 = 0xFB,
[Description("电子标签返回错误代码")] Error252 = 0xFC,
[Description("命令长度错误")] Error253 = 0xFD,
[Description("命令非法")] Error254 = 0xFE,
[Description("参数错误")] Error255 = 0xFF,
[Description("通讯错误")] Error48 = 0x30,
[Description("CRC 错误")] Error49 = 0x31,
[Description("通讯繁忙,设备正在执行其他命令")] Error51 = 0x33,
[Description("端口已打开")] Error53 = 0x35,
[Description("端口已关闭")] Error54 = 0x36,
[Description("无效句柄")] Error55 = 0x37,
[Description("已打开设备过多,空间丌足")] Error57 = 0x39,
}
public enum ErrorCodeEnum
{
[Description("其它错误,全部捕捉未被其它代码覆盖的错误")] Error0 = 0x00,
[Description("存储器超限或丌被支持的 PC 值,规定存储位置丌存在或标签丌支持 PC 值")] Error3 = 0x03,
[Description("存储器锁定,存储位置锁定永久锁定,且丌可写入")] Error4 = 0x04,
[Description("电源丌足,标签电源丌足,无法执行存储写入操作")] Error11 = 0x0B,
[Description("非特定错误,标签丌支持特定错误代码")] Error15 = 0x0F,
}
}
public static class EnumExtension
{
/// <summary>
/// 根据值得到中文备注
/// </summary>
/// <param name="e"></param>
/// <param name="value"></param>
/// <returns></returns>
public static string GetEnumDesc(this System.Type e, int? value)
{
string result;
try
{
System.Reflection.FieldInfo[] fields = e.GetFields();
int i = 1;
int count = fields.Length;
while (i < count)
{
if ((int)System.Enum.Parse(e, fields[i].Name) == value)
{
DescriptionAttribute[] EnumAttributes = (DescriptionAttribute[])fields[i].GetCustomAttributes(typeof(DescriptionAttribute), false);
if (EnumAttributes.Length > 0)
{
result = EnumAttributes[0].Description;
return result;
}
}
i++;
}
result = "";
}
catch
{
result = "";
}
return result;
}
}
}
\ No newline at end of file
......@@ -124,6 +124,7 @@ namespace LiteChannel
ShelfAddress = "http://192.168.3.128:38080/api/BoundDocuments";
IsAutoUpdate = true;
AutoUpdateTime = 0;
ReaderType = 0;
}
/// <summary>
/// 接口域名
......@@ -162,6 +163,13 @@ namespace LiteChannel
/// </summary>
public int AutoUpdateTime { get; set; }
/// <summary>
/// 读写器类型
/// 0 钧普
/// 1 索力得
/// </summary>
public int ReaderType { get; set; }
[JsonIgnore]
public static new bool IsInDesignModeStatic { get; }
}
......
......@@ -41,6 +41,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
......@@ -50,6 +51,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>1.ico</ApplicationIcon>
......@@ -123,6 +125,7 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Commons\ReaderHelper.cs" />
<Compile Include="SelectPoliceWindow.xaml.cs">
<DependentUpon>SelectPoliceWindow.xaml</DependentUpon>
</Compile>
......@@ -259,6 +262,18 @@
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="ThirdPackages\plugin\hik\GdiPlus.lib" />
<None Include="ThirdPackages\plugin\hik\HCCore.lib" />
<None Include="ThirdPackages\plugin\hik\HCNetSDK.lib" />
<None Include="ThirdPackages\plugin\hik\HCNetSDKCom\HCAlarm.lib" />
<None Include="ThirdPackages\plugin\hik\HCNetSDKCom\HCGeneralCfgMgr.lib" />
<None Include="ThirdPackages\plugin\hik\HCNetSDKCom\HCPreview.lib" />
<None Include="ThirdPackages\plugin\hik\LocalXml.zip" />
<None Include="ThirdPackages\plugin\hik\log4cxx.properties" />
<None Include="ThirdPackages\plugin\hik\PlayCtrl.lib" />
<None Include="ThirdPackages\tts\common.jet" />
<None Include="ThirdPackages\tts\xiaofeng.jet" />
<None Include="ThirdPackages\tts\xiaoyan.jet" />
<Resource Include="Font\iconfont.ttf" />
<None Include="config.json" />
<None Include="packages.config" />
......@@ -298,6 +313,43 @@
<ItemGroup>
<Resource Include="Resources\2.png" />
</ItemGroup>
<ItemGroup>
<Content Include="ThirdPackages\msc.dll" />
<Content Include="ThirdPackages\msc_x64.dll" />
<Content Include="ThirdPackages\plugin\hik\AudioRender.dll" />
<Content Include="ThirdPackages\plugin\hik\EagleEyeRender.dll" />
<Content Include="ThirdPackages\plugin\hik\gdiplus.dll" />
<Content Include="ThirdPackages\plugin\hik\HCCore.dll" />
<Content Include="ThirdPackages\plugin\hik\HCNetSDK.dll" />
<Content Include="ThirdPackages\plugin\hik\HCNetSDKCom\AnalyzeData.dll" />
<Content Include="ThirdPackages\plugin\hik\HCNetSDKCom\AudioIntercom.dll" />
<Content Include="ThirdPackages\plugin\hik\HCNetSDKCom\HCAlarm.dll" />
<Content Include="ThirdPackages\plugin\hik\HCNetSDKCom\HCCoreDevCfg.dll" />
<Content Include="ThirdPackages\plugin\hik\HCNetSDKCom\HCDisplay.dll" />
<Content Include="ThirdPackages\plugin\hik\HCNetSDKCom\HCGeneralCfgMgr.dll" />
<Content Include="ThirdPackages\plugin\hik\HCNetSDKCom\HCIndustry.dll" />
<Content Include="ThirdPackages\plugin\hik\HCNetSDKCom\HCPlayBack.dll" />
<Content Include="ThirdPackages\plugin\hik\HCNetSDKCom\HCPreview.dll" />
<Content Include="ThirdPackages\plugin\hik\HCNetSDKCom\HCVoiceTalk.dll" />
<Content Include="ThirdPackages\plugin\hik\HCNetSDKCom\libiconv2.dll" />
<Content Include="ThirdPackages\plugin\hik\HCNetSDKCom\msvcr90.dll" />
<Content Include="ThirdPackages\plugin\hik\HCNetSDKCom\OpenAL32.dll" />
<Content Include="ThirdPackages\plugin\hik\HCNetSDKCom\StreamTransClient.dll" />
<Content Include="ThirdPackages\plugin\hik\HCNetSDKCom\SystemTransform.dll" />
<Content Include="ThirdPackages\plugin\hik\hlog.dll" />
<Content Include="ThirdPackages\plugin\hik\hpr.dll" />
<Content Include="ThirdPackages\plugin\hik\HXVA.dll" />
<Content Include="ThirdPackages\plugin\hik\libeay32.dll" />
<Content Include="ThirdPackages\plugin\hik\MP_Render.dll" />
<Content Include="ThirdPackages\plugin\hik\MP_VIE.dll" />
<Content Include="ThirdPackages\plugin\hik\NPQos.dll" />
<Content Include="ThirdPackages\plugin\hik\PlayCtrl.dll" />
<Content Include="ThirdPackages\plugin\hik\ssleay32.dll" />
<Content Include="ThirdPackages\plugin\hik\SuperRender.dll" />
<Content Include="ThirdPackages\plugin\hik\YUVProcess.dll" />
<Content Include="ThirdPackages\plugin\hik\zlib1.dll" />
<Content Include="ThirdPackages\USBUHFPlatform.dll" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\MaterialDesignThemes.3.1.3\build\MaterialDesignThemes.targets" Condition="Exists('..\packages\MaterialDesignThemes.3.1.3\build\MaterialDesignThemes.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
......
......@@ -51,5 +51,5 @@ using System.Windows;
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.12.12070")]
[assembly: AssemblyFileVersion("1.2.12.12070")]
[assembly: AssemblyVersion("1.2.13.12290")]
[assembly: AssemblyFileVersion("1.2.13.12290")]
......@@ -6,7 +6,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:LiteChannel"
mc:Ignorable="d"
Title="系统配置" Height="460" Loaded="OnWindow_Loaded" Width="800" Icon="1.ico" ResizeMode="NoResize" WindowStartupLocation="CenterScreen">
Title="系统配置" Height="500" Loaded="OnWindow_Loaded" Width="800" Icon="1.ico" ResizeMode="NoResize" WindowStartupLocation="CenterScreen">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="40"/>
......@@ -18,6 +18,7 @@
<RowDefinition Height="40"/>
<RowDefinition Height="40"/>
<RowDefinition Height="40"/>
<RowDefinition Height="40"/>
<RowDefinition Height="10"/>
<RowDefinition Height="40"/>
<RowDefinition Height="40"/>
......@@ -43,9 +44,6 @@
<TextBlock Grid.Row="1" Grid.Column="3" Text="登录接口:" HorizontalAlignment="Right" VerticalAlignment="Center"/>
<TextBox Grid.Row="1" Grid.Column="4" x:Name="txt_login" Width="auto" Height="25" HorizontalAlignment="Stretch" VerticalAlignment="Center"/>
<TextBlock Grid.Row="2" Grid.Column="3" Text="串口编号:" HorizontalAlignment="Right" VerticalAlignment="Center"/>
<ComboBox Grid.Row="2" Grid.Column="4" x:Name="cbo_com" Width="auto" Height="25" HorizontalAlignment="Stretch" VerticalAlignment="Center"/>
<TextBlock Grid.Row="2" Grid.Column="1" Text="程序标题:" HorizontalAlignment="Right" VerticalAlignment="Center"/>
<TextBox Grid.Row="2" Grid.Column="2" x:Name="txt_title" Width="auto" Height="25" HorizontalAlignment="Stretch" VerticalAlignment="Center"/>
......@@ -123,10 +121,21 @@
<ComboBoxItem>23:00</ComboBoxItem>
</ComboBox>
<TextBlock Grid.Row="9" Grid.Column="1" Text="读写器类型:" HorizontalAlignment="Right" VerticalAlignment="Center"/>
<ComboBox Grid.Row="9" Grid.Column="2" x:Name="cbo_readerType" Width="auto" Height="25"
HorizontalAlignment="Stretch" VerticalAlignment="Center"
pu:ComboBoxHelper.HoverBackground="#1EB5B5B5"
pu:ComboBoxHelper.SelectedBackground="#32B5B5B5"
pu:ComboBoxHelper.IsSearchTextBoxVisible="False" SelectionChanged="cbo_readerType_SelectionChanged">
<ComboBoxItem>钧普</ComboBoxItem>
<ComboBoxItem>索力得</ComboBoxItem>
</ComboBox>
<TextBlock Grid.Row="9" Grid.Column="3" x:Name="tb_com" Text="串口编号:" HorizontalAlignment="Right" VerticalAlignment="Center"/>
<ComboBox Grid.Row="9" Grid.Column="4" x:Name="cbo_com" Width="auto" Height="25" HorizontalAlignment="Stretch" VerticalAlignment="Center"/>
<Button Grid.Row="10" Grid.ColumnSpan="6" Click="OnSave_Click" HorizontalAlignment="Right" Width="90" Margin="0,0,110,0">保存配置</Button>
<Button Grid.Row="11" Grid.ColumnSpan="6" Click="OnSave_Click" HorizontalAlignment="Right" Width="90" Margin="0,0,110,0">保存配置</Button>
<!--<Button Grid.Row="14" Grid.ColumnSpan="6" Click="OnRefresh_Click" HorizontalAlignment="Right" Width="90" Margin="0,0,110,0">刷新仓库</Button>-->
<Button Grid.Row="10" Grid.ColumnSpan="6" Click="OnCancel_Click" HorizontalAlignment="Right" Background="#C8FF7F00" pu:ButtonHelper.HoverBrush="#FF7F00" Width="90" Margin="0,0,10,0">关闭</Button>
<Button Grid.Row="11" Grid.ColumnSpan="6" Click="OnCancel_Click" HorizontalAlignment="Right" Background="#C8FF7F00" pu:ButtonHelper.HoverBrush="#FF7F00" Width="90" Margin="0,0,10,0">关闭</Button>
</Grid>
</pu:WindowX>
......@@ -39,7 +39,6 @@ namespace LiteChannel
LiteCaChe.SysConfig.DomainUrl = txt_domain.Text;
//LiteCaChe.SysConfig.AppTitle = txt_title.Text;
//LiteCaChe.SysConfig.AppVersion = ver;
LiteCaChe.SysConfig.ComMouth = cbo_com.Text;
//LiteCaChe.SysConfig.WarehouseID = cbo_warehouse.SelectedValue?.ToString() ?? "";
LiteCaChe.SysConfig.FaceAddress = txt_ip.Text;
......@@ -57,6 +56,12 @@ namespace LiteChannel
LiteCaChe.SysConfig.IsAutoUpdate = cb_autoUpdate.IsChecked == true;
LiteCaChe.SysConfig.AutoUpdateTime = cbb_autoUpdate.SelectedIndex;
LiteCaChe.SysConfig.ReaderType = cbo_readerType.SelectedIndex;
if (LiteCaChe.SysConfig.ReaderType == 0)
{
LiteCaChe.SysConfig.ComMouth = cbo_com.Text;
}
LiteCaChe.SaveSystemStep(LiteCaChe.SysConfig);
MessageBox.Show("配置保存成功!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
this.Close();
......@@ -86,7 +91,7 @@ namespace LiteChannel
txt_domain.Text = LiteCaChe.SysConfig.DomainUrl;
txt_title.Text = LiteCaChe.SysConfig.AppTitle;
txt_ver.Text = LiteCaChe.SysConfig.AppVersion.ToString();
cbo_com.Text = LiteCaChe.SysConfig.ComMouth;
//cbo_warehouse.SelectedValue = LiteCaChe.SysConfig.WarehouseID;
txt_ip.Text = LiteCaChe.SysConfig.FaceAddress;
......@@ -113,6 +118,19 @@ namespace LiteChannel
cbb_autoUpdate.SelectedIndex = LiteCaChe.SysConfig.AutoUpdateTime;
IsLoaded = true;
cbo_readerType.SelectedIndex = LiteCaChe.SysConfig.ReaderType;
if (LiteCaChe.SysConfig.ReaderType == 0)
{
tb_com.Visibility = Visibility.Visible;
cbo_com.Visibility = Visibility.Visible;
cbo_com.Text = LiteCaChe.SysConfig.ComMouth;
}
else
{
tb_com.Visibility = Visibility.Hidden;
cbo_com.Visibility = Visibility.Hidden;
}
}
//private void cbo_warehouse_SearchTextChanged(object sender, Panuon.UI.Silver.Core.SearchTextChangedEventArgs e)
......@@ -142,5 +160,20 @@ namespace LiteChannel
cbb_autoUpdate.IsEnabled = false;
}
}
private void cbo_readerType_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (cbo_readerType.SelectedIndex == 0)
{
tb_com.Visibility = Visibility.Visible;
cbo_com.Visibility = Visibility.Visible;
cbo_com.Text = LiteCaChe.SysConfig.ComMouth;
}
else
{
tb_com.Visibility = Visibility.Hidden;
cbo_com.Visibility = Visibility.Hidden;
}
}
}
}
......@@ -29,7 +29,7 @@ namespace LiteChannel
/// </summary>
public partial class StoreInWindow : WindowX, IComponentConnector
{
private JmpRfidLp.Reader reader;
private IReaderHelper reader;
private List<scan_info> SourcesList = new List<scan_info>();
private List<scan_info> BoxMarkList = new List<scan_info>();
private Queue<string> _epcQueue = new Queue<string>();
......@@ -57,7 +57,19 @@ namespace LiteChannel
{
try
{ //启动读写器
reader = new Reader(LiteCaChe.SysConfig.ComMouth);
switch (LiteCaChe.SysConfig.ReaderType)
{
case 0:
{
reader = new JmpRfidLpReaderHelper(LiteCaChe.SysConfig.ComMouth);
break;
}
case 1:
{
reader = new USBRFIDReaderHelper();
break;
}
}
reader.OnInventory += OnRadioInventory;
var state = reader.Open();
if (state)
......@@ -93,7 +105,7 @@ namespace LiteChannel
return false;
}
}
private void OnRadioInventory(TagInfo args)
private void OnRadioInventory(TagInfoData args)
{
if (!BoxMarkList.Any(t => t.epcList.Contains(args.EPC)) &&
args.EPC.Length == 24 && args.EPC.Substring(0, 4) == "5842")
......
......@@ -29,7 +29,7 @@ namespace LiteChannel
/// </summary>
public partial class StoreOutWindow : WindowX, IComponentConnector
{
private JmpRfidLp.Reader reader;
private IReaderHelper reader;
private List<scan_info> SourcesList = new List<scan_info>();
private List<scan_info> BoxMarkList = new List<scan_info>();
private Queue<string> _epcQueue = new Queue<string>();
......@@ -119,7 +119,19 @@ namespace LiteChannel
{
try
{ //启动读写器
reader = new Reader(LiteCaChe.SysConfig.ComMouth);
switch (LiteCaChe.SysConfig.ReaderType)
{
case 0:
{
reader = new JmpRfidLpReaderHelper(LiteCaChe.SysConfig.ComMouth);
break;
}
case 1:
{
reader = new USBRFIDReaderHelper();
break;
}
}
reader.OnInventory += OnRadioInventory;
var state = reader.Open();
if (state)
......@@ -155,7 +167,7 @@ namespace LiteChannel
}
}
private void OnRadioInventory(TagInfo args)
private void OnRadioInventory(TagInfoData args)
{
if (!BoxMarkList.Any(t => t.epcList.Contains(args.EPC)) &&
args.EPC.Length == 24 && args.EPC.Substring(0, 4) == "5842")
......
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
<appSettings>
<add key="ip" value="192.168.0.18"/>
<add key="port" value="502"/>
<add key="index" value="01"/>
</appSettings>
</configuration>
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
namespace TransmitterService
{
internal static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
static void Main()
{
//ServiceBase[] ServicesToRun;
//ServicesToRun = new ServiceBase[]
//{
// new Service1()
//};
//ServiceBase.Run(ServicesToRun);
new Service1().RunTest();
Console.ReadKey();
}
}
}
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("TransmitterService")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TransmitterService")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("fb7e4eb3-f9c2-42da-89cc-d8831c462cb5")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
namespace TransmitterService
{
partial class Service1
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
this.ServiceName = "Service1";
}
#endregion
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.IO.Ports;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.ServiceProcess;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Configuration;
namespace TransmitterService
{
public partial class Service1 : ServiceBase
{
private TcpClient myTcpClient; //声明TCP客户端
private NetworkStream netStream; //声明网络数据流
private Thread receiveDataThread; //声明接收数据进程
private bool lostFlag;
private CancellationToken token;
private string ip = ConfigurationManager.AppSettings["ip"];
private string port = ConfigurationManager.AppSettings["port"];
private string index = ConfigurationManager.AppSettings["index"];
public Service1()
{
InitializeComponent();
}
#region tcp
private void Init()
{
//创建并实例化IP终结点
IPEndPoint iPEndPoint = new IPEndPoint(IPAddress.Parse(ip), Convert.ToInt32(port));
//实例化TCP客户端
myTcpClient = new TcpClient();
try
{
//发起TCP连接
myTcpClient.Connect(iPEndPoint);
//获取绑定的网络数据流
netStream = myTcpClient.GetStream();
//实例化接收数据进程
receiveDataThread = new Thread(ReceiveMsg);
receiveDataThread.Start();
lostFlag = false;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
/// <summary>
/// 接收消息线程
/// </summary>
private void ReceiveMsg()
{
Console.WriteLine("客户端已连接服务器!");
while (true)
{
try
{
//获取数据
byte[] getData = new byte[1024];
netStream.Read(getData, 0, getData.Length);
//todo 处理返回消息 00 00 00 00 00 07 01 03 04 0B 3E 70 BC
if (getData[0] == 0 && getData[1] == 0 && getData[2] == 0 && getData[3] == 0 && getData[7] == 3)
{
var sd = Convert.ToInt32("0x" + getData[9].ToString("X2") + getData[10].ToString("X2"), 16) / 100.0;
var wd = (Convert.ToInt32("0x" + getData[11].ToString("X2") + getData[12].ToString("X2"), 16) - 27315) / 100.0;
Console.WriteLine($"温度:{wd} 湿度:{sd}");
}
}
catch (ThreadAbortException)
{
}
catch (System.Exception ex)
{
lostFlag = true;
Console.WriteLine(ex.Message);
//释放相关资源
if (netStream != null)
{
netStream.Dispose();
}
break;
}
}
}
private void Reconnect()
{
Task.Run(() =>
{
while (!token.IsCancellationRequested)
{
try
{
if (lostFlag)
{
Init();
}
Thread.Sleep(10 * 1000);
}
catch (Exception e)
{
Console.WriteLine(e);
Thread.Sleep(10 * 1000);
}
}
}, token);
}
#endregion
public void RunTest()
{
OnStart(null);
}
protected override void OnStart(string[] args)
{
token = new CancellationToken();
Init();
Reconnect();
Task.Run(() =>
{
while (!token.IsCancellationRequested)
{
try
{
//发送查询命令 00 00 00 00 00 06 01 03 00 00 00 02
var index = Convert.ToInt32(this.index);
var msg = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, Convert.ToByte(index), 0x03, 0x00, 0x00, 0x00, 0x02 };
netStream.Write(msg, 0, msg.Length);
Thread.Sleep(30 * 1000); //30秒获取一次
}
catch (Exception e)
{
lostFlag = true;
Console.WriteLine(e);
Thread.Sleep(30 * 1000); //30秒获取一次
}
}
}, token);
}
protected override void OnStop()
{
//销毁TCP客户端和网络数据流的实例
myTcpClient.Close();
netStream.Dispose();
receiveDataThread.Abort();
}
}
}
<?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>{FB7E4EB3-F9C2-42DA-89CC-D8831C462CB5}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>TransmitterService</RootNamespace>
<AssemblyName>TransmitterService</AssemblyName>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</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>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.configuration" />
<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.Net.Http" />
<Reference Include="System.ServiceProcess" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Service1.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Service1.Designer.cs">
<DependentUpon>Service1.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论